forked from application-research/estuary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbwgrapher.go
40 lines (33 loc) · 1.06 KB
/
bwgrapher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"time"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/libp2p/go-libp2p-core/metrics"
)
func StartBandwidthGrapher(client influxdb2.Client, bwc *metrics.BandwidthCounter) {
// TODO: using a custom bandwidth counter might make sense here...
byproto := bwc.GetBandwidthByProtocol()
bypeer := bwc.GetBandwidthByPeer()
writeAPI := client.WriteAPI("estuary", "bandwidth")
t := time.Now()
for p, v := range byproto {
writeAPI.WritePoint(influxdb2.NewPointWithMeasurement("stat").
AddTag("unit", "bytespersecond").
AddTag("protocol", string(p)).
AddField("ratein", v.RateIn).
AddField("rateout", v.RateOut).
AddField("totalin", v.TotalIn).
AddField("totalout", v.TotalOut).
SetTime(t))
}
for p, v := range bypeer {
writeAPI.WritePoint(influxdb2.NewPointWithMeasurement("stat").
AddTag("unit", "bytespersecond").
AddTag("peer", p.String()).
AddField("ratein", v.RateIn).
AddField("rateout", v.RateOut).
AddField("totalin", v.TotalIn).
AddField("totalout", v.TotalOut).
SetTime(t))
}
}