pub struct Client { /* private fields */ }
Expand description
The client struct that handles sending metrics to the Dogstatsd server.
Implementations§
source§impl Client
impl Client
sourcepub fn new(options: Options) -> Result<Self, DogstatsdError>
pub fn new(options: Options) -> Result<Self, DogstatsdError>
Create a new client from an options struct.
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
sourcepub fn incr<'a, I, S, T>(&self, stat: S, tags: I) -> DogstatsdResult
pub fn incr<'a, I, S, T>(&self, stat: S, tags: I) -> DogstatsdResult
Increment a StatsD counter
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.incr("counter", &["tag:counter"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn incr_by_value<'a, I, S, T>(
&self,
stat: S,
value: i64,
tags: I
) -> DogstatsdResult
pub fn incr_by_value<'a, I, S, T>( &self, stat: S, value: i64, tags: I ) -> DogstatsdResult
Increment a StatsD counter by the provided amount
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.incr_by_value("counter", 123, &["tag:counter"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn decr<'a, I, S, T>(&self, stat: S, tags: I) -> DogstatsdResult
pub fn decr<'a, I, S, T>(&self, stat: S, tags: I) -> DogstatsdResult
Decrement a StatsD counter
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.decr("counter", &["tag:counter"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn decr_by_value<'a, I, S, T>(
&self,
stat: S,
value: i64,
tags: I
) -> DogstatsdResult
pub fn decr_by_value<'a, I, S, T>( &self, stat: S, value: i64, tags: I ) -> DogstatsdResult
Decrement a StatsD counter by the provided amount
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.decr_by_value("counter", 23, &["tag:counter"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn count<'a, I, S, T>(
&self,
stat: S,
count: i64,
tags: I
) -> DogstatsdResult
pub fn count<'a, I, S, T>( &self, stat: S, count: i64, tags: I ) -> DogstatsdResult
Make an arbitrary change to a StatsD counter
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.count("counter", 42, &["tag:counter"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn time<'a, F, O, I, S, T>(
&self,
stat: S,
tags: I,
block: F
) -> Result<O, (O, DogstatsdError)>
pub fn time<'a, F, O, I, S, T>( &self, stat: S, tags: I, block: F ) -> Result<O, (O, DogstatsdError)>
Time how long it takes for a block of code to execute.
Examples
use dogstatsd::{Client, Options};
use std::thread;
use std::time::Duration;
let client = Client::new(Options::default()).unwrap();
client.time("timer", &["tag:time"], || {
thread::sleep(Duration::from_millis(200))
}).unwrap_or_else(|(_, e)| println!("Encountered error: {}", e))
sourcepub async fn async_time<'a, Fn, Fut, O, I, S, T>(
&self,
stat: S,
tags: I,
block: Fn
) -> Result<O, (O, DogstatsdError)>
pub async fn async_time<'a, Fn, Fut, O, I, S, T>( &self, stat: S, tags: I, block: Fn ) -> Result<O, (O, DogstatsdError)>
Time how long it takes for an async block of code to execute.
Examples
use dogstatsd::{Client, Options};
use std::thread;
use std::time::Duration;
async fn timer() {
let client = Client::new(Options::default()).unwrap();
client.async_time("timer", &["tag:time"], do_work)
.await
.unwrap_or_else(|(_, e)| println!("Encountered error: {}", e))
}
sourcepub fn timing<'a, I, S, T>(&self, stat: S, ms: i64, tags: I) -> DogstatsdResult
pub fn timing<'a, I, S, T>(&self, stat: S, ms: i64, tags: I) -> DogstatsdResult
Send your own timing metric in milliseconds
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.timing("timing", 350, &["tag:timing"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn gauge<'a, I, S, SS, T>(
&self,
stat: S,
val: SS,
tags: I
) -> DogstatsdResult
pub fn gauge<'a, I, S, SS, T>( &self, stat: S, val: SS, tags: I ) -> DogstatsdResult
Report an arbitrary value as a gauge
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.gauge("gauge", "12345", &["tag:gauge"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn histogram<'a, I, S, SS, T>(
&self,
stat: S,
val: SS,
tags: I
) -> DogstatsdResult
pub fn histogram<'a, I, S, SS, T>( &self, stat: S, val: SS, tags: I ) -> DogstatsdResult
Report a value in a histogram
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.histogram("histogram", "67890", &["tag:histogram"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn distribution<'a, I, S, SS, T>(
&self,
stat: S,
val: SS,
tags: I
) -> DogstatsdResult
pub fn distribution<'a, I, S, SS, T>( &self, stat: S, val: SS, tags: I ) -> DogstatsdResult
Report a value in a distribution
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.distribution("distribution", "67890", &["tag:distribution"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn set<'a, I, S, SS, T>(&self, stat: S, val: SS, tags: I) -> DogstatsdResult
pub fn set<'a, I, S, SS, T>(&self, stat: S, val: SS, tags: I) -> DogstatsdResult
Report a value in a set
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.set("set", "13579", &["tag:set"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn service_check<'a, I, S, T>(
&self,
stat: S,
val: ServiceStatus,
tags: I,
options: Option<ServiceCheckOptions<'_>>
) -> DogstatsdResult
pub fn service_check<'a, I, S, T>( &self, stat: S, val: ServiceStatus, tags: I, options: Option<ServiceCheckOptions<'_>> ) -> DogstatsdResult
Report the status of a service
Examples
use dogstatsd::{Client, Options, ServiceStatus, ServiceCheckOptions};
let client = Client::new(Options::default()).unwrap();
client.service_check("redis.can_connect", ServiceStatus::OK, &["tag:service"], None)
.unwrap_or_else(|e| println!("Encountered error: {}", e));
let options = ServiceCheckOptions {
hostname: Some("my-host.localhost"),
..Default::default()
};
client.service_check("redis.can_connect", ServiceStatus::OK, &["tag:service"], Some(options))
.unwrap_or_else(|e| println!("Encountered error: {}", e));
let all_options = ServiceCheckOptions {
hostname: Some("my-host.localhost"),
timestamp: Some(1510326433),
message: Some("Message about the check or service")
};
client.service_check("redis.can_connect", ServiceStatus::OK, &["tag:service"], Some(all_options))
.unwrap_or_else(|e| println!("Encountered error: {}", e));
sourcepub fn event<'a, I, S, SS, T>(
&self,
title: S,
text: SS,
tags: I
) -> DogstatsdResult
pub fn event<'a, I, S, SS, T>( &self, title: S, text: SS, tags: I ) -> DogstatsdResult
Send a custom event as a title and a body
Examples
use dogstatsd::{Client, Options};
let client = Client::new(Options::default()).unwrap();
client.event("Event Title", "Event Body", &["tag:event"])
.unwrap_or_else(|e| println!("Encountered error: {}", e));
Trait Implementations§
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