diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-07-07 09:51:46 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-07-07 09:51:46 +0530 |
commit | 4e2671608059ca5d99586eab3ff61ef1da9b0d23 (patch) | |
tree | 1f7c51f6cd3ce4849145d37854ed97c10f6b55e0 | |
parent | 87b230e71a830e191dd5c14aa94a025c39792145 (diff) |
api/addwidth: send total to response
-rw-r--r-- | api/bandwidth.go | 9 |
1 files changed, 9 insertions, 0 deletions
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) |