feat(telemetry)_: track total bandwidth
This commit is contained in:
parent
3179532b64
commit
36bd9c58f5
|
@ -45,7 +45,7 @@ func getStatsPerProtocol(protocolID protocol.ID, stats map[protocol.ID]metrics.S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BandwidthTelemetryClient) getTelemetryRequestBody(stats map[protocol.ID]metrics.Stats) map[string]interface{} {
|
func (c *BandwidthTelemetryClient) getTelemetryRequestBody(stats map[protocol.ID]metrics.Stats, totals metrics.Stats) map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"hostID": c.hostID,
|
"hostID": c.hostID,
|
||||||
"relay": getStatsPerProtocol(relay.WakuRelayID_v200, stats),
|
"relay": getStatsPerProtocol(relay.WakuRelayID_v200, stats),
|
||||||
|
@ -53,13 +53,19 @@ func (c *BandwidthTelemetryClient) getTelemetryRequestBody(stats map[protocol.ID
|
||||||
"filter-push": getStatsPerProtocol(filter.FilterPushID_v20beta1, stats),
|
"filter-push": getStatsPerProtocol(filter.FilterPushID_v20beta1, stats),
|
||||||
"filter-subscribe": getStatsPerProtocol(filter.FilterSubscribeID_v20beta1, stats),
|
"filter-subscribe": getStatsPerProtocol(filter.FilterSubscribeID_v20beta1, stats),
|
||||||
"lightpush": getStatsPerProtocol(lightpush.LightPushID_v20beta1, stats),
|
"lightpush": getStatsPerProtocol(lightpush.LightPushID_v20beta1, stats),
|
||||||
|
"total": map[string]interface{}{
|
||||||
|
"rateIn": totals.RateIn,
|
||||||
|
"rateOut": totals.RateOut,
|
||||||
|
"totalIn": totals.TotalIn,
|
||||||
|
"totalOut": totals.TotalOut,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BandwidthTelemetryClient) PushProtocolStats(stats map[protocol.ID]metrics.Stats) {
|
func (c *BandwidthTelemetryClient) PushProtocolStats(stats map[protocol.ID]metrics.Stats, totals metrics.Stats) {
|
||||||
defer gocommon.LogOnPanic()
|
defer gocommon.LogOnPanic()
|
||||||
url := fmt.Sprintf("%s/protocol-stats", c.serverURL)
|
url := fmt.Sprintf("%s/protocol-stats", c.serverURL)
|
||||||
body, _ := json.Marshal(c.getTelemetryRequestBody(stats))
|
body, _ := json.Marshal(c.getTelemetryRequestBody(stats, totals))
|
||||||
_, err := c.httpClient.Post(url, "application/json", bytes.NewBuffer(body))
|
_, err := c.httpClient.Post(url, "application/json", bytes.NewBuffer(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Error("Error sending message to telemetry server", zap.Error(err))
|
c.logger.Error("Error sending message to telemetry server", zap.Error(err))
|
||||||
|
|
|
@ -564,8 +564,9 @@ func (w *Waku) telemetryBandwidthStats(telemetryServerURL string) {
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
bandwidthPerProtocol := w.bandwidthCounter.GetBandwidthByProtocol()
|
bandwidthPerProtocol := w.bandwidthCounter.GetBandwidthByProtocol()
|
||||||
|
totals := w.bandwidthCounter.GetBandwidthTotals()
|
||||||
w.bandwidthCounter.Reset()
|
w.bandwidthCounter.Reset()
|
||||||
go telemetry.PushProtocolStats(bandwidthPerProtocol)
|
go telemetry.PushProtocolStats(bandwidthPerProtocol, totals)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue