2018-06-14 20:08:54 +00:00
|
|
|
//! A sample application sending ad-hoc counter values both to statsd _and_ to stdout.
|
|
|
|
|
|
|
|
use dipstick::*;
|
2018-06-26 15:46:55 +00:00
|
|
|
|
2018-06-14 20:08:54 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
// undeclared root (un-prefixed) metrics
|
2018-06-22 05:08:04 +00:00
|
|
|
metrics! {
|
2018-06-14 20:08:54 +00:00
|
|
|
// create counter "some_counter"
|
2018-06-22 19:32:07 +00:00
|
|
|
pub ROOT_COUNTER: Counter = "root_counter";
|
2018-06-14 20:08:54 +00:00
|
|
|
// create counter "root_counter"
|
2018-06-22 19:32:07 +00:00
|
|
|
pub ROOT_GAUGE: Gauge = "root_gauge";
|
2018-06-14 20:08:54 +00:00
|
|
|
// create counter "root_timer"
|
2018-06-22 19:32:07 +00:00
|
|
|
pub ROOT_TIMER: Timer = "root_timer";
|
2018-06-22 05:08:04 +00:00
|
|
|
}
|
2018-06-14 20:08:54 +00:00
|
|
|
|
|
|
|
// public source
|
|
|
|
metrics!(pub PUB_METRICS = "pub_lib_prefix" => {
|
|
|
|
// create counter "lib_prefix.some_counter"
|
2018-06-22 19:32:07 +00:00
|
|
|
pub PUB_COUNTER: Counter = "some_counter";
|
2018-06-14 20:08:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// declare mod source
|
|
|
|
metrics!(pub LIB_METRICS = "mod_lib_prefix" => {
|
|
|
|
// create counter "mod_lib_prefix.some_counter"
|
2018-06-22 19:32:07 +00:00
|
|
|
pub SOME_COUNTER: Counter = "some_counter";
|
2018-06-14 20:08:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// reuse declared source
|
|
|
|
metrics!(LIB_METRICS => {
|
|
|
|
// create counter "mod_lib_prefix.another_counter"
|
2018-06-22 19:32:07 +00:00
|
|
|
ANOTHER_COUNTER: Counter = "another_counter";
|
2018-06-14 20:08:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
fn main() {
|
2020-05-15 04:28:40 +00:00
|
|
|
dipstick::Proxy::default_target(Stream::write_to_stdout().metrics());
|
2018-06-14 20:08:54 +00:00
|
|
|
|
|
|
|
loop {
|
|
|
|
ROOT_COUNTER.count(123);
|
|
|
|
ANOTHER_COUNTER.count(456);
|
|
|
|
ROOT_TIMER.interval_us(2000000);
|
|
|
|
ROOT_GAUGE.value(34534);
|
|
|
|
std::thread::sleep(Duration::from_millis(40));
|
|
|
|
}
|
|
|
|
}
|