Rust Statsd
A StatsD client implementation of statsd in rust.
Using the client library
Add the statsd
package as a dependency in your Cargo.toml
file:
[]
= "0.1.0"
You can then get a client instance and start tracking metrics:
// Load the crate
extern crate statsd;
// Import the client object.
use Client;
// Get a client with the prefix of `myapp`. The host should be the
// IP:port of your statsd daemon.
let mut client = new.unwrap;
Tracking Metrics
Once you've created a client, you can track timers and metrics:
// Increment a counter by 1
client.incr;
// Decrement a counter by 1
client.decr;
// Update a gauge
client.gauge;
// Modify a counter by an arbitrary float.
client.count;
Tracking Timers
Timers can be updated using timer()
and time()
:
// Update a timer based on a calculation you've done.
client.timer;
// Time a closure
client.time;