summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/bandwidth.go9
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)