pub struct UnixMetricSink { /* private fields */ }
Expand description

Implementation of a MetricSink that emits metrics over a Unix socket.

This is the most basic version of MetricSink that sends metrics over a Unix socket. It accepts a Unix socket instance over which to write metrics and the path of the socket for the Statsd server to send metrics to.

Each metric is sent to the Statsd server when the .emit() method is called, in the thread of the caller.

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.

Implementations

Construct a new UnixMetricSink instance.

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

Example
use std::os::unix::net::UnixDatagram;
use cadence::UnixMetricSink;

let socket = UnixDatagram::unbound().unwrap();
let sink = UnixMetricSink::from("/run/statsd.sock", socket);

To send metrics over a non-blocking socket, simply put the socket in non-blocking mode before creating the Unix metric sink.

Non-blocking Example
use std::os::unix::net::UnixDatagram;
use cadence::UnixMetricSink;

let socket = UnixDatagram::unbound().unwrap();
socket.set_nonblocking(true).unwrap();
let sink = UnixMetricSink::from("/run/statsd.sock", socket);

Trait Implementations

Formats the value using the given formatter. Read more

Send the Statsd metric using this sink and return the number of bytes written or an I/O error. Read more

Flush any currently buffered metrics to the underlying backend, returning an I/O error if they could not be written for some reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.