mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00

for i in github.com/BurntSushi/toml github.com/coreos/go-etcd/etcd github.com/coreos/go-log/log github.com/gorilla/context github.com/rcrowley/go-metrics bitbucket.org/kardianos/osext github.com/coreos/go-systemd/journal github.com/coreos/raft code.google.com/p/goprotobuf/proto ; do goven -copy -rewrite $i; done
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package metrics
|
|
|
|
import "encoding/json"
|
|
|
|
// MarshalJSON returns a byte slice containing a JSON representation of all
|
|
// the metrics in the Registry.
|
|
func (r StandardRegistry) MarshalJSON() ([]byte, error) {
|
|
data := make(map[string]map[string]interface{})
|
|
r.Each(func(name string, i interface{}) {
|
|
values := make(map[string]interface{})
|
|
switch metric := i.(type) {
|
|
case Counter:
|
|
values["count"] = metric.Count()
|
|
case Gauge:
|
|
values["value"] = metric.Value()
|
|
case Healthcheck:
|
|
metric.Check()
|
|
values["error"] = metric.Error().Error()
|
|
case Histogram:
|
|
h := metric.Snapshot()
|
|
ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
|
|
values["count"] = h.Count()
|
|
values["min"] = h.Min()
|
|
values["max"] = h.Max()
|
|
values["mean"] = h.Mean()
|
|
values["stddev"] = h.StdDev()
|
|
values["median"] = ps[0]
|
|
values["75%"] = ps[1]
|
|
values["95%"] = ps[2]
|
|
values["99%"] = ps[3]
|
|
values["99.9%"] = ps[4]
|
|
case Meter:
|
|
m := metric.Snapshot()
|
|
values["count"] = m.Count()
|
|
values["1m.rate"] = m.Rate1()
|
|
values["5m.rate"] = m.Rate5()
|
|
values["15m.rate"] = m.Rate15()
|
|
values["mean.rate"] = m.RateMean()
|
|
case Timer:
|
|
t := metric.Snapshot()
|
|
ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
|
|
values["count"] = t.Count()
|
|
values["min"] = t.Min()
|
|
values["max"] = t.Max()
|
|
values["mean"] = t.Mean()
|
|
values["stddev"] = t.StdDev()
|
|
values["median"] = ps[0]
|
|
values["75%"] = ps[1]
|
|
values["95%"] = ps[2]
|
|
values["99%"] = ps[3]
|
|
values["99.9%"] = ps[4]
|
|
values["1m.rate"] = t.Rate1()
|
|
values["5m.rate"] = t.Rate5()
|
|
values["15m.rate"] = t.Rate15()
|
|
values["mean.rate"] = t.RateMean()
|
|
}
|
|
data[name] = values
|
|
})
|
|
return json.Marshal(data)
|
|
}
|