dipstick/examples/text_format_label.rs

36 lines
1.0 KiB
Rust
Raw Normal View History

2018-10-12 20:44:39 +00:00
//! A sample application asynchronously printing metrics to stdout.
extern crate dipstick;
use std::thread::sleep;
use std::time::Duration;
2018-10-18 14:10:23 +00:00
use dipstick::{Stream, InputScope, Input, Formatting, AppLabel,
2018-10-18 13:31:53 +00:00
Name, Kind, LineTemplate, LineFormat, LineOp, LabelOp};
2018-10-12 20:44:39 +00:00
2018-10-18 13:31:53 +00:00
struct MyFormat;
2018-10-18 12:54:41 +00:00
2018-10-18 13:31:53 +00:00
impl LineFormat for MyFormat {
fn template(&self, name: &Name, _kind: Kind) -> LineTemplate {
vec![
2018-10-18 14:10:23 +00:00
LineOp::Literal(format!("{} ", name.join(".")).into()),
2018-10-18 13:31:53 +00:00
LineOp::ValueAsText,
LineOp::Literal(" ".into()),
LineOp::LabelExists("abc".into(),
vec![LabelOp::LabelKey, LabelOp::Literal(":".into()), LabelOp::LabelValue],
),
LineOp::NewLine,
].into()
}
}
fn main() {
2018-10-18 14:10:23 +00:00
let counter = Stream::stderr().formatting(MyFormat).input().counter("counter_a");
2018-10-12 20:44:39 +00:00
AppLabel::set("abc", "xyz");
loop {
// report some metric values from our "application" loop
2018-10-18 14:10:23 +00:00
counter.count(11);
2018-10-12 20:44:39 +00:00
sleep(Duration::from_millis(500));
}
}