Skip to main content

CounterMetric

Trait CounterMetric 

Source
pub trait CounterMetric {
    // Required method
    fn name(&self) -> &'static str;
}
Expand description

A metric for capturing counters.

Counters are simple values incremented or decremented by a client. The rates at which these events occur or average values will be determined by the server receiving them. Examples of counter uses include number of logins to a system or requests received.

§Example

use relay_statsd::{metric, CounterMetric};

enum MyCounter {
    TotalRequests,
    TotalBytes,
}

impl CounterMetric for MyCounter {
    fn name(&self) -> &'static str {
        match self {
            Self::TotalRequests => "total_requests",
            Self::TotalBytes => "total_bytes",
        }
    }
}


// add to the counter
metric!(counter(MyCounter::TotalRequests) += 1);
metric!(counter(MyCounter::TotalBytes) += buffer.len() as u64);

// add to the counter and provide tags
metric!(
    counter(MyCounter::TotalRequests) += 1,
    server = "s1",
    host = "h1"
);

Required Methods§

Source

fn name(&self) -> &'static str

Returns the counter metric name that will be sent to statsd.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§