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));
Sourcepub fn event_with_options<'a, I, S, SS, T>(
&self,
title: S,
text: SS,
tags: I,
options: Option<EventOptions<'a>>,
) -> DogstatsdResult
pub fn event_with_options<'a, I, S, SS, T>( &self, title: S, text: SS, tags: I, options: Option<EventOptions<'a>>, ) -> DogstatsdResult
Send a custom event as a title and a body
§Examples
use dogstatsd::{Client, Options, EventOptions, EventAlertType, EventPriority};
let client = Client::new(Options::default()).unwrap();
let event_options = EventOptions::new()
.with_timestamp(1638480000)
.with_hostname("localhost")
.with_priority(EventPriority::Normal)
.with_alert_type(EventAlertType::Error);
client.event_with_options("My Custom Event Title", "My Custom Event Body", &["tag:event"], Some(event_options))
.unwrap_or_else(|e| println!("Encountered error: {}", e));Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Client
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin 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