Struct cadence::UdpMetricSink
source · [−]pub struct UdpMetricSink { /* private fields */ }
Expand description
Implementation of a MetricSink
that emits metrics over UDP.
This is the most basic version of MetricSink
that sends metrics over
UDP. It accepts a UDP socket instance over which to write metrics and
the address of the Statsd server to send packets to.
Each metric is sent to the Statsd server when the .emit()
method is
called, in the thread of the caller.
Implementations
sourceimpl UdpMetricSink
impl UdpMetricSink
sourcepub fn from<A>(to_addr: A, socket: UdpSocket) -> MetricResult<UdpMetricSink> where
A: ToSocketAddrs,
pub fn from<A>(to_addr: A, socket: UdpSocket) -> MetricResult<UdpMetricSink> where
A: ToSocketAddrs,
Construct a new UdpMetricSink
instance.
The address should be the address of the remote metric server to emit metrics to over UDP. The socket should already be bound to a local address with any desired configuration applied (blocking vs non-blocking, timeouts, etc.).
Example
use std::net::UdpSocket;
use cadence::{UdpMetricSink, DEFAULT_PORT};
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let host = ("metrics.example.com", DEFAULT_PORT);
let sink = UdpMetricSink::from(host, socket);
To send metrics over a non-blocking socket, simply put the socket in non-blocking mode before creating the UDP metric sink.
Non-blocking Example
Note that putting the UDP socket into non-blocking mode is the
default when sink and socket are automatically created with the
StatsdClient::from_udp_host
method.
use std::net::UdpSocket;
use cadence::{UdpMetricSink, DEFAULT_PORT};
let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
socket.set_nonblocking(true).unwrap();
let host = ("metrics.example.com", DEFAULT_PORT);
let sink = UdpMetricSink::from(host, socket);
Failures
This method may fail if:
- It is unable to resolve the hostname of the metric server.
- The host address is otherwise unable to be parsed
Trait Implementations
sourceimpl Debug for UdpMetricSink
impl Debug for UdpMetricSink
sourceimpl MetricSink for UdpMetricSink
impl MetricSink for UdpMetricSink
Auto Trait Implementations
impl RefUnwindSafe for UdpMetricSink
impl Send for UdpMetricSink
impl Sync for UdpMetricSink
impl Unpin for UdpMetricSink
impl UnwindSafe for UdpMetricSink
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