Trait MetricClient
pub trait MetricClient:
Counted<i64>
+ Counted<i32>
+ Counted<u64>
+ Counted<u32>
+ CountedExt
+ Timed<u64>
+ Timed<Duration>
+ Timed<Vec<u64>>
+ Timed<Vec<Duration>>
+ Gauged<u64>
+ Gauged<f64>
+ Metered<u64>
+ Histogrammed<u64>
+ Histogrammed<f64>
+ Histogrammed<Duration>
+ Histogrammed<Vec<u64>>
+ Histogrammed<Vec<f64>>
+ Histogrammed<Vec<Duration>>
+ Distributed<u64>
+ Distributed<f64>
+ Distributed<Vec<u64>>
+ Distributed<Vec<f64>>
+ Setted<i64> { }
Expand description
Trait that encompasses all other traits for sending metrics.
If you wish to use StatsdClient
with a generic type or place a
StatsdClient
instance behind a pointer (such as a Box
) this will allow
you to reference all the implemented methods for recording metrics, while
using a single trait. An example of this is shown below.
use std::time::Duration;
use cadence::{MetricClient, StatsdClient, NopMetricSink};
let client: Box<dyn MetricClient> = Box::new(StatsdClient::from_sink(
"prefix", NopMetricSink));
client.count("some.counter", 1).unwrap();
client.count("some.counter", 2i32).unwrap();
client.count("some.counter", 4u64).unwrap();
client.count("some.counter", 8u32).unwrap();
client.time("some.timer", 42).unwrap();
client.time("some.timer", Duration::from_millis(42)).unwrap();
client.time("some.timer", vec![42]).unwrap();
client.time("some.timer", vec![Duration::from_millis(42)]).unwrap();
client.gauge("some.gauge", 8).unwrap();
client.meter("some.meter", 13).unwrap();
client.histogram("some.histogram", 4).unwrap();
client.histogram("some.histogram", Duration::from_nanos(4)).unwrap();
client.histogram("some.histogram", vec![4]).unwrap();
client.histogram("some.histogram", vec![Duration::from_nanos(4)]).unwrap();
client.distribution("some.distribution", 4).unwrap();
client.distribution("some.distribution", vec![4]).unwrap();
client.set("some.set", 5).unwrap();