2017-09-25 10:43:04 +00:00
|
|
|
//! A sample application sending ad-hoc counter values both to statsd _and_ to stdout.
|
|
|
|
|
2019-03-18 01:42:00 +00:00
|
|
|
use dipstick::{Graphite, Input, InputScope, MultiInput, Prefixed, Stream};
|
2017-12-07 20:06:14 +00:00
|
|
|
use std::time::Duration;
|
2017-09-25 10:43:04 +00:00
|
|
|
|
|
|
|
fn main() {
|
2018-06-14 16:37:21 +00:00
|
|
|
// will output metrics to graphite and to stdout
|
2019-01-21 21:07:22 +00:00
|
|
|
let different_type_metrics = MultiInput::new()
|
2019-01-25 20:45:46 +00:00
|
|
|
.add_target(Graphite::send_to("localhost:2003").expect("Connecting"))
|
2020-05-15 04:28:40 +00:00
|
|
|
.add_target(Stream::write_to_stdout())
|
2019-01-21 21:07:22 +00:00
|
|
|
.metrics();
|
2017-12-13 19:58:42 +00:00
|
|
|
|
2019-01-23 17:53:46 +00:00
|
|
|
// will output metrics twice, once with "both.yeah" prefix and once with "both.ouch" prefix.
|
2019-01-21 21:07:22 +00:00
|
|
|
let same_type_metrics = MultiInput::new()
|
2020-05-15 04:28:40 +00:00
|
|
|
.add_target(Stream::write_to_stderr().named("yeah"))
|
|
|
|
.add_target(Stream::write_to_stderr().named("ouch"))
|
2019-01-23 17:53:46 +00:00
|
|
|
.named("both")
|
2019-01-21 21:07:22 +00:00
|
|
|
.metrics();
|
2017-09-25 10:43:04 +00:00
|
|
|
|
|
|
|
loop {
|
2018-01-08 05:32:32 +00:00
|
|
|
different_type_metrics.counter("counter_a").count(123);
|
|
|
|
same_type_metrics.timer("timer_a").interval_us(2000000);
|
2018-06-26 19:51:49 +00:00
|
|
|
std::thread::sleep(Duration::from_millis(400));
|
2017-09-25 10:43:04 +00:00
|
|
|
}
|
|
|
|
}
|