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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
|
|
||||||
"github.com/rcrowley/go-metrics"
|
"github.com/rcrowley/go-metrics"
|
||||||
)
|
)
|
||||||
@ -18,30 +19,48 @@ func TimerMap(timer metrics.Timer) map[string]interface{} {
|
|||||||
t := timer.Snapshot()
|
t := timer.Snapshot()
|
||||||
p := t.Percentiles(timerPercentiles)
|
p := t.Percentiles(timerPercentiles)
|
||||||
|
|
||||||
|
percentileKeys := []string{"median", "75%", "95%", "99%", "99.9%"}
|
||||||
percentiles := make(map[string]interface{})
|
percentiles := make(map[string]interface{})
|
||||||
percentiles["median"] = p[0]
|
for i, pi := range p {
|
||||||
percentiles["75%"] = p[1]
|
if !isNanOrInf(pi) {
|
||||||
percentiles["95%"] = p[2]
|
percentileKey := percentileKeys[i]
|
||||||
percentiles["99%"] = p[3]
|
percentiles[percentileKey] = pi
|
||||||
percentiles["99.9%"] = p[4]
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rateKeys := []string{"1-min", "5-min", "15-min", "mean"}
|
||||||
rates := make(map[string]interface{})
|
rates := make(map[string]interface{})
|
||||||
rates["1-min"] = t.Rate1()
|
for i, ri := range []float64{t.Rate1(), t.Rate5(), t.Rate15(), t.RateMean()} {
|
||||||
rates["5-min"] = t.Rate5()
|
if !isNanOrInf(ri) {
|
||||||
rates["15-min"] = t.Rate15()
|
rateKey := rateKeys[i]
|
||||||
rates["mean"] = t.RateMean()
|
rates[rateKey] = ri
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rv["count"] = t.Count()
|
rv["count"] = t.Count()
|
||||||
rv["min"] = t.Min()
|
rv["min"] = t.Min()
|
||||||
rv["max"] = t.Max()
|
rv["max"] = t.Max()
|
||||||
rv["mean"] = t.Mean()
|
mean := t.Mean()
|
||||||
rv["stddev"] = t.StdDev()
|
if !isNanOrInf(mean) {
|
||||||
|
rv["mean"] = mean
|
||||||
|
}
|
||||||
|
stddev := t.StdDev()
|
||||||
|
if !isNanOrInf(stddev) {
|
||||||
|
rv["stddev"] = stddev
|
||||||
|
}
|
||||||
rv["percentiles"] = percentiles
|
rv["percentiles"] = percentiles
|
||||||
rv["rates"] = rates
|
rv["rates"] = rates
|
||||||
|
|
||||||
return rv
|
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) {
|
func WriteTimerJSON(w io.Writer, timer metrics.Timer) {
|
||||||
t := timer.Snapshot()
|
t := timer.Snapshot()
|
||||||
p := t.Percentiles(timerPercentiles)
|
p := t.Percentiles(timerPercentiles)
|
||||||
|
Loading…
Reference in New Issue
Block a user