From 46e8c7d6a678a3050a0bde7acef10278a72e8a6f Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 6 Jul 2024 14:34:04 +0530 Subject: bpf: track bandwidth --- bpf/main.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'bpf') 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, } } } -- cgit v1.2.3