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 i64);
// add to the counter and provide tags
metric!(
counter(MyCounter::TotalRequests) += 1,
server = "s1",
host = "h1"
);
// subtract from the counter
metric!(counter(MyCounter::TotalRequests) -= 1);
// subtract from the counter and provide tags
metric!(
counter(MyCounter::TotalRequests) -= 1,
server = "s1",
host = "h1"
);