[−][src]Struct cadence::BufferedUdpMetricSink
Implementation of a MetricSink
that buffers metrics before
sending them to a UDP 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 UDP 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 the "safest"
size for a UDP packet according to the Etsy Statsd docs. 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 UDP socket, bypassing the buffer.
Methods
impl BufferedUdpMetricSink
[src]
pub fn from<A>(
sink_addr: A,
socket: UdpSocket
) -> MetricResult<BufferedUdpMetricSink> where
A: ToSocketAddrs,
[src]
sink_addr: A,
socket: UdpSocket
) -> MetricResult<BufferedUdpMetricSink> where
A: ToSocketAddrs,
Construct a new BufferedUdpMetricSink
instance with a default
buffer size of 512 bytes.
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.).
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::net::UdpSocket; use cadence::{BufferedUdpMetricSink, DEFAULT_PORT}; let socket = UdpSocket::bind("0.0.0.0:0").unwrap(); let host = ("metrics.example.com", DEFAULT_PORT); let sink = BufferedUdpMetricSink::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
pub fn with_capacity<A>(
sink_addr: A,
socket: UdpSocket,
cap: usize
) -> MetricResult<BufferedUdpMetricSink> where
A: ToSocketAddrs,
[src]
sink_addr: A,
socket: UdpSocket,
cap: usize
) -> MetricResult<BufferedUdpMetricSink> where
A: ToSocketAddrs,
Construct a new BufferedUdpMetricSink
instance with a custom
buffer size.
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.).
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.
For guidance on sizing your buffer see the Statsd docs.
Example
use std::net::UdpSocket; use cadence::{BufferedUdpMetricSink, DEFAULT_PORT}; let socket = UdpSocket::bind("0.0.0.0:0").unwrap(); let host = ("metrics.example.com", DEFAULT_PORT); let sink = BufferedUdpMetricSink::with_capacity(host, socket, 1432);
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
impl MetricSink for BufferedUdpMetricSink
[src]
impl Debug for BufferedUdpMetricSink
[src]
Auto Trait Implementations
impl Sync for BufferedUdpMetricSink
impl Unpin for BufferedUdpMetricSink
impl Send for BufferedUdpMetricSink
impl UnwindSafe for BufferedUdpMetricSink
impl RefUnwindSafe for BufferedUdpMetricSink
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, 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,