forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eth/protocols, metrics: use resetting histograms for rare packets
- Loading branch information
Showing
3 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package metrics | ||
|
||
// ResettingSample converts an ordinary sample into one that resets whenever its | ||
// snapshot is retrieved. This will break for multi-monitor systems, but when only | ||
// a single metric is being pushed out, this ensure that low-frequency events don't | ||
// skew th charts indefinitely. | ||
func ResettingSample(sample Sample) Sample { | ||
return &resettingSample{ | ||
Sample: sample, | ||
} | ||
} | ||
|
||
// resettingSample is a simple wrapper around a sample that resets it upon the | ||
// snapshot retrieval. | ||
type resettingSample struct { | ||
Sample | ||
} | ||
|
||
// Snapshot returns a read-only copy of the sample with the original reset. | ||
func (rs *resettingSample) Snapshot() Sample { | ||
s := rs.Sample.Snapshot() | ||
rs.Sample.Clear() | ||
return s | ||
} |