github.com/calmw/ethereum@v0.1.1/metrics/syslog.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package metrics 5 6 import ( 7 "fmt" 8 "log/syslog" 9 "time" 10 ) 11 12 // Output each metric in the given registry to syslog periodically using 13 // the given syslogger. 14 func Syslog(r Registry, d time.Duration, w *syslog.Writer) { 15 for range time.Tick(d) { 16 r.Each(func(name string, i interface{}) { 17 switch metric := i.(type) { 18 case Counter: 19 w.Info(fmt.Sprintf("counter %s: count: %d", name, metric.Count())) 20 case CounterFloat64: 21 w.Info(fmt.Sprintf("counter %s: count: %f", name, metric.Count())) 22 case Gauge: 23 w.Info(fmt.Sprintf("gauge %s: value: %d", name, metric.Value())) 24 case GaugeFloat64: 25 w.Info(fmt.Sprintf("gauge %s: value: %f", name, metric.Value())) 26 case Healthcheck: 27 metric.Check() 28 w.Info(fmt.Sprintf("healthcheck %s: error: %v", name, metric.Error())) 29 case Histogram: 30 h := metric.Snapshot() 31 ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) 32 w.Info(fmt.Sprintf( 33 "histogram %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f", 34 name, 35 h.Count(), 36 h.Min(), 37 h.Max(), 38 h.Mean(), 39 h.StdDev(), 40 ps[0], 41 ps[1], 42 ps[2], 43 ps[3], 44 ps[4], 45 )) 46 case Meter: 47 m := metric.Snapshot() 48 w.Info(fmt.Sprintf( 49 "meter %s: count: %d 1-min: %.2f 5-min: %.2f 15-min: %.2f mean: %.2f", 50 name, 51 m.Count(), 52 m.Rate1(), 53 m.Rate5(), 54 m.Rate15(), 55 m.RateMean(), 56 )) 57 case Timer: 58 t := metric.Snapshot() 59 ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) 60 w.Info(fmt.Sprintf( 61 "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-rate: %.2f", 62 name, 63 t.Count(), 64 t.Min(), 65 t.Max(), 66 t.Mean(), 67 t.StdDev(), 68 ps[0], 69 ps[1], 70 ps[2], 71 ps[3], 72 ps[4], 73 t.Rate1(), 74 t.Rate5(), 75 t.Rate15(), 76 t.RateMean(), 77 )) 78 } 79 }) 80 } 81 }