Struct statsd::client::Client [] [src]

pub struct Client { /* fields omitted */ }

Client socket for statsd servers.

After creating a metric you can use Client to send metrics to the configured statsd server

Example

Creating a client and sending metrics is easy.

use statsd::client::Client;

let client = Client::new("127.0.0.1:8125", "myapp");
client.incr("some.metric.completed");

Methods

impl Client
[src]

Construct a new statsd client given an host/port & prefix

Increment a metric by 1

client.incr("metric.completed");

This modifies a counter with an effective sampling rate of 1.0.

Decrement a metric by -1

client.decr("metric.completed");

This modifies a counter with an effective sampling rate of 1.0.

Modify a counter by value.

Will increment or decrement a counter by value with a sampling rate of 1.0.

// Increment by 12
client.count("metric.completed", 12.0);

Modify a counter by value only x% of the time.

Will increment or decrement a counter by value with a custom sampling rate.

// Increment by 4 50% of the time.
client.sampled_count("metric.completed", 4, 0.5);

Set a gauge value.

// set a gauge to 9001
client.gauge("power_level.observed", 9001.0);

Send a timer value.

The value is expected to be in ms.

// pass a duration value
client.timer("response.duration", 10.123);

Time a block of code.

The passed closure will be timed and executed. The block's duration will be sent as a metric.

// pass a duration value
client.time("response.duration", || {
  // Your code here.
});

Get a pipeline struct that allows optimizes the number of UDP packets used to send multiple metrics

let mut pipeline = client.pipeline();
pipeline.incr("some.metric", 1);
pipeline.incr("other.metric", 1);
pipeline.send(&mut client);