Struct cadence::BufferedUnixMetricSink
source · [−]pub struct BufferedUnixMetricSink { /* private fields */ }
Expand description
Implementation of a MetricSink
that buffers metrics before
sending them to a Unix socket.
Metrics are line buffered, meaning that a trailing “\n” is added after each metric written to this sink. When the buffer is sufficiently full and a write is attempted, the contents of the buffer are flushed to a Unix socket and then the metric is written to the buffer. The buffer is also flushed when this sink is destroyed.
The default size of the buffer is 512 bytes. This is to be consistent with
the default for the BufferedUdpMetricSink
. The buffer size can be customized
using the with_capacity
method to create the sink if desired.
If a metric larger than the buffer is emitted, it will be written directly to the underlying Unix socket, bypassing the buffer.
Note that since metrics are buffered until a certain size is reached, it’s
possible that they may sit in the buffer for a while for applications
that do not emit metrics frequently or at a high volume. For these low-
throughput use cases, it may make more sense to use the UnixMetricSink
since it sends metrics immediately with no buffering.
Also note that unlike the UDP sinks, if there is no receiving socket at the path specified or nothing listening at the path, an error will be returned when metrics are emitted (though this may not happen on every write due to buffering).
Implementations
sourceimpl BufferedUnixMetricSink
impl BufferedUnixMetricSink
sourcepub fn from<P>(path: P, socket: UnixDatagram) -> BufferedUnixMetricSink where
P: AsRef<Path>,
pub fn from<P>(path: P, socket: UnixDatagram) -> BufferedUnixMetricSink where
P: AsRef<Path>,
Construct a new BufferedUnixMetricSink
instance with a default
buffer size of 512 bytes.
The socket does not need to be bound (i.e. UnixDatagram::unbound()
is
fine) but should have any desired configuration already applied
(blocking vs non-blocking, timeouts, etc.).
Writes to this sink are automatically suffixed with a Unix newline (‘\n’) by the sink and stored in a 512 byte buffer until the buffer is full or this sink is destroyed, at which point the buffer will be flushed.
Example
use std::os::unix::net::UnixDatagram;
use cadence::BufferedUnixMetricSink;
let socket = UnixDatagram::unbound().unwrap();
let sink = BufferedUnixMetricSink::from("/run/statsd.sock", socket);
sourcepub fn with_capacity<P>(
path: P,
socket: UnixDatagram,
cap: usize
) -> BufferedUnixMetricSink where
P: AsRef<Path>,
pub fn with_capacity<P>(
path: P,
socket: UnixDatagram,
cap: usize
) -> BufferedUnixMetricSink where
P: AsRef<Path>,
Construct a new BufferedUnixMetricSink
instance with a custom
buffer size.
The socket does not need to be bound (i.e. UnixDatagram::unbound()
is
fine) but should have with any desired configuration already applied
(blocking vs non-blocking, timeouts, etc.).
Writes to this sink are automatically suffixed with a Unix newline (‘\n’) by the sink and stored in a buffer until the buffer is full or this sink is destroyed, at which point the buffer will be flushed.
Example
use std::os::unix::net::UnixDatagram;
use cadence::BufferedUnixMetricSink;
let socket = UnixDatagram::unbound().unwrap();
let sink = BufferedUnixMetricSink::with_capacity("/run/statsd.sock", socket, 1432);
Trait Implementations
sourceimpl Debug for BufferedUnixMetricSink
impl Debug for BufferedUnixMetricSink
sourceimpl MetricSink for BufferedUnixMetricSink
impl MetricSink for BufferedUnixMetricSink
Auto Trait Implementations
impl RefUnwindSafe for BufferedUnixMetricSink
impl Send for BufferedUnixMetricSink
impl Sync for BufferedUnixMetricSink
impl Unpin for BufferedUnixMetricSink
impl UnwindSafe for BufferedUnixMetricSink
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more