feat(telemetry)_: track total bandwidth

This commit is contained in:
Arseniy Klempner 2024-10-21 17:13:40 -07:00
parent 3179532b64
commit 36bd9c58f5
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B
2 changed files with 11 additions and 4 deletions

View File

@ -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{}{
"hostID": c.hostID,
"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-subscribe": getStatsPerProtocol(filter.FilterSubscribeID_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()
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))
if err != nil {
c.logger.Error("Error sending message to telemetry server", zap.Error(err))

View File

@ -564,8 +564,9 @@ func (w *Waku) telemetryBandwidthStats(telemetryServerURL string) {
return
case <-ticker.C:
bandwidthPerProtocol := w.bandwidthCounter.GetBandwidthByProtocol()
totals := w.bandwidthCounter.GetBandwidthTotals()
w.bandwidthCounter.Reset()
go telemetry.PushProtocolStats(bandwidthPerProtocol)
go telemetry.PushProtocolStats(bandwidthPerProtocol, totals)
}
}
}