metrics: expvar support for ResettingTimer (#16878)

* metrics: expvar support for ResettingTimer

* metrics: use integers for percentiles; remove Overall

* metrics: fix edge-case panic for index-out-of-range
This commit is contained in:
Anton Evangelatov
2018-06-04 13:05:16 +03:00
committed by Péter Szilágyi
parent 143c4341d8
commit be2aec092d
4 changed files with 154 additions and 1 deletions

View File

@ -338,6 +338,21 @@ func (api *PublicDebugAPI) Metrics(raw bool) (map[string]interface{}, error) {
},
}
case metrics.ResettingTimer:
t := metric.Snapshot()
ps := t.Percentiles([]float64{5, 20, 50, 80, 95})
root[name] = map[string]interface{}{
"Measurements": len(t.Values()),
"Mean": time.Duration(t.Mean()).String(),
"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 +388,21 @@ func (api *PublicDebugAPI) Metrics(raw bool) (map[string]interface{}, error) {
},
}
case metrics.ResettingTimer:
t := metric.Snapshot()
ps := t.Percentiles([]float64{5, 20, 50, 80, 95})
root[name] = map[string]interface{}{
"Measurements": len(t.Values()),
"Mean": time.Duration(t.Mean()).String(),
"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"
}