• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

cmd/H03-May-2018-199159

exp/H03-May-2018-157131

librato/H03-May-2018-339297

stathat/H03-May-2018-7065

.gitignoreH A D03-May-2018135 109

.travis.ymlH A D03-May-2018236 1814

LICENSEH A D03-May-20181.5 KiB3024

README.mdH A D03-May-20184.5 KiB169122

counter.goH A D03-May-20182.5 KiB11365

counter_test.goH A D03-May-20181.4 KiB7867

debug.goH A D03-May-20182.6 KiB7749

debug_test.goH A D03-May-2018849 4944

ewma.goH A D03-May-20183.8 KiB13983

ewma_test.goH A D03-May-20187.4 KiB259248

gauge.goH A D03-May-20182.8 KiB12173

gauge_float64.goH A D03-May-20183.3 KiB12678

gauge_float64_test.goH A D03-May-20181.5 KiB7061

gauge_test.goH A D03-May-20181.6 KiB8877

graphite.goH A D03-May-20184.7 KiB11497

graphite_test.goH A D03-May-2018490 2319

healthcheck.goH A D03-May-20181.5 KiB6234

histogram.goH A D03-May-20186.1 KiB20398

histogram_test.goH A D03-May-20182.3 KiB9688

json.goH A D03-May-2018753 3220

json_test.goH A D03-May-2018536 2925

log.goH A D03-May-20182.9 KiB8173

memory.mdH A D03-May-20185.2 KiB286236

meter.goH A D03-May-20186.6 KiB258168

meter_test.goH A D03-May-20182 KiB10896

metrics.goH A D03-May-2018461 142

metrics_test.goH A D03-May-20182 KiB12571

opentsdb.goH A D03-May-20185.4 KiB120105

opentsdb_test.goH A D03-May-2018438 2218

registry.goH A D03-May-20189.7 KiB364259

registry_test.goH A D03-May-20186.7 KiB364317

runtime.goH A D03-May-20188.6 KiB213184

runtime_cgo.goH A D03-May-2018128 115

runtime_gccpufraction.goH A D03-May-2018142 105

runtime_no_cgo.goH A D03-May-201881 84

runtime_no_gccpufraction.goH A D03-May-2018122 105

runtime_test.goH A D03-May-20182 KiB8981

sample.goH A D03-May-201814.7 KiB617431

sample_test.goH A D03-May-20188.5 KiB364329

syslog.goH A D03-May-20181.9 KiB7972

timer.goH A D03-May-20188.7 KiB330185

timer_test.goH A D03-May-20182.3 KiB10293

validate.shH A D03-May-2018245 114

writer.goH A D03-May-20183.5 KiB10186

writer_test.goH A D03-May-2018341 2319

README.md

1go-metrics
2==========
3
4![travis build status](https://travis-ci.org/rcrowley/go-metrics.svg?branch=master)
5
6Go port of Coda Hale's Metrics library: <https://github.com/dropwizard/metrics>.
7
8Documentation: <http://godoc.org/github.com/rcrowley/go-metrics>.
9
10Usage
11-----
12
13Create and update metrics:
14
15```go
16c := metrics.NewCounter()
17metrics.Register("foo", c)
18c.Inc(47)
19
20g := metrics.NewGauge()
21metrics.Register("bar", g)
22g.Update(47)
23
24r := NewRegistry()
25g := metrics.NewRegisteredFunctionalGauge("cache-evictions", r, func() int64 { return cache.getEvictionsCount() })
26
27s := metrics.NewExpDecaySample(1028, 0.015) // or metrics.NewUniformSample(1028)
28h := metrics.NewHistogram(s)
29metrics.Register("baz", h)
30h.Update(47)
31
32m := metrics.NewMeter()
33metrics.Register("quux", m)
34m.Mark(47)
35
36t := metrics.NewTimer()
37metrics.Register("bang", t)
38t.Time(func() {})
39t.Update(47)
40```
41
42Register() is not threadsafe. For threadsafe metric registration use
43GetOrRegister:
44
45```go
46t := metrics.GetOrRegisterTimer("account.create.latency", nil)
47t.Time(func() {})
48t.Update(47)
49```
50
51**NOTE:** Be sure to unregister short-lived meters and timers otherwise they will
52leak memory:
53
54```go
55// Will call Stop() on the Meter to allow for garbage collection
56metrics.Unregister("quux")
57// Or similarly for a Timer that embeds a Meter
58metrics.Unregister("bang")
59```
60
61Periodically log every metric in human-readable form to standard error:
62
63```go
64go metrics.Log(metrics.DefaultRegistry, 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))
65```
66
67Periodically log every metric in slightly-more-parseable form to syslog:
68
69```go
70w, _ := syslog.Dial("unixgram", "/dev/log", syslog.LOG_INFO, "metrics")
71go metrics.Syslog(metrics.DefaultRegistry, 60e9, w)
72```
73
74Periodically emit every metric to Graphite using the [Graphite client](https://github.com/cyberdelia/go-metrics-graphite):
75
76```go
77
78import "github.com/cyberdelia/go-metrics-graphite"
79
80addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003")
81go graphite.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr)
82```
83
84Periodically emit every metric into InfluxDB:
85
86**NOTE:** this has been pulled out of the library due to constant fluctuations
87in the InfluxDB API. In fact, all client libraries are on their way out. see
88issues [#121](https://github.com/rcrowley/go-metrics/issues/121) and
89[#124](https://github.com/rcrowley/go-metrics/issues/124) for progress and details.
90
91```go
92import "github.com/vrischmann/go-metrics-influxdb"
93
94go influxdb.InfluxDB(metrics.DefaultRegistry,
95  10e9,
96  "127.0.0.1:8086",
97  "database-name",
98  "username",
99  "password"
100)
101```
102
103Periodically upload every metric to Librato using the [Librato client](https://github.com/mihasya/go-metrics-librato):
104
105**Note**: the client included with this repository under the `librato` package
106has been deprecated and moved to the repository linked above.
107
108```go
109import "github.com/mihasya/go-metrics-librato"
110
111go librato.Librato(metrics.DefaultRegistry,
112    10e9,                  // interval
113    "example@example.com", // account owner email address
114    "token",               // Librato API token
115    "hostname",            // source
116    []float64{0.95},       // percentiles to send
117    time.Millisecond,      // time unit
118)
119```
120
121Periodically emit every metric to StatHat:
122
123```go
124import "github.com/rcrowley/go-metrics/stathat"
125
126go stathat.Stathat(metrics.DefaultRegistry, 10e9, "example@example.com")
127```
128
129Maintain all metrics along with expvars at `/debug/metrics`:
130
131This uses the same mechanism as [the official expvar](http://golang.org/pkg/expvar/)
132but exposed under `/debug/metrics`, which shows a json representation of all your usual expvars
133as well as all your go-metrics.
134
135
136```go
137import "github.com/rcrowley/go-metrics/exp"
138
139exp.Exp(metrics.DefaultRegistry)
140```
141
142Installation
143------------
144
145```sh
146go get github.com/rcrowley/go-metrics
147```
148
149StatHat support additionally requires their Go client:
150
151```sh
152go get github.com/stathat/go
153```
154
155Publishing Metrics
156------------------
157
158Clients are available for the following destinations:
159
160* Librato - https://github.com/mihasya/go-metrics-librato
161* Graphite - https://github.com/cyberdelia/go-metrics-graphite
162* InfluxDB - https://github.com/vrischmann/go-metrics-influxdb
163* Ganglia - https://github.com/appscode/metlia
164* Prometheus - https://github.com/deathowl/go-metrics-prometheus
165* DataDog - https://github.com/syntaqx/go-metrics-datadog
166* SignalFX - https://github.com/pascallouisperez/go-metrics-signalfx
167* Honeycomb - https://github.com/getspine/go-metrics-honeycomb
168* Wavefront - https://github.com/wavefrontHQ/go-metrics-wavefront
169