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