macro_proxy/
macro_proxy.rs

1//! A sample application sending ad-hoc counter values both to statsd _and_ to stdout.
2
3use dipstick::*;
4
5use std::time::Duration;
6
7// undeclared root (un-prefixed) metrics
8metrics! {
9    // create counter "some_counter"
10    pub ROOT_COUNTER: Counter = "root_counter";
11    // create counter "root_counter"
12    pub ROOT_GAUGE: Gauge = "root_gauge";
13    // create counter "root_timer"
14    pub ROOT_TIMER: Timer = "root_timer";
15}
16
17// public source
18metrics!(pub PUB_METRICS = "pub_lib_prefix" => {
19    // create counter "lib_prefix.some_counter"
20    pub PUB_COUNTER: Counter = "some_counter";
21});
22
23// declare mod source
24metrics!(pub LIB_METRICS = "mod_lib_prefix" => {
25    // create counter "mod_lib_prefix.some_counter"
26    pub SOME_COUNTER: Counter = "some_counter";
27});
28
29// reuse declared source
30metrics!(LIB_METRICS => {
31    // create counter "mod_lib_prefix.another_counter"
32    ANOTHER_COUNTER: Counter = "another_counter";
33});
34
35fn main() {
36    dipstick::Proxy::default_target(Stream::write_to_stdout().metrics());
37
38    loop {
39        ROOT_COUNTER.count(123);
40        ANOTHER_COUNTER.count(456);
41        ROOT_TIMER.interval_us(2000000);
42        ROOT_GAUGE.value(34534);
43        std::thread::sleep(Duration::from_millis(40));
44    }
45}