forked from cerc-io/plugeth
eth/protocols, metrics: use resetting histograms for rare packets
This commit is contained in:
parent
efe0229768
commit
2550e46269
@ -246,7 +246,11 @@ func handleMessage(backend Backend, peer *Peer) error {
|
|||||||
if metrics.Enabled {
|
if metrics.Enabled {
|
||||||
h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)
|
h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)
|
||||||
defer func(start time.Time) {
|
defer func(start time.Time) {
|
||||||
sampler := func() metrics.Sample { return metrics.NewExpDecaySample(1028, 0.015) }
|
sampler := func() metrics.Sample {
|
||||||
|
return metrics.ResettingSample(
|
||||||
|
metrics.NewExpDecaySample(1028, 0.015),
|
||||||
|
)
|
||||||
|
}
|
||||||
metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(time.Since(start).Microseconds())
|
metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(time.Since(start).Microseconds())
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,11 @@ func handleMessage(backend Backend, peer *Peer) error {
|
|||||||
if metrics.Enabled {
|
if metrics.Enabled {
|
||||||
h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)
|
h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)
|
||||||
defer func(start time.Time) {
|
defer func(start time.Time) {
|
||||||
sampler := func() metrics.Sample { return metrics.NewExpDecaySample(1028, 0.015) }
|
sampler := func() metrics.Sample {
|
||||||
|
return metrics.ResettingSample(
|
||||||
|
metrics.NewExpDecaySample(1028, 0.015),
|
||||||
|
)
|
||||||
|
}
|
||||||
metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(time.Since(start).Microseconds())
|
metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(time.Since(start).Microseconds())
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
}
|
}
|
||||||
|
24
metrics/resetting_sample.go
Normal file
24
metrics/resetting_sample.go
Normal file
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user