[−][src]Struct cadence::QueuingMetricSink
Implementation of a MetricSink
that wraps another implementation
and uses it to emit metrics asynchronously, in another thread.
Metrics submitted to this sink are queued and sent to the wrapped sink
that is running in a separate thread. The wrapped implementation can
be any thread (Sync
+ Send
) and panic (RefUnwindSafe
) safe
MetricSink
. Results from the wrapped implementation will be discarded.
The thread used for network operations (actually sending the metrics
using the wrapped sink) is created and started when the QueuingMetricSink
is created. The dequeuing of metrics is stopped and the thread stopped
when QueuingMetricSink
instance is destroyed (when .drop()
is
called).
Entries already queued are guaranteed to be sent to the wrapped sink
before the queuing sink is stopped. Meaning, the following code ends up
calling wrapped.emit(metric)
on every metric submitted to the queuing
sink.
Example
use cadence::{MetricSink, QueuingMetricSink, NopMetricSink}; let wrapped = NopMetricSink; { let queuing = QueuingMetricSink::from(wrapped); queuing.emit("foo.counter:4|c"); queuing.emit("bar.counter:5|c"); queuing.emit("baz.gauge:6|g"); }
At the end of this code block, all metrics are guaranteed to be sent to the underlying wrapped metric sink before the thread used by the queuing sink is stopped.
Methods
impl QueuingMetricSink
[src]
pub fn from<T>(sink: T) -> QueuingMetricSink where
T: MetricSink + Sync + Send + RefUnwindSafe + 'static,
[src]
T: MetricSink + Sync + Send + RefUnwindSafe + 'static,
Construct a new QueuingMetricSink
instance wrapping another sink
implementation.
The .emit()
method of the wrapped sink will be executed in a
different thread after being passed to it via a queue. The wrapped
sink should be thread safe (Send + Sync
) and panic safe
(RefUnwindSafe
).
The thread in which the wrapped sink runs is created when the
QueuingMetricSink
is created and stopped when the queuing sink
is destroyed.
Buffered UDP Sink Example
In this example we wrap a buffered UDP sink to execute it in a different thread.
use std::net::UdpSocket; use cadence::{BufferedUdpMetricSink, QueuingMetricSink, DEFAULT_PORT}; let socket = UdpSocket::bind("0.0.0.0:0").unwrap(); let host = ("metrics.example.com", DEFAULT_PORT); let udp_sink = BufferedUdpMetricSink::from(host, socket).unwrap(); let queuing_sink = QueuingMetricSink::from(udp_sink);
pub fn panics(&self) -> usize
[src]
Return the number of times the wrapped sink or underlying worker thread
has panicked and needed to be restarted. In typical use this should always
be 0
but sometimes bugs happen.
Trait Implementations
impl MetricSink for QueuingMetricSink
[src]
impl Drop for QueuingMetricSink
[src]
fn drop(&mut self)
[src]
Send the worker a signal to stop processing metrics.
Note that this destructor only sends the worker thread a signal to stop, it doesn't wait for it to stop.
impl Clone for QueuingMetricSink
[src]
fn clone(&self) -> QueuingMetricSink
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for QueuingMetricSink
[src]
Auto Trait Implementations
impl Send for QueuingMetricSink
impl Sync for QueuingMetricSink
impl Unpin for QueuingMetricSink
impl UnwindSafe for QueuingMetricSink
impl RefUnwindSafe for QueuingMetricSink
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,