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

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.

This example is not tested
use statsd::client::Client;

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

Implementations

impl Client[src]

pub fn new<T: ToSocketAddrs>(
    host: T,
    prefix: &str
) -> Result<Client, StatsdError>
[src]

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

pub fn incr(&self, metric: &str)[src]

Increment a metric by 1

This example is not tested
client.incr("metric.completed");

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

pub fn decr(&self, metric: &str)[src]

Decrement a metric by -1

This example is not tested
client.decr("metric.completed");

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

pub fn count(&self, metric: &str, value: f64)[src]

Modify a counter by value.

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

This example is not tested
// Increment by 12
client.count("metric.completed", 12.0);

pub fn sampled_count(&self, metric: &str, value: f64, rate: f64)[src]

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

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

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

pub fn gauge(&self, metric: &str, value: f64)[src]

Set a gauge value.

This example is not tested
// set a gauge to 9001
client.gauge("power_level.observed", 9001.0);

pub fn timer(&self, metric: &str, value: f64)[src]

Send a timer value.

The value is expected to be in ms.

This example is not tested
// pass a duration value
client.timer("response.duration", 10.123);

pub fn time<F, R>(&self, metric: &str, callable: F) -> R where
    F: FnOnce() -> R, 
[src]

Time a block of code.

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

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

pub fn pipeline(&self) -> Pipeline[src]

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

This example is not tested
let mut pipeline = client.pipeline();
pipeline.incr("some.metric", 1);
pipeline.incr("other.metric", 1);
pipeline.send(&mut client);

pub fn histogram(&self, metric: &str, value: f64)[src]

Send a histogram value.

This example is not tested
// pass response size value
client.histogram("response.size", 128.0);

Auto Trait Implementations

impl RefUnwindSafe for Client

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl UnwindSafe for Client

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.