Skip to content

Commit

Permalink
fix: bandwidthCounter should be reset each time it is retrieved other…
Browse files Browse the repository at this point in the history
…wise it behaves like an accumulator
  • Loading branch information
richard-ramos committed Sep 30, 2024
1 parent 031b534 commit 823db33
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions wakuv2/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,20 +519,14 @@ func (w *Waku) telemetryBandwidthStats(telemetryServerURL string) {
ticker := time.NewTicker(time.Second * 20)
defer ticker.Stop()

today := time.Now()

for {
select {
case <-w.ctx.Done():
return
case now := <-ticker.C:
// Reset totals when day changes
if now.Day() != today.Day() {
today = now
w.bandwidthCounter.Reset()
}

go telemetry.PushProtocolStats(w.bandwidthCounter.GetBandwidthByProtocol())
case <-ticker.C:
bandwidthPerProtocol := w.bandwidthCounter.GetBandwidthByProtocol()
w.bandwidthCounter.Reset()
go telemetry.PushProtocolStats(bandwidthPerProtocol)
}
}
}
Expand Down

0 comments on commit 823db33

Please sign in to comment.