| 1 |
## Overview |
| 2 |
|
| 3 |
Package `statsd` provides a Go [dogstatsd](http://docs.datadoghq.com/guides/dogstatsd/) client. Dogstatsd extends Statsd, adding tags |
| 4 |
and histograms. |
| 5 |
|
| 6 |
## Get the code |
| 7 |
|
| 8 |
$ go get github.com/DataDog/datadog-go/statsd |
| 9 |
|
| 10 |
## Usage |
| 11 |
|
| 12 |
```go |
| 13 |
// Create the client |
| 14 |
c, err := statsd.New("127.0.0.1:8125") |
| 15 |
if err != nil { |
| 16 |
log.Fatal(err) |
| 17 |
} |
| 18 |
// Prefix every metric with the app name |
| 19 |
c.Namespace = "flubber." |
| 20 |
// Send the EC2 availability zone as a tag with every metric |
| 21 |
c.Tags = append(c.Tags, "us-east-1a") |
| 22 |
|
| 23 |
// Do some metrics! |
| 24 |
err = c.Gauge("request.queue_depth", 12, nil, 1) |
| 25 |
err = c.Timing("request.duration", duration, nil, 1) // Uses a time.Duration! |
| 26 |
err = c.TimeInMilliseconds("request", 12, nil, 1) |
| 27 |
err = c.Incr("request.count_total", nil, 1) |
| 28 |
err = c.Decr("request.count_total", nil, 1) |
| 29 |
err = c.Count("request.count_total", 2, nil, 1) |
| 30 |
``` |
| 31 |
|
| 32 |
## Buffering Client |
| 33 |
|
| 34 |
DogStatsD accepts packets with multiple statsd payloads in them. Using the BufferingClient via `NewBufferingClient` will buffer up commands and send them when the buffer is reached or after 100msec. |
| 35 |
|
| 36 |
## Unix Domain Sockets Client |
| 37 |
|
| 38 |
DogStatsD version 6 accepts packets through a Unix Socket datagram connection. You can use this protocol by giving a |
| 39 |
`unix:///path/to/dsd.socket` addr argument to the `New` or `NewBufferingClient`. |
| 40 |
|
| 41 |
With this protocol, writes can become blocking if the server's receiving buffer is full. Our default behaviour is to |
| 42 |
timeout and drop the packet after 1 ms. You can set a custom timeout duration via the `SetWriteTimeout` method. |
| 43 |
|
| 44 |
The default mode is to pass write errors from the socket to the caller. This includes write errors the library will |
| 45 |
automatically recover from (DogStatsD server not ready yet or is restarting). You can drop these errors and emulate |
| 46 |
the UDP behaviour by setting the `SkipErrors` property to `true`. Please note that packets will be dropped in both modes. |
| 47 |
|
| 48 |
## Development |
| 49 |
|
| 50 |
Run the tests with: |
| 51 |
|
| 52 |
$ go test |
| 53 |
|
| 54 |
## Documentation |
| 55 |
|
| 56 |
Please see: http://godoc.org/github.com/DataDog/datadog-go/statsd |
| 57 |
|
| 58 |
## License |
| 59 |
|
| 60 |
go-dogstatsd is released under the [MIT license](http://www.opensource.org/licenses/mit-license.php). |
| 61 |
|
| 62 |
## Credits |
| 63 |
|
| 64 |
Original code by [ooyala](https://github.com/ooyala/go-dogstatsd). |