metrics: expvar support for ResettingTimer

This commit is contained in:
Anton Evangelatov 2018-06-04 12:05:31 +03:00
parent 143c4341d8
commit d6f6cceabc
2 changed files with 42 additions and 0 deletions

View file

@ -134,6 +134,18 @@ func (exp *exp) publishTimer(name string, metric metrics.Timer) {
exp.getFloat(name + ".mean-rate").Set(t.RateMean())
}
func (exp *exp) publishResettingTimer(name string, metric metrics.ResettingTimer) {
t := metric.Snapshot()
ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
exp.getInt(name + ".count").Set(int64(len(t.Values())))
exp.getFloat(name + ".mean").Set(t.Mean())
exp.getInt(name + ".50-percentile").Set(ps[0])
exp.getInt(name + ".75-percentile").Set(ps[1])
exp.getInt(name + ".95-percentile").Set(ps[2])
exp.getInt(name + ".99-percentile").Set(ps[3])
exp.getInt(name + ".999-percentile").Set(ps[4])
}
func (exp *exp) syncToExpvar() {
exp.registry.Each(func(name string, i interface{}) {
switch i.(type) {
@ -149,6 +161,8 @@ func (exp *exp) syncToExpvar() {
exp.publishMeter(name, i.(metrics.Meter))
case metrics.Timer:
exp.publishTimer(name, i.(metrics.Timer))
case metrics.ResettingTimer:
exp.publishResettingTimer(name, i.(metrics.ResettingTimer))
default:
panic(fmt.Sprintf("unsupported type for '%s': %T", name, i))
}

View file

@ -338,6 +338,20 @@ func (api *PublicDebugAPI) Metrics(raw bool) (map[string]interface{}, error) {
},
}
case metrics.ResettingTimer:
t := metric.Snapshot()
ps := t.Percentiles([]float64{0.05, 0.2, 0.5, 0.8, 0.95})
root[name] = map[string]interface{}{
"Overall": format(float64(len(t.Values())), t.Mean()),
"Percentiles": map[string]interface{}{
"5": time.Duration(ps[0]).String(),
"20": time.Duration(ps[1]).String(),
"50": time.Duration(ps[2]).String(),
"80": time.Duration(ps[3]).String(),
"95": time.Duration(ps[4]).String(),
},
}
default:
root[name] = "Unknown metric type"
}
@ -373,6 +387,20 @@ func (api *PublicDebugAPI) Metrics(raw bool) (map[string]interface{}, error) {
},
}
case metrics.ResettingTimer:
t := metric.Snapshot()
ps := t.Percentiles([]float64{0.05, 0.2, 0.5, 0.8, 0.95})
root[name] = map[string]interface{}{
"Overall": format(float64(len(t.Values())), t.Mean()),
"Percentiles": map[string]interface{}{
"5": time.Duration(ps[0]).String(),
"20": time.Duration(ps[1]).String(),
"50": time.Duration(ps[2]).String(),
"80": time.Duration(ps[3]).String(),
"95": time.Duration(ps[4]).String(),
},
}
default:
root[name] = "Unknown metric type"
}