pub struct MetricsClient {
pub statsd_client: StatsdClient,
pub default_tags: BTreeMap<String, String>,
pub sample_rate: f32,
pub rx: Option<Receiver<Vec<u8>>>,
}
Expand description
Client configuration object to store globally.
Fields§
§statsd_client: StatsdClient
The raw statsd client.
Default tags to apply to every metric.
sample_rate: f32
Global sample rate.
rx: Option<Receiver<Vec<u8>>>
Receiver for external listeners.
Only available when the client was initialized with init_basic
.
Implementations§
Source§impl MetricsClient
impl MetricsClient
Sourcepub fn send_metric<'a, T>(&'a self, metric: MetricBuilder<'a, '_, T>)
pub fn send_metric<'a, T>(&'a self, metric: MetricBuilder<'a, '_, T>)
Send a metric with the default tags defined on this MetricsClient
.
Methods from Deref<Target = StatsdClient>§
pub fn flush(&self) -> Result<(), MetricError>
pub fn flush(&self) -> Result<(), MetricError>
Flush the underlying metric sink.
This is helpful for when you’d like to buffer metrics
but still want strong control over when to emit them.
For example, you are using a BufferedUdpMetricSink and
have just emitted some time-sensitive metrics, but you
aren’t sure if the buffer is full or not. Thus, you can
use flush
to force the sink to flush your metrics now.
§Buffered UDP Socket Example
use std::net::UdpSocket;
use cadence::prelude::*;
use cadence::{StatsdClient, BufferedUdpMetricSink, DEFAULT_PORT};
let prefix = "my.stats";
let host = ("127.0.0.1", DEFAULT_PORT);
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let sink = BufferedUdpMetricSink::from(host, socket).unwrap();
let client = StatsdClient::from_sink(prefix, sink);
client.count("time-sensitive.keyA", 1);
client.count("time-sensitive.keyB", 2);
client.count("time-sensitive.keyC", 3);
// Any number of time-sensitive metrics ...
client.flush();
Trait Implementations§
Source§impl Debug for MetricsClient
impl Debug for MetricsClient
Source§impl Deref for MetricsClient
impl Deref for MetricsClient
Auto Trait Implementations§
impl Freeze for MetricsClient
impl RefUnwindSafe for MetricsClient
impl Send for MetricsClient
impl Sync for MetricsClient
impl Unpin for MetricsClient
impl !UnwindSafe for MetricsClient
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