Statsd client implemented in Rust
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Rust Statsd

Build Status

A StatsD client implementation of statsd in rust.

Using the client library

Add the statsd package as a dependency in your Cargo.toml file:

statsd = "^0.9.0"

You need rustc >= 1.8.0 for statsd to work.

You can then get a client instance and start tracking metrics:

// Load the crate
extern crate statsd;

// Import the client object.
use statsd::Client;

// Get a client with the prefix of `myapp`. The host should be the
// IP:port of your statsd daemon.
let client = Client::new("", "myapp").unwrap();

Tracking Metrics

Once you've created a client, you can track timers and metrics:

// Increment a counter by 1

// Decrement a counter by 1

// Update a gauge
client.gauge("some.value", 12.0);

// Modify a counter by an arbitrary float.
client.count("some.counter", 511.0);

Tracking Timers

Timers can be updated using timer() and time():

// Update a timer based on a calculation you've done.
client.timer("operation.duration", 13.4);

// Time a closure
client.time("operation.duration", || {
	// Do something expensive.


Multiple metrics can be sent to StatsD once using pipeline:

let mut pipe = client.pipeline():

// Increment a counter by 1

// Decrement a counter by 1

// Update a gauge
pipe.gauge("some.value", 12.0);

// Modify a counter by an arbitrary float.
pipe.count("some.counter", 511.0);

// Set max UDP packet size if you wish, default is 512

// Send to StatsD

Pipelines are also helpful to make functions simpler to test, as you can pass a pipeline and be confident that no UDP packets will be sent.


Licenesed under the MIT License.