summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-07-06 14:34:04 +0530
committersinanmohd <sinan@sinanmohd.com>2024-07-06 14:34:04 +0530
commit46e8c7d6a678a3050a0bde7acef10278a72e8a6f (patch)
tree5e4d76e62d85480e977dcf8d465b826fd6606f7a
parent4c8be274a50104917fd777645b2985b92eecdfb5 (diff)
bpf: track bandwidth
-rw-r--r--bpf/main.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/bpf/main.go b/bpf/main.go
index b465f2c..d956a9b 100644
--- a/bpf/main.go
+++ b/bpf/main.go
@@ -17,10 +17,12 @@ import (
)
type UsageStat struct {
- lastSeen time.Time
- lastDbPush time.Time
- ingress uint64
- egress uint64
+ lastSeen time.Time
+ lastDbPush time.Time
+ bandwidthIngress uint64
+ bandwidthEgress uint64
+ ingress uint64
+ egress uint64
}
type UsageMap map[uint64]UsageStat
@@ -145,14 +147,16 @@ func (usageMap UsageMap) update(ingress *ebpf.Map, egress *ebpf.Map) error {
key = batchKeys[i]
usage, ok := usageMap[key]
if ok {
+ usage.bandwidthIngress = batchValues[i] - usage.ingress
usage.ingress += batchValues[i]
usage.lastSeen = timeStart
usageMap[key] = usage
} else {
usageMap[key] = UsageStat{
- ingress: batchValues[i],
- lastDbPush: timeStart,
- lastSeen: timeStart,
+ bandwidthIngress: batchValues[i],
+ ingress: batchValues[i],
+ lastDbPush: timeStart,
+ lastSeen: timeStart,
}
}
}
@@ -176,14 +180,16 @@ func (usageMap UsageMap) update(ingress *ebpf.Map, egress *ebpf.Map) error {
key = batchKeys[i]
usage, ok := usageMap[key]
if ok {
+ usage.bandwidthEgress = batchValues[i] - usage.egress
usage.egress += batchValues[i]
usage.lastSeen = timeStart
usageMap[key] = usage
} else {
usageMap[key] = UsageStat{
- egress: batchValues[i],
- lastDbPush: timeStart,
- lastSeen: timeStart,
+ bandwidthEgress: batchValues[i],
+ egress: batchValues[i],
+ lastDbPush: timeStart,
+ lastSeen: timeStart,
}
}
}