pub struct Counter { /* private fields */ }
Expand description
A counter of absolute observed values (non-negative amounts). Used to count things that cannot be undone:
- Bytes sent
- Records written
- Apples eaten
For relative (possibly negative) values, the
Level
counter type can be used. If aggregated, minimum and maximum scores will track the collected values, not their sum.
Implementations§
source§impl Counter
impl Counter
sourcepub fn count(&self, count: usize)
pub fn count(&self, count: usize)
Record a value count.
Examples found in repository?
More examples
examples/graphite.rs (line 13)
6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
let metrics = Graphite::send_to("localhost:2003")
.expect("Connected")
.named("my_app")
.metrics();
loop {
metrics.counter("counter_a").count(123);
metrics.timer("timer_a").interval_us(2000000);
std::thread::sleep(Duration::from_millis(40));
}
}
examples/text_format_label.rs (line 40)
32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
let counter = Stream::write_to_stderr()
.formatting(MyFormat)
.metrics()
.counter("counter_a");
AppLabel::set("abc", "xyz");
loop {
// report some metric values from our "application" loop
counter.count(11);
sleep(Duration::from_millis(500));
}
}
examples/cache.rs (line 16)
8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
let metrics = Stream::write_to(io::stdout())
.cached(5)
.metrics()
.named("cache");
loop {
// report some ad-hoc metric values from our "application" loop
metrics.counter("blorf").count(1134);
metrics.marker("burg").mark();
sleep(Duration::from_millis(500));
}
}
examples/statsd_sampling.rs (line 17)
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));
}
}
examples/statsd_nosampling.rs (line 17)
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));
}
}
Methods from Deref<Target = InputMetric>§
sourcepub fn write(&self, value: MetricValue, labels: Labels)
pub fn write(&self, value: MetricValue, labels: Labels)
Collect a new value for this metric.
Trait Implementations§
source§impl From<InputMetric> for Counter
impl From<InputMetric> for Counter
source§fn from(metric: InputMetric) -> Counter
fn from(metric: InputMetric) -> Counter
Converts to this type from the input type.