pub struct Statsd { /* private fields */ }
Expand description
Statsd Input holds a datagram (UDP) socket to a statsd server. The socket is shared between scopes opened from the Input.
Implementations§
source§impl Statsd
impl Statsd
sourcepub fn send_to<ADDR: ToSocketAddrs>(address: ADDR) -> Result<Statsd>
pub fn send_to<ADDR: ToSocketAddrs>(address: ADDR) -> Result<Statsd>
Send metrics to a statsd server at the address and port provided.
Examples found in repository?
examples/statsd_sampling.rs (line 7)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
let metrics = Statsd::send_to("localhost:8125")
.expect("Connected")
.sampled(Sampling::Random(0.2))
.named("my_app")
.metrics();
let counter = metrics.counter("counter_a");
loop {
for i in 1..11 {
counter.count(i);
}
std::thread::sleep(Duration::from_millis(3000));
}
}
More examples
examples/statsd_nosampling.rs (line 7)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
let metrics = Statsd::send_to("localhost:8125")
.expect("Connected")
// .with_sampling(Sampling::Random(0.2))
.named("my_app")
.metrics();
let counter = metrics.counter("counter_a");
loop {
for i in 1..11 as usize {
counter.count(i);
}
std::thread::sleep(Duration::from_millis(3000));
}
}
examples/per_metric_sampling.rs (line 7)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
fn main() {
let statsd = Statsd::send_to("localhost:8125")
.expect("Connected")
.named("my_app");
// Sampling::Full is the default
// .sampled(Sampling::Full);
let unsampled_marker = statsd.metrics().marker("marker_a");
let low_freq_marker = statsd
.sampled(Sampling::Random(0.1))
.metrics()
.marker("low_freq_marker");
let hi_freq_marker = statsd
.sampled(Sampling::Random(0.001))
.metrics()
.marker("hi_freq_marker");
loop {
unsampled_marker.mark();
for _i in 0..10 {
low_freq_marker.mark();
}
for _i in 0..1000 {
hi_freq_marker.mark();
}
std::thread::sleep(Duration::from_millis(3000));
}
}
Trait Implementations§
source§impl Buffered for Statsd
impl Buffered for Statsd
source§fn buffered(&self, buffering: Buffering) -> Self
fn buffered(&self, buffering: Buffering) -> Self
Return a clone with the specified buffering set.
source§fn get_buffering(&self) -> Buffering
fn get_buffering(&self) -> Buffering
Return the current buffering strategy.
source§fn is_buffered(&self) -> bool
fn is_buffered(&self) -> bool
Returns false if the current buffering strategy is
Buffering::Unbuffered
.
Returns true otherwise.source§impl CachedInput for Statsd
impl CachedInput for Statsd
source§fn cached(self, max_size: usize) -> InputCache
fn cached(self, max_size: usize) -> InputCache
Wrap an input with a metric definition cache.
This can provide performance benefits for metrics that are dynamically defined at runtime on each access.
Caching is useless if all metrics are statically declared
or instantiated programmatically in advance and referenced by a long living variable.
source§impl Input for Statsd
impl Input for Statsd
source§impl QueuedInput for Statsd
impl QueuedInput for Statsd
source§fn queued(self, max_size: usize) -> InputQueue
fn queued(self, max_size: usize) -> InputQueue
Wrap this output with an asynchronous dispatch queue of specified length.
source§impl WithAttributes for Statsd
impl WithAttributes for Statsd
source§fn get_attributes(&self) -> &Attributes
fn get_attributes(&self) -> &Attributes
Return attributes of component.
source§fn mut_attributes(&mut self) -> &mut Attributes
fn mut_attributes(&mut self) -> &mut Attributes
Return attributes of component for mutation.
source§fn with_attributes<F: Fn(&mut Attributes)>(&self, edit: F) -> Self
fn with_attributes<F: Fn(&mut Attributes)>(&self, edit: F) -> Self
Clone the component and mutate its attributes at once.