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

pub struct Client {
    // some 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]

fn new(host: &str, prefix: &str) -> Result<ClientStatsdError>

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

fn incr(&mut self, metric: &str)

Increment a metric by 1

client.incr("metric.completed");

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

fn decr(&mut self, metric: &str)

Decrement a metric by -1

client.decr("metric.completed");

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

fn count(&mut self, metric: &str, value: f64)

Modify a counter by value.

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

client.count("metric.completed", 12);

fn sampled_count(&mut self, metric: &str, value: f64, rate: f64)

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

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

client.sampled_count("metric.completed", 4, 0.5);

fn gauge(&mut self, metric: &str, value: f64)

Set a gauge value.

client.gauge("power_level.observed", 9001);

fn timer(&mut self, metric: &str, value: f64)

Send a timer value.

The value is expected to be in ms.

client.timer("response.duration", 10.123);

fn time<F>(&mut self, metric: &str, callable: F) where F: Fn()

Time a block of code.

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

client.time("response.duration", || {
});