From 90e7224ee18ca0fabfa558b58ddc94a9f184f11f Mon Sep 17 00:00:00 2001 From: Arseniy Klempner Date: Mon, 21 Oct 2024 17:13:40 -0700 Subject: [PATCH] feat(telemetry)_: track total bandwidth --- wakuv2/telemetry.go | 12 +++++++++--- wakuv2/waku.go | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/wakuv2/telemetry.go b/wakuv2/telemetry.go index 5749bb2a8..6b29f0615 100644 --- a/wakuv2/telemetry.go +++ b/wakuv2/telemetry.go @@ -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)) diff --git a/wakuv2/waku.go b/wakuv2/waku.go index db9d3d7c7..419ffee06 100644 --- a/wakuv2/waku.go +++ b/wakuv2/waku.go @@ -571,8 +571,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) } } }