bucket2graphite/
bucket2graphite.rs

1//! A sample application continuously aggregating metrics,
2//! printing the summary stats every three seconds
3
4use dipstick::*;
5use std::time::Duration;
6
7fn main() {
8    // adding a name to the stats
9    let bucket = AtomicBucket::new().named("test");
10
11    // adding two names to Graphite output
12    // metrics will be prefixed with "machine1.application.test"
13    bucket.drain(
14        Graphite::send_to("localhost:2003")
15            .expect("Socket")
16            .named("machine1")
17            .add_name("application"),
18    );
19
20    bucket.flush_every(Duration::from_secs(3));
21
22    let counter = bucket.counter("counter_a");
23    let timer = bucket.timer("timer_a");
24    let gauge = bucket.gauge("gauge_a");
25    let marker = bucket.marker("marker_a");
26
27    loop {
28        // add counts forever, non-stop
29        counter.count(11);
30        counter.count(12);
31        counter.count(13);
32
33        timer.interval_us(11_000_000);
34        timer.interval_us(12_000_000);
35        timer.interval_us(13_000_000);
36
37        gauge.value(11);
38        gauge.value(12);
39        gauge.value(13);
40
41        marker.mark();
42    }
43}