diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-06-22 17:00:55 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-06-24 23:34:04 +0800 |
commit | 7bd71fa80071f86ca86ed7ef64ab51c88cabe7d4 (patch) | |
tree | 9f770d2f59ca1a3053ebf7aa7921a122aa3bc388 /Godeps/_workspace/src/github.com/rcrowley/go-metrics/log.go | |
parent | 7f92e708c504e1c4a7382c68b5a4ed68db9c8deb (diff) | |
download | dexon-7bd71fa80071f86ca86ed7ef64ab51c88cabe7d4.tar dexon-7bd71fa80071f86ca86ed7ef64ab51c88cabe7d4.tar.gz dexon-7bd71fa80071f86ca86ed7ef64ab51c88cabe7d4.tar.bz2 dexon-7bd71fa80071f86ca86ed7ef64ab51c88cabe7d4.tar.lz dexon-7bd71fa80071f86ca86ed7ef64ab51c88cabe7d4.tar.xz dexon-7bd71fa80071f86ca86ed7ef64ab51c88cabe7d4.tar.zst dexon-7bd71fa80071f86ca86ed7ef64ab51c88cabe7d4.zip |
godeps: pull in go-metrics
Diffstat (limited to 'Godeps/_workspace/src/github.com/rcrowley/go-metrics/log.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/rcrowley/go-metrics/log.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/rcrowley/go-metrics/log.go b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/log.go new file mode 100644 index 000000000..278a8a441 --- /dev/null +++ b/Godeps/_workspace/src/github.com/rcrowley/go-metrics/log.go @@ -0,0 +1,70 @@ +package metrics + +import ( + "log" + "time" +) + +// Output each metric in the given registry periodically using the given +// logger. +func Log(r Registry, d time.Duration, l *log.Logger) { + for _ = range time.Tick(d) { + r.Each(func(name string, i interface{}) { + switch metric := i.(type) { + case Counter: + l.Printf("counter %s\n", name) + l.Printf(" count: %9d\n", metric.Count()) + case Gauge: + l.Printf("gauge %s\n", name) + l.Printf(" value: %9d\n", metric.Value()) + case GaugeFloat64: + l.Printf("gauge %s\n", name) + l.Printf(" value: %f\n", metric.Value()) + case Healthcheck: + metric.Check() + l.Printf("healthcheck %s\n", name) + l.Printf(" error: %v\n", metric.Error()) + case Histogram: + h := metric.Snapshot() + ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) + l.Printf("histogram %s\n", name) + l.Printf(" count: %9d\n", h.Count()) + l.Printf(" min: %9d\n", h.Min()) + l.Printf(" max: %9d\n", h.Max()) + l.Printf(" mean: %12.2f\n", h.Mean()) + l.Printf(" stddev: %12.2f\n", h.StdDev()) + l.Printf(" median: %12.2f\n", ps[0]) + l.Printf(" 75%%: %12.2f\n", ps[1]) + l.Printf(" 95%%: %12.2f\n", ps[2]) + l.Printf(" 99%%: %12.2f\n", ps[3]) + l.Printf(" 99.9%%: %12.2f\n", ps[4]) + case Meter: + m := metric.Snapshot() + l.Printf("meter %s\n", name) + l.Printf(" count: %9d\n", m.Count()) + l.Printf(" 1-min rate: %12.2f\n", m.Rate1()) + l.Printf(" 5-min rate: %12.2f\n", m.Rate5()) + l.Printf(" 15-min rate: %12.2f\n", m.Rate15()) + l.Printf(" mean rate: %12.2f\n", m.RateMean()) + case Timer: + t := metric.Snapshot() + ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) + l.Printf("timer %s\n", name) + l.Printf(" count: %9d\n", t.Count()) + l.Printf(" min: %9d\n", t.Min()) + l.Printf(" max: %9d\n", t.Max()) + l.Printf(" mean: %12.2f\n", t.Mean()) + l.Printf(" stddev: %12.2f\n", t.StdDev()) + l.Printf(" median: %12.2f\n", ps[0]) + l.Printf(" 75%%: %12.2f\n", ps[1]) + l.Printf(" 95%%: %12.2f\n", ps[2]) + l.Printf(" 99%%: %12.2f\n", ps[3]) + l.Printf(" 99.9%%: %12.2f\n", ps[4]) + l.Printf(" 1-min rate: %12.2f\n", t.Rate1()) + l.Printf(" 5-min rate: %12.2f\n", t.Rate5()) + l.Printf(" 15-min rate: %12.2f\n", t.Rate15()) + l.Printf(" mean rate: %12.2f\n", t.RateMean()) + } + }) + } +} |