github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/metrics/syslog.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:42</date> 10 //</624342651461701632> 11 12 //+建设!窗户 13 14 package metrics 15 16 import ( 17 "fmt" 18 "log/syslog" 19 "time" 20 ) 21 22 //使用以下命令定期将给定注册表中的每个度量输出到syslog 23 //给定的系统记录器。 24 func Syslog(r Registry, d time.Duration, w *syslog.Writer) { 25 for range time.Tick(d) { 26 r.Each(func(name string, i interface{}) { 27 switch metric := i.(type) { 28 case Counter: 29 w.Info(fmt.Sprintf("counter %s: count: %d", name, metric.Count())) 30 case Gauge: 31 w.Info(fmt.Sprintf("gauge %s: value: %d", name, metric.Value())) 32 case GaugeFloat64: 33 w.Info(fmt.Sprintf("gauge %s: value: %f", name, metric.Value())) 34 case Healthcheck: 35 metric.Check() 36 w.Info(fmt.Sprintf("healthcheck %s: error: %v", name, metric.Error())) 37 case Histogram: 38 h := metric.Snapshot() 39 ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) 40 w.Info(fmt.Sprintf( 41 "histogram %s: count: %d min: %d max: %d mean: %.2f stddev: %.2f median: %.2f 75%%: %.2f 95%%: %.2f 99%%: %.2f 99.9%%: %.2f", 42 name, 43 h.Count(), 44 h.Min(), 45 h.Max(), 46 h.Mean(), 47 h.StdDev(), 48 ps[0], 49 ps[1], 50 ps[2], 51 ps[3], 52 ps[4], 53 )) 54 case Meter: 55 m := metric.Snapshot() 56 w.Info(fmt.Sprintf( 57 "meter %s: count: %d 1-min: %.2f 5-min: %.2f 15-min: %.2f mean: %.2f", 58 name, 59 m.Count(), 60 m.Rate1(), 61 m.Rate5(), 62 m.Rate15(), 63 m.RateMean(), 64 )) 65 case Timer: 66 t := metric.Snapshot() 67 ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999}) 68 w.Info(fmt.Sprintf( 69 "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", 70 name, 71 t.Count(), 72 t.Min(), 73 t.Max(), 74 t.Mean(), 75 t.StdDev(), 76 ps[0], 77 ps[1], 78 ps[2], 79 ps[3], 80 ps[4], 81 t.Rate1(), 82 t.Rate5(), 83 t.Rate15(), 84 t.RateMean(), 85 )) 86 } 87 }) 88 } 89 } 90