dipstick/examples/proxy.rs

55 lines
1.3 KiB
Rust
Raw Normal View History

2018-07-03 15:44:29 +00:00
//! Use the proxy to dynamically switch the metrics input & names.
2018-06-19 19:27:26 +00:00
extern crate dipstick;
use std::thread::sleep;
use std::time::Duration;
2018-10-12 20:44:39 +00:00
use dipstick::{Proxy, Stream, InputScope, Input, Naming};
2018-06-19 19:27:26 +00:00
fn main() {
2018-10-18 14:10:23 +00:00
let root_proxy = Proxy::default();
let sub = root_proxy.add_naming("sub");
2018-06-19 19:27:26 +00:00
2018-10-18 14:10:23 +00:00
let count1 = root_proxy.counter("counter_a");
2018-06-19 19:27:26 +00:00
let count2 = sub.counter("counter_b");
loop {
2018-10-18 14:10:23 +00:00
let stdout = Stream::stdout().input();
root_proxy.set_target(stdout.clone());
2018-06-19 19:27:26 +00:00
count1.count(1);
count2.count(2);
// route every metric from the root to stdout with prefix "root"
2018-10-18 14:10:23 +00:00
root_proxy.set_target(stdout.add_naming("root"));
2018-06-19 19:27:26 +00:00
count1.count(3);
count2.count(4);
// route metrics from "sub" to stdout with prefix "mutant"
2018-10-18 14:10:23 +00:00
sub.set_target(stdout.add_naming("mutant"));
2018-06-19 19:27:26 +00:00
count1.count(5);
count2.count(6);
// clear root metrics route, "sub" still appears
2018-10-18 14:10:23 +00:00
root_proxy.unset_target();
2018-06-19 19:27:26 +00:00
count1.count(7);
count2.count(8);
// now no metrics appear
sub.unset_target();
count1.count(9);
count2.count(10);
2018-06-26 15:46:55 +00:00
// go back to initial single un-prefixed route
2018-10-18 14:10:23 +00:00
root_proxy.set_target(stdout.clone());
2018-06-19 19:27:26 +00:00
count1.count(11);
count2.count(12);
sleep(Duration::from_secs(1));
println!()
}
}