Skip to content

feat(metrics): add Reset and TrimIdle methods to reporter interface#3343

Merged
sukunrt merged 1 commit intolibp2p:masterfrom
cpeliciari:feature/metrics-reset-trimidle-methods
Aug 11, 2025
Merged

feat(metrics): add Reset and TrimIdle methods to reporter interface#3343
sukunrt merged 1 commit intolibp2p:masterfrom
cpeliciari:feature/metrics-reset-trimidle-methods

Conversation

@cpeliciari
Copy link
Copy Markdown
Contributor

No description provided.

@cpeliciari
Copy link
Copy Markdown
Contributor Author

cpeliciari commented Jul 26, 2025

@sukunrt This link is no longer available https://github.com/sonr-io/sonr

Copy link
Copy Markdown
Member

@sukunrt sukunrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you using these?

@cpeliciari
Copy link
Copy Markdown
Contributor Author

I'm monitoring bandwidth usage, and sometimes I need to reset it.

I noticed that in core/metrics/bandwidth.go, the Reset and TrimIdle methods already exist. This allows others to reset the bandwidth status as well.

// Reset clears all stats.
func (bwc *BandwidthCounter) Reset() {
bwc.totalIn.Reset()
bwc.totalOut.Reset()
bwc.protocolIn.Clear()
bwc.protocolOut.Clear()
bwc.peerIn.Clear()
bwc.peerOut.Clear()
}
// TrimIdle trims all timers idle since the given time.
func (bwc *BandwidthCounter) TrimIdle(since time.Time) {
bwc.peerIn.TrimIdle(since)
bwc.peerOut.TrimIdle(since)
bwc.protocolIn.TrimIdle(since)
bwc.protocolOut.TrimIdle(since)
}

@p-shahi
Copy link
Copy Markdown
Member

p-shahi commented Aug 5, 2025

@cpeliciari Can you take a look at the CI failure?

@sukunrt sukunrt merged commit 8e10f84 into libp2p:master Aug 11, 2025
8 of 9 checks passed
@cpeliciari cpeliciari deleted the feature/metrics-reset-trimidle-methods branch August 11, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants