pub struct Client { /* private fields */ }
Expand description
Implementations§
source§impl Client
impl Client
sourcepub fn new<T: ToSocketAddrs>(
host: T,
prefix: &str
) -> Result<Client, StatsdError>
pub fn new<T: ToSocketAddrs>( host: T, prefix: &str ) -> Result<Client, StatsdError>
Construct a new statsd client given an host/port & prefix
sourcepub fn incr(&self, metric: &str)
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.
sourcepub fn decr(&self, metric: &str)
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.
sourcepub fn count(&self, metric: &str, value: f64)
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);
sourcepub fn sampled_count(&self, metric: &str, value: f64, rate: f64)
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);
sourcepub fn gauge(&self, metric: &str, value: f64)
pub fn gauge(&self, metric: &str, value: f64)
Set a gauge value.
ⓘ
// set a gauge to 9001
client.gauge("power_level.observed", 9001.0);
sourcepub fn timer(&self, metric: &str, value: f64)
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);
sourcepub fn time<F, R>(&self, metric: &str, callable: F) -> Rwhere
F: FnOnce() -> R,
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.
});
sourcepub fn pipeline(&self) -> Pipeline
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);
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more