fix: reset bandwidth stats totals every day, and send message size

This commit is contained in:
Richard Ramos 2023-02-01 11:46:01 -04:00 committed by RichΛrd
parent ab2ff4eeb1
commit dc4c1a61b1
2 changed files with 10 additions and 1 deletions

View File

@ -46,6 +46,7 @@ func (c *Client) PushReceivedMessages(filter transport.Filter, sshMessage *types
"messageType": message.Type.String(), "messageType": message.Type.String(),
"receiverKeyUID": c.keyUID, "receiverKeyUID": c.keyUID,
"nodeName": c.nodeName, "nodeName": c.nodeName,
"messageSize": len(sshMessage.Payload),
}) })
} }
body, _ := json.Marshal(postBody) body, _ := json.Marshal(postBody)

View File

@ -563,11 +563,19 @@ func (w *Waku) telemetryBandwidthStats(telemetryServerURL string) {
ticker := time.NewTicker(time.Second * 20) ticker := time.NewTicker(time.Second * 20)
defer ticker.Stop() defer ticker.Stop()
today := time.Now()
for { for {
select { select {
case <-w.quit: case <-w.quit:
return return
case <-ticker.C: case now := <-ticker.C:
// Reset totals when day changes
if now.Day() != today.Day() {
today = now
w.bandwidthCounter.Reset()
}
storeStats := w.bandwidthCounter.GetBandwidthForProtocol(store.StoreID_v20beta4) storeStats := w.bandwidthCounter.GetBandwidthForProtocol(store.StoreID_v20beta4)
relayStats := w.bandwidthCounter.GetBandwidthForProtocol(relay.WakuRelayID_v200) relayStats := w.bandwidthCounter.GetBandwidthForProtocol(relay.WakuRelayID_v200)
go telemetry.PushProtocolStats(relayStats, storeStats) go telemetry.PushProtocolStats(relayStats, storeStats)