Skip to content

Commit

Permalink
feat(telemetry)_: track total bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
adklempner committed Nov 25, 2024
1 parent ad28f15 commit cb426a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions wakuv2/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,27 @@ 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),
"store": getStatsPerProtocol(legacy_store.StoreID_v20beta4, stats),
"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))
Expand Down
3 changes: 2 additions & 1 deletion wakuv2/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,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)
}
}
}
Expand Down

0 comments on commit cb426a7

Please sign in to comment.