Struct dogstatsd::Client

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

The client struct that handles sending metrics to the Dogstatsd server.

Implementations§

source§

impl Client

source

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

pub fn incr<'a, I, S, T>(&self, stat: S, tags: I) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn incr_by_value<'a, I, S, T>( &self, stat: S, value: i64, tags: I ) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn decr<'a, I, S, T>(&self, stat: S, tags: I) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn decr_by_value<'a, I, S, T>( &self, stat: S, value: i64, tags: I ) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn count<'a, I, S, T>( &self, stat: S, count: i64, tags: I ) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn time<'a, F, O, I, S, T>( &self, stat: S, tags: I, block: F ) -> Result<O, (O, DogstatsdError)>
where F: FnOnce() -> O, I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub async fn async_time<'a, Fn, Fut, O, I, S, T>( &self, stat: S, tags: I, block: Fn ) -> Result<O, (O, DogstatsdError)>
where Fn: FnOnce() -> Fut, Fut: Future<Output = O>, I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn timing<'a, I, S, T>(&self, stat: S, ms: i64, tags: I) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn gauge<'a, I, S, SS, T>( &self, stat: S, val: SS, tags: I ) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, SS: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn histogram<'a, I, S, SS, T>( &self, stat: S, val: SS, tags: I ) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, SS: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn distribution<'a, I, S, SS, T>( &self, stat: S, val: SS, tags: I ) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, SS: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn set<'a, I, S, SS, T>(&self, stat: S, val: SS, tags: I) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, SS: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn service_check<'a, I, S, T>( &self, stat: S, val: ServiceStatus, tags: I, options: Option<ServiceCheckOptions<'_>> ) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, T: AsRef<str>,

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

pub fn event<'a, I, S, SS, T>( &self, title: S, text: SS, tags: I ) -> DogstatsdResult
where I: IntoIterator<Item = T>, S: Into<Cow<'a, str>>, SS: Into<Cow<'a, str>>, T: AsRef<str>,

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§

source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Client

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl PartialEq for Client

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where 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 T
where 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 T
where V: MultiLane<T>,

§

fn vzip(self) -> V