Skip to content

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

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

sukunrt merged 1 commit into
libp2p:masterfrom
cpeliciari:feature/metrics-reset-trimidle-methods

Conversation

@cpeliciari

Copy link
Copy Markdown
Contributor

No description provided.

@cpeliciari

cpeliciari commented Jul 26, 2025 •

Copy link
Copy Markdown
Contributor Author

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

@sukunrt sukunrt left a comment •

Copy link
Copy Markdown
Member

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

p-shahi commented Aug 5, 2025

Copy link
Copy Markdown
Member

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

@sukunrt
sukunrt merged commit 8e10f84 into libp2p:master Aug 11, 2025
@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