Merge pull request #370 from mschoch/safermetrics
do not put +/-Inf or NaN values into the stats map
This commit is contained in:
commit
95b03f9b54
|
@ -3,6 +3,7 @@ package metrics
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
|
||||
"github.com/rcrowley/go-metrics"
|
||||
)
|
||||
|
@ -18,30 +19,48 @@ func TimerMap(timer metrics.Timer) map[string]interface{} {
|
|||
t := timer.Snapshot()
|
||||
p := t.Percentiles(timerPercentiles)
|
||||
|
||||
percentileKeys := []string{"median", "75%", "95%", "99%", "99.9%"}
|
||||
percentiles := make(map[string]interface{})
|
||||
percentiles["median"] = p[0]
|
||||
percentiles["75%"] = p[1]
|
||||
percentiles["95%"] = p[2]
|
||||
percentiles["99%"] = p[3]
|
||||
percentiles["99.9%"] = p[4]
|
||||
for i, pi := range p {
|
||||
if !isNanOrInf(pi) {
|
||||
percentileKey := percentileKeys[i]
|
||||
percentiles[percentileKey] = pi
|
||||
}
|
||||
}
|
||||
|
||||
rateKeys := []string{"1-min", "5-min", "15-min", "mean"}
|
||||
rates := make(map[string]interface{})
|
||||
rates["1-min"] = t.Rate1()
|
||||
rates["5-min"] = t.Rate5()
|
||||
rates["15-min"] = t.Rate15()
|
||||
rates["mean"] = t.RateMean()
|
||||
for i, ri := range []float64{t.Rate1(), t.Rate5(), t.Rate15(), t.RateMean()} {
|
||||
if !isNanOrInf(ri) {
|
||||
rateKey := rateKeys[i]
|
||||
rates[rateKey] = ri
|
||||
}
|
||||
}
|
||||
|
||||
rv["count"] = t.Count()
|
||||
rv["min"] = t.Min()
|
||||
rv["max"] = t.Max()
|
||||
rv["mean"] = t.Mean()
|
||||
rv["stddev"] = t.StdDev()
|
||||
mean := t.Mean()
|
||||
if !isNanOrInf(mean) {
|
||||
rv["mean"] = mean
|
||||
}
|
||||
stddev := t.StdDev()
|
||||
if !isNanOrInf(stddev) {
|
||||
rv["stddev"] = stddev
|
||||
}
|
||||
rv["percentiles"] = percentiles
|
||||
rv["rates"] = rates
|
||||
|
||||
return rv
|
||||
}
|
||||
|
||||
func isNanOrInf(v float64) bool {
|
||||
if math.IsNaN(v) || math.IsInf(v, 0) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func WriteTimerJSON(w io.Writer, timer metrics.Timer) {
|
||||
t := timer.Snapshot()
|
||||
p := t.Percentiles(timerPercentiles)
|
||||
|
|
Loading…
Reference in New Issue
Block a user