forked from rcrowley/go-metrics
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsyslog.go
74 lines (71 loc) · 1.68 KB
/
syslog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// +build !windows
package metrics
import (
"fmt"
"log/syslog"
"time"
)
// Output each metric in the given registry to syslog periodically using
// the given syslogger.
func Syslog(r Registry, d time.Duration, w *syslog.Writer) {
for {
r.Each(func(name string, i interface{}) {
switch m := i.(type) {
case Counter:
w.Info(fmt.Sprintf("counter %s: count: %d", name, m.Count()))
case Gauge:
w.Info(fmt.Sprintf("gauge %s: value: %d", name, m.Value()))
case Healthcheck:
m.Check()
w.Info(fmt.Sprintf("healthcheck %s: error: %v", name, m.Error()))
case Histogram:
ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
w.Info(fmt.Sprintf(
"histogram %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f",
name,
m.Count(),
m.Min(),
m.Max(),
m.Mean(),
m.StdDev(),
ps[0],
ps[1],
ps[2],
ps[3],
ps[4],
))
case Meter:
w.Info(fmt.Sprintf(
"meter %s: count: %d 1-min: %.2f 5-min: %.2f 15-min: %.2f mean: %.2f",
name,
m.Count(),
m.Rate1(),
m.Rate5(),
m.Rate15(),
m.RateMean(),
))
case Timer:
ps := m.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
w.Info(fmt.Sprintf(
"timer %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f 1-min: %.2f 5-min: %.2f 15-min: %.2f mean: %.2f",
name,
m.Count(),
m.Min(),
m.Max(),
m.Mean(),
m.StdDev(),
ps[0],
ps[1],
ps[2],
ps[3],
ps[4],
m.Rate1(),
m.Rate5(),
m.Rate15(),
m.RateMean(),
))
}
})
time.Sleep(d)
}
}