github.com/theQRL/go-zond@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.Snapshot().Count())) 20 case CounterFloat64: 21 w.Info(fmt.Sprintf("counter %s: count: %f", name, metric.Snapshot().Count())) 22 case Gauge: 23 w.Info(fmt.Sprintf("gauge %s: value: %d", name, metric.Snapshot().Value())) 24 case GaugeFloat64: 25 w.Info(fmt.Sprintf("gauge %s: value: %f", name, metric.Snapshot().Value())) 26 case GaugeInfo: 27 w.Info(fmt.Sprintf("gauge %s: value: %s", name, metric.Snapshot().Value())) 28 case Healthcheck: 29 metric.Check() 30 w.Info(fmt.Sprintf("healthcheck %s: error: %v", name, metric.Error())) 31 case Histogram: 32 h := metric.Snapshot() 33 ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) 34 w.Info(fmt.Sprintf( 35 "histogram %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f", 36 name, 37 h.Count(), 38 h.Min(), 39 h.Max(), 40 h.Mean(), 41 h.StdDev(), 42 ps[0], 43 ps[1], 44 ps[2], 45 ps[3], 46 ps[4], 47 )) 48 case Meter: 49 m := metric.Snapshot() 50 w.Info(fmt.Sprintf( 51 "meter %s: count: %d 1-min: %.2f 5-min: %.2f 15-min: %.2f mean: %.2f", 52 name, 53 m.Count(), 54 m.Rate1(), 55 m.Rate5(), 56 m.Rate15(), 57 m.RateMean(), 58 )) 59 case Timer: 60 t := metric.Snapshot() 61 ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) 62 w.Info(fmt.Sprintf( 63 "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", 64 name, 65 t.Count(), 66 t.Min(), 67 t.Max(), 68 t.Mean(), 69 t.StdDev(), 70 ps[0], 71 ps[1], 72 ps[2], 73 ps[3], 74 ps[4], 75 t.Rate1(), 76 t.Rate5(), 77 t.Rate15(), 78 t.RateMean(), 79 )) 80 } 81 }) 82 } 83 }