Struct cadence::ext::SocketStats
source · pub struct SocketStats { /* private fields */ }
Expand description
Thread-safe collection of stats updated by network sinks.
This struct is meant to be updated internally by MetricSink
implementations
and converted to an instance of SinkStats
for consumption by external callers.
§Example
use std::net::{SocketAddr, UdpSocket};
use cadence::ext::SocketStats;
use cadence::{MetricSink, SinkStats};
pub struct MyCustomSink {
addr: SocketAddr,
socket: UdpSocket,
stats: SocketStats,
}
impl MetricSink for MyCustomSink {
fn emit(&self, metric: &str) -> std::io::Result<usize> {
let res = self.socket.send_to(metric.as_bytes(), &self.addr);
self.stats.update(res, metric.len())
}
fn stats(&self) -> SinkStats {
(&self.stats).into()
}
}
Implementations§
source§impl SocketStats
impl SocketStats
pub fn incr_bytes_sent(&self, n: u64)
pub fn incr_packets_sent(&self)
pub fn incr_bytes_dropped(&self, n: u64)
pub fn incr_packets_dropped(&self)
pub fn update(&self, res: Result<usize>, len: usize) -> Result<usize>
Trait Implementations§
source§impl Clone for SocketStats
impl Clone for SocketStats
source§fn clone(&self) -> SocketStats
fn clone(&self) -> SocketStats
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for SocketStats
impl Debug for SocketStats
source§impl Default for SocketStats
impl Default for SocketStats
source§fn default() -> SocketStats
fn default() -> SocketStats
Returns the “default value” for a type. Read more
source§impl From<&SocketStats> for SinkStats
impl From<&SocketStats> for SinkStats
source§fn from(stats: &SocketStats) -> Self
fn from(stats: &SocketStats) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for SocketStats
impl RefUnwindSafe for SocketStats
impl Send for SocketStats
impl Sync for SocketStats
impl Unpin for SocketStats
impl UnwindSafe for SocketStats
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more