Struct statsd::client::Client

source ·
pub struct Client { /* private fields */ }
Expand description

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");

Implementations§

source§

impl Client

source

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

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

source

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

Increment a metric by 1

client.incr("metric.completed");

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

source

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

Decrement a metric by -1

client.decr("metric.completed");

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

source

pub fn count(&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.

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

pub fn sampled_count(&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.

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

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

Set a gauge value.

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

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

Send a timer value.

The value is expected to be in ms.

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

pub fn time<F, R>(&self, metric: &str, callable: F) -> Rwhere F: FnOnce() -> R,

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.
});
source

pub fn pipeline(&self) -> Pipeline

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);
source

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

Send a histogram value.

// pass response size value
client.histogram("response.size", 128.0);
source

pub fn kv(&self, metric: &str, value: f64)

Send a key/value

client.kv("key", 1.);

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V