README.md
1go-metrics
2==========
3
4Go port of Coda Hale's Metrics library: <https://github.com/codahale/metrics>.
5
6Documentation: <http://godoc.org/github.com/rcrowley/go-metrics>.
7
8Usage
9-----
10
11Create and update metrics:
12
13```go
14c := metrics.NewCounter()
15metrics.Register("foo", c)
16c.Inc(47)
17
18g := metrics.NewGauge()
19metrics.Register("bar", g)
20g.Update(47)
21
22s := metrics.NewExpDecaySample(1028, 0.015) // or metrics.NewUniformSample(1028)
23h := metrics.NewHistogram(s)
24metrics.Register("baz", h)
25h.Update(47)
26
27m := metrics.NewMeter()
28metrics.Register("quux", m)
29m.Mark(47)
30
31t := metrics.NewTimer()
32metrics.Register("bang", t)
33t.Time(func() {})
34t.Update(47)
35```
36
37Periodically log every metric in human-readable form to standard error:
38
39```go
40go metrics.Log(metrics.DefaultRegistry, 60e9, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))
41```
42
43Periodically log every metric in slightly-more-parseable form to syslog:
44
45```go
46w, _ := syslog.Dial("unixgram", "/dev/log", syslog.LOG_INFO, "metrics")
47go metrics.Syslog(metrics.DefaultRegistry, 60e9, w)
48```
49
50Periodically emit every metric to Graphite:
51
52```go
53addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003")
54go metrics.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr)
55```
56
57Periodically emit every metric into InfluxDB:
58
59```go
60import "github.com/rcrowley/go-metrics/influxdb"
61
62go influxdb.Influxdb(metrics.DefaultRegistry, 10e9, &influxdb.Config{
63 Host: "127.0.0.1:8086",
64 Database: "metrics",
65 Username: "test",
66 Password: "test",
67})
68```
69
70Periodically upload every metric to Librato:
71
72```go
73import "github.com/rcrowley/go-metrics/librato"
74
75go librato.Librato(metrics.DefaultRegistry,
76 10e9, // interval
77 "example@example.com", // account owner email address
78 "token", // Librato API token
79 "hostname", // source
80 []float64{0.95}, // precentiles to send
81 time.Millisecond, // time unit
82)
83```
84
85Periodically emit every metric to StatHat:
86
87```go
88import "github.com/rcrowley/go-metrics/stathat"
89
90go stathat.Stathat(metrics.DefaultRegistry, 10e9, "example@example.com")
91```
92
93Installation
94------------
95
96```sh
97go get github.com/rcrowley/go-metrics
98```
99
100StatHat support additionally requires their Go client:
101
102```sh
103go get github.com/stathat/go
104```
105