Documentation ¶
Overview ¶
StatsD is a network daemon that runs on the Node.js platform and listens for statistics, like counters and timers, sent over UDP and sends aggregates to one or more pluggable backend services (e.g., Graphite).
StatsD was written at Etsy. We blogged about how it works and why we created it: http://codeascraft.com/2011/02/15/measure-anything-measure-everything/
To install this Go client, use go get:
go get github.com/etsy/statsd
This client's documentation can be found on godoc.org: http://godoc.org/github.com/etsy/statsd/examples/go
Example usage:
package main import ( "github.com/etsy/statsd/examples/go" "time" ) func main() { // Record a start time t1 := time.Now() // Create a new StatsD connection host := "localhost" port := 8125 client := statsd.New(host, port) // Increment a stat counter client.Increment("stat.metric1") // Decrement a stat counter client.Decrement("stat.metric1") // Record an end time t2 := time.Now() // Submit timing information duration := int64(t2.Sub(t1) / time.Millisecond) client.Timing("stat.timer", duration) }
Index ¶
- type StatsdClient
- func (client *StatsdClient) Close()
- func (client *StatsdClient) Decrement(stat string)
- func (client *StatsdClient) DecrementWithSampling(stat string, sampleRate float32)
- func (client *StatsdClient) Increment(stat string)
- func (client *StatsdClient) IncrementByValue(stat string, val int)
- func (client *StatsdClient) IncrementWithSampling(stat string, sampleRate float32)
- func (client *StatsdClient) Open()
- func (client *StatsdClient) Send(data map[string]string, sampleRate float32)
- func (client *StatsdClient) Timing(stat string, time int64)
- func (client *StatsdClient) TimingWithSampleRate(stat string, time int64, sampleRate float32)
- func (client *StatsdClient) UpdateStats(stats []string, delta int, sampleRate float32)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StatsdClient ¶
The StatsdClient type defines the relevant properties of a StatsD connection.
func New ¶
func New(host string, port int) *StatsdClient
Factory method to initialize udp connection
Usage:
import "statsd" client := statsd.New('localhost', 8125)
func (*StatsdClient) Decrement ¶
func (client *StatsdClient) Decrement(stat string)
Decrements one stat counter without sampling
Usage:
import "statsd" client := statsd.New('localhost', 8125) client.Decrement('foo.bar')
func (*StatsdClient) DecrementWithSampling ¶
func (client *StatsdClient) DecrementWithSampling(stat string, sampleRate float32)
Decrements one stat counter with sampling
Usage:
import "statsd" client := statsd.New('localhost', 8125) client.Decrement('foo.bar', 0.2)
func (*StatsdClient) Increment ¶
func (client *StatsdClient) Increment(stat string)
Increments one stat counter without sampling
Usage:
import "statsd" client := statsd.New('localhost', 8125) client.Increment('foo.bar')
func (*StatsdClient) IncrementByValue ¶ added in v0.8.0
func (client *StatsdClient) IncrementByValue(stat string, val int)
Increments one stat counter by value provided without sampling
Usage:
import "statsd" client := statsd.New('localhost', 8125) client.IncrementByValue('foo.bar', 5)
func (*StatsdClient) IncrementWithSampling ¶
func (client *StatsdClient) IncrementWithSampling(stat string, sampleRate float32)
Increments one stat counter with sampling
Usage:
import "statsd" client := statsd.New('localhost', 8125) client.Increment('foo.bar', 0.2)
func (*StatsdClient) Open ¶
func (client *StatsdClient) Open()
Method to open udp connection, called by default client factory
func (*StatsdClient) Send ¶
func (client *StatsdClient) Send(data map[string]string, sampleRate float32)
Sends data to udp statsd daemon
func (*StatsdClient) Timing ¶
func (client *StatsdClient) Timing(stat string, time int64)
Log timing information (in milliseconds) without sampling
Usage:
import ( "statsd" "time" ) client := statsd.New('localhost', 8125) t1 := time.Now() expensiveCall() t2 := time.Now() duration := int64(t2.Sub(t1)/time.Millisecond) client.Timing("foo.time", duration)
func (*StatsdClient) TimingWithSampleRate ¶
func (client *StatsdClient) TimingWithSampleRate(stat string, time int64, sampleRate float32)
Log timing information (in milliseconds) with sampling
Usage:
import ( "statsd" "time" ) client := statsd.New('localhost', 8125) t1 := time.Now() expensiveCall() t2 := time.Now() duration := int64(t2.Sub(t1)/time.Millisecond) client.TimingWithSampleRate("foo.time", duration, 0.2)
func (*StatsdClient) UpdateStats ¶
func (client *StatsdClient) UpdateStats(stats []string, delta int, sampleRate float32)
Arbitrarily updates a list of stats by a delta