jason 075d766964 first | пре 3 година | |
---|---|---|
.. | ||
.gitignore | пре 3 година | |
.travis.yml | пре 3 година | |
LICENSE | пре 3 година | |
README.md | пре 3 година | |
fix.bash | пре 3 година | |
g2s.go | пре 3 година | |
g2s_test.go | пре 3 година | |
safe.go | пре 3 година | |
types.go | пре 3 година |
Get to Statsd: forward simple statistics to a statsd server.
g2s provides a Statsd object, which provides some convenience functions for each of the supported statsd statistic-types. Just call the relevant function on the Statsd object wherever it makes sense in your code.
s, err := g2s.Dial("udp", "statsd-server:8125")
if err != nil {
// do something
}
s.Counter(1.0, "my.silly.counter", 1)
s.Timing(1.0, "my.silly.slow-process", time.Since(somethingBegan))
s.Timing(0.2, "my.silly.fast-process", 7*time.Millisecond)
s.Gauge(1.0, "my.silly.status", "green")
If you need to add a prefix to your metrics (for example, if you need to use an
API key to send metrics to your statsd service) just use DialWithPrefix
instead
when instantiating your statsd struct:
s, err := g2s.DialWithPrefix("udp", "statsd-server:8125", "my-cool-prefix")
if err != nil {
// do something
}
s.Counter(1.0, "this.gets.prefixed", 1)
If you use a standard UDP connection to a statsd server, all 'update'-class functions are goroutine safe. They should return quickly, but they're safe to fire in a seperate goroutine.
Upgrade to the latest API by running ./fix.bash *.go
where *.go
expands to
the paths of the source files you'd like to rewrite to the new API.