From 4e2671608059ca5d99586eab3ff61ef1da9b0d23 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sun, 7 Jul 2024 09:51:46 +0530 Subject: api/addwidth: send total to response --- api/bandwidth.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/api/bandwidth.go b/api/bandwidth.go index 5f23221..51b1760 100644 --- a/api/bandwidth.go +++ b/api/bandwidth.go @@ -20,9 +20,13 @@ type BandwidthResp map[string]BandwidthStat func handleBandwidth(conn net.Conn, u *usage.Usage) { resp := make(BandwidthResp) + var ingressTotal, egressTotal uint64 u.Mutex.RLock() for key, value := range u.Data { + ingressTotal += value.BandwidthIngress + egressTotal += value.BandwidthEgress + m := mac.Uint64MAC(key) resp[m.String()] = BandwidthStat{ Ingress: fmt.Sprintf("%s/s", humanize.Bytes(value.BandwidthIngress)), @@ -31,6 +35,11 @@ func handleBandwidth(conn net.Conn, u *usage.Usage) { } u.Mutex.RUnlock() + resp["total"] = BandwidthStat{ + Ingress: fmt.Sprintf("%s/s", humanize.Bytes(ingressTotal)), + Egress: fmt.Sprintf("%s/s", humanize.Bytes(egressTotal)), + } + buf, err := json.Marshal(resp) if err != nil { log.Printf("marshaling json: %s", err) -- cgit v1.2.3