Go Client library for StatsD. Contains a direct and a buffered client. The buffered version will hold and aggregate values for the same key in memory before flushing them at the defined frequency.
This client library was inspired by the one embedded in the Bit.ly NSQ project, and extended to support some extra custom events used at DataSift.
go get github.com/quipo/statsd
Increment
- Count occurrences per second/minute of a specific eventDecrement
- Count occurrences per second/minute of a specific eventTiming
- To track a duration eventPrecisionTiming
- To track a duration eventGauge
(int) / FGauge
(float) - Gauges are a constant data type. They are not subject to averaging, and they don’t change unless you change them. That is, once you set a gauge value, it will be a flat line on the graph until you change it againGaugeDelta
(int) / FGaugeDelta
(float) - Same as above, but as a delta change to the previous value rather than a new absolute valueAbsolute
(int) / FAbsolute
(float) - Absolute-valued metric (not averaged/aggregated)Total
- Continously increasing value, e.g. read operations since bootpackage main
import (
"log"
"os"
"time"
"github.com/quipo/statsd"
)
func main() {
// init
prefix := "myproject."
statsdclient := statsd.NewStatsdClient("localhost:8125", prefix)
err := statsdclient.CreateSocket()
if nil != err {
log.Println(err)
os.Exit(1)
}
interval := time.Second * 2 // aggregate stats and flush every 2 seconds
stats := statsd.NewStatsdBuffer(interval, statsdclient)
defer stats.Close()
// not buffered: send immediately
statsdclient.Incr("mymetric", 4)
// buffered: aggregate in memory before flushing
stats.Incr("mymetric", 1)
stats.Incr("mymetric", 3)
stats.Incr("mymetric", 1)
stats.Incr("mymetric", 1)
}
The string %HOST%
in the metric name will automatically be replaced with the hostname of the server the event is sent from.
HEAD
:
*
v.1.2.0
: Sample rate support (thanks to Hongjian Zhu)
SendEvents
function to Statsd
interface;v.1.0.0
: First stable release
v.0.0.9
: Added memoization to reduce memory allocations
v.0.0.8
: Pre-release
Lorenzo Alberton
See LICENSE document