github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/rcrowley/go-metrics/README.md (about) 1 go-metrics 2 ========== 3 4  5 6 Go port of Coda Hale's Metrics library: <https://github.com/dropwizard/metrics>. 7 8 Documentation: <http://godoc.org/github.com/rcrowley/go-metrics>. 9 10 Usage 11 ----- 12 13 Create and update metrics: 14 15 ```go 16 c := metrics.NewCounter() 17 metrics.Register("foo", c) 18 c.Inc(47) 19 20 g := metrics.NewGauge() 21 metrics.Register("bar", g) 22 g.Update(47) 23 24 s := metrics.NewExpDecaySample(1028, 0.015) // or metrics.NewUniformSample(1028) 25 h := metrics.NewHistogram(s) 26 metrics.Register("baz", h) 27 h.Update(47) 28 29 m := metrics.NewMeter() 30 metrics.Register("quux", m) 31 m.Mark(47) 32 33 t := metrics.NewTimer() 34 metrics.Register("bang", t) 35 t.Time(func() {}) 36 t.Update(47) 37 ``` 38 39 Periodically log every metric in human-readable form to standard error: 40 41 ```go 42 go metrics.Log(metrics.DefaultRegistry, 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds)) 43 ``` 44 45 Periodically log every metric in slightly-more-parseable form to syslog: 46 47 ```go 48 w, _ := syslog.Dial("unixgram", "/dev/log", syslog.LOG_INFO, "metrics") 49 go metrics.Syslog(metrics.DefaultRegistry, 60e9, w) 50 ``` 51 52 Periodically emit every metric to Graphite using the [Graphite client](https://github.com/cyberdelia/go-metrics-graphite): 53 54 ```go 55 56 import "github.com/cyberdelia/go-metrics-graphite" 57 58 addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003") 59 go graphite.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr) 60 ``` 61 62 Periodically emit every metric into InfluxDB: 63 64 **NOTE:** this has been pulled out of the library due to constant fluctuations 65 in the InfluxDB API. In fact, all client libraries are on their way out. see 66 issues [#121](https://github.com/rcrowley/go-metrics/issues/121) and 67 [#124](https://github.com/rcrowley/go-metrics/issues/124) for progress and details. 68 69 ```go 70 import "github.com/rcrowley/go-metrics/influxdb" 71 72 go influxdb.Influxdb(metrics.DefaultRegistry, 10e9, &influxdb.Config{ 73 Host: "127.0.0.1:8086", 74 Database: "metrics", 75 Username: "test", 76 Password: "test", 77 }) 78 ``` 79 80 Periodically upload every metric to Librato using the [Librato client](https://github.com/mihasya/go-metrics-librato): 81 82 **Note**: the client included with this repository under the `librato` package 83 has been deprecated and moved to the repository linked above. 84 85 ```go 86 import "github.com/mihasya/go-metrics-librato" 87 88 go librato.Librato(metrics.DefaultRegistry, 89 10e9, // interval 90 "example@example.com", // account owner email address 91 "token", // Librato API token 92 "hostname", // source 93 []float64{0.95}, // percentiles to send 94 time.Millisecond, // time unit 95 ) 96 ``` 97 98 Periodically emit every metric to StatHat: 99 100 ```go 101 import "github.com/rcrowley/go-metrics/stathat" 102 103 go stathat.Stathat(metrics.DefaultRegistry, 10e9, "example@example.com") 104 ``` 105 106 Maintain all metrics along with expvars at `/debug/metrics`: 107 108 This uses the same mechanism as [the official expvar](http://golang.org/pkg/expvar/) 109 but exposed under `/debug/metrics`, which shows a json representation of all your usual expvars 110 as well as all your go-metrics. 111 112 113 ```go 114 import "github.com/rcrowley/go-metrics/exp" 115 116 exp.Exp(metrics.DefaultRegistry) 117 ``` 118 119 Installation 120 ------------ 121 122 ```sh 123 go get github.com/rcrowley/go-metrics 124 ``` 125 126 StatHat support additionally requires their Go client: 127 128 ```sh 129 go get github.com/stathat/go 130 ``` 131 132 Publishing Metrics 133 ------------------ 134 135 Clients are available for the following destinations: 136 137 * Librato - [https://github.com/mihasya/go-metrics-librato](https://github.com/mihasya/go-metrics-librato) 138 * Graphite - [https://github.com/cyberdelia/go-metrics-graphite](https://github.com/cyberdelia/go-metrics-graphite) 139 * InfluxDB - [https://github.com/vrischmann/go-metrics-influxdb](https://github.com/vrischmann/go-metrics-influxdb)