diff --git a/Makefile b/Makefile index e5e20da..ffc4336 100755 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ CARGO_BUILD_FLAGS ?= # 'test' is a friendly alias for 'unit_test' test: - $(CARGO_CMD) test + $(CARGO_CMD) test --features="skeptic" examples: $(CARGO_CMD) build --examples diff --git a/README.md b/README.md index 0b28498..092de1a 100755 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Here's a basic aggregating & auto-publish counter metric: ```$rust,skt-run let bucket = Bucket::new(); -bucket.set_target(Text::output(io::stdout())); +bucket.set_target(Stream::stdout()); bucket.flush_every(Duration::from_secs(3)); let counter = bucket.counter("counter_a"); counter.count(8) @@ -53,12 +53,13 @@ counter.count(8) Persistent apps wanting to declare static metrics will prefer using the `metrics!` macro: ```$rust,skt-run -metrics! { METRICS = "my_app" => - pub COUNTER: Counter = "my_counter"; +metrics! { METRICS = "my_app" => { + pub COUNTER: Counter = "my_counter"; + } } fn main() { - METRICS.set_target(Graphite::output("graphite.com:2003").unwrap()); + METRICS.set_target(Graphite::send_to("graphite.com:2003").unwrap().input()); COUNTER.count(32); } ``` diff --git a/README.md.skt.md b/README.md.skt.md index 7336266..ece0fc5 100644 --- a/README.md.skt.md +++ b/README.md.skt.md @@ -3,8 +3,10 @@ Templates Use `cargo test --features="skeptic"` to run the examples in the README using the `skeptic` crate. ```rust,skt-run +#[macro_use] extern crate dipstick; use dipstick::*; +use std::time::Duration; fn main() {{ {} @@ -14,8 +16,8 @@ fn main() {{ ```rust,skt-fail extern crate dipstick; use dipstick::*; -use dipstick::error::Error; use std::result::Result; +use std::time::Duration; fn main() {{ run().ok(); diff --git a/assets/dipstick_coarse_medium.jpg b/assets/dipstick_coarse_medium.jpg deleted file mode 100644 index c37caa4..0000000 Binary files a/assets/dipstick_coarse_medium.jpg and /dev/null differ diff --git a/assets/dipstick_horizontal_read.jpg b/assets/dipstick_horizontal_read.jpg deleted file mode 100644 index 5c0b56d..0000000 Binary files a/assets/dipstick_horizontal_read.jpg and /dev/null differ diff --git a/assets/dipstick_red_small.jpg b/assets/dipstick_red_small.jpg deleted file mode 100644 index acef06c..0000000 Binary files a/assets/dipstick_red_small.jpg and /dev/null differ diff --git a/assets/dipstick_single_ok_horiz.png b/assets/dipstick_single_ok_horiz.png deleted file mode 100644 index 9eec0fa..0000000 Binary files a/assets/dipstick_single_ok_horiz.png and /dev/null differ diff --git a/assets/dipstick_single_ok_horiz_transparent.png b/assets/dipstick_single_ok_horiz_transparent.png deleted file mode 100644 index 40da0ab..0000000 Binary files a/assets/dipstick_single_ok_horiz_transparent.png and /dev/null differ diff --git a/assets/oil_temp.png b/assets/oil_temp.png deleted file mode 100755 index f6717f0..0000000 Binary files a/assets/oil_temp.png and /dev/null differ diff --git a/examples/proxy.rs b/examples/proxy.rs index 85f758e..268fd9d 100644 --- a/examples/proxy.rs +++ b/examples/proxy.rs @@ -4,35 +4,35 @@ extern crate dipstick; use std::thread::sleep; use std::time::Duration; -use std::io; use dipstick::{Proxy, Stream, InputScope, Input, Naming}; fn main() { - let root = Proxy::default(); - let sub = root.add_naming("sub"); + let root_proxy = Proxy::default(); + let sub = root_proxy.add_naming("sub"); - let count1 = root.counter("counter_a"); + let count1 = root_proxy.counter("counter_a"); let count2 = sub.counter("counter_b"); loop { - root.set_target(Stream::write_to(io::stdout()).input()); + let stdout = Stream::stdout().input(); + root_proxy.set_target(stdout.clone()); count1.count(1); count2.count(2); // route every metric from the root to stdout with prefix "root" - root.set_target(Stream::write_to(io::stdout()).add_naming("root").input()); + root_proxy.set_target(stdout.add_naming("root")); count1.count(3); count2.count(4); // route metrics from "sub" to stdout with prefix "mutant" - sub.set_target(Stream::write_to(io::stdout()).add_naming("mutant").input()); + sub.set_target(stdout.add_naming("mutant")); count1.count(5); count2.count(6); // clear root metrics route, "sub" still appears - root.unset_target(); + root_proxy.unset_target(); count1.count(7); count2.count(8); @@ -42,7 +42,7 @@ fn main() { count2.count(10); // go back to initial single un-prefixed route - root.set_target(Stream::write_to(io::stdout()).input()); + root_proxy.set_target(stdout.clone()); count1.count(11); count2.count(12); diff --git a/examples/text_format_label.rs b/examples/text_format_label.rs index a7f6ab8..d96e5d7 100644 --- a/examples/text_format_label.rs +++ b/examples/text_format_label.rs @@ -1,23 +1,18 @@ //! A sample application asynchronously printing metrics to stdout. -#[macro_use] extern crate dipstick; use std::thread::sleep; use std::time::Duration; -use dipstick::{Proxy, Stream, Counter, InputScope, Input, Formatting, AppLabel, +use dipstick::{Stream, InputScope, Input, Formatting, AppLabel, Name, Kind, LineTemplate, LineFormat, LineOp, LabelOp}; -metrics!{ - COUNTER: Counter = "counter_a"; -} - struct MyFormat; impl LineFormat for MyFormat { fn template(&self, name: &Name, _kind: Kind) -> LineTemplate { vec![ - LineOp::Literal(format!("{} ", name.join("."))), + LineOp::Literal(format!("{} ", name.join(".")).into()), LineOp::ValueAsText, LineOp::Literal(" ".into()), LineOp::LabelExists("abc".into(), @@ -29,11 +24,11 @@ impl LineFormat for MyFormat { } fn main() { - Proxy::set_default_target(Stream::stderr().formatting(MyFormat).input()); + let counter = Stream::stderr().formatting(MyFormat).input().counter("counter_a"); AppLabel::set("abc", "xyz"); loop { // report some metric values from our "application" loop - COUNTER.count(11); + counter.count(11); sleep(Duration::from_millis(500)); } diff --git a/src/core/label.rs b/src/core/label.rs index 5fcb1d7..a274ac8 100644 --- a/src/core/label.rs +++ b/src/core/label.rs @@ -191,8 +191,8 @@ pub mod test { #[test] fn context_labels() { - AppLabel::set("abc".into(), "456".into()); - ThreadLabel::set("abc".into(), "123".into()); + AppLabel::set("abc", "456"); + ThreadLabel::set("abc", "123"); assert_eq!(Arc::new("123".into()), labels!().lookup("abc").unwrap()); ThreadLabel::unset("abc"); assert_eq!(Arc::new("456".into()), labels!().lookup("abc").unwrap()); @@ -213,8 +213,8 @@ pub mod test { #[test] fn value_labels() { - AppLabel::set("abc".into(), "456".into()); - ThreadLabel::set("abc".into(), "123".into()); + AppLabel::set("abc", "456"); + ThreadLabel::set("abc", "123"); let mut labels = labels!{ "abc" => "789", }; diff --git a/src/macros.rs b/src/macros.rs index 4362419..9f17c8b 100755 --- a/src/macros.rs +++ b/src/macros.rs @@ -164,7 +164,7 @@ mod test { use core::proxy::Proxy; metrics!{TEST: Proxy = "test_prefix" => { - M1: Marker = "failed"; + pub M1: Marker = "failed"; C1: Counter = "failed"; G1: Gauge = "failed"; T1: Timer = "failed"; diff --git a/src/output/format.rs b/src/output/format.rs index 67ef8d7..176b356 100644 --- a/src/output/format.rs +++ b/src/output/format.rs @@ -9,7 +9,7 @@ use std::sync::Arc; /// Print commands are steps in the execution of output templates. pub enum LineOp { /// Print a string. - Literal(String), + Literal(Vec), /// Lookup and print label value for key, if it exists. LabelExists(String, Vec), /// Print metric value as text. @@ -23,7 +23,7 @@ pub enum LineOp { /// Print commands are steps in the execution of output templates. pub enum LabelOp { /// Print a string. - Literal(String), + Literal(Vec), /// Print the label key. LabelKey, /// Print the label value. @@ -101,7 +101,7 @@ impl LineFormat for SimpleFormat { header.push(' '); LineTemplate { ops: vec![ - Literal(header), + Literal(header.into_bytes()), ValueAsText, NewLine, ] @@ -109,23 +109,6 @@ impl LineFormat for SimpleFormat { } } -//enum Parsed { -// Literal(String), -// Name() -// Value(Value), -// StaticLabel(String), -// DynamicLabel(String), -//} -// -//struct TemplateFormat { -// tokens: Vec -//} -// -//fn parse(template: &str) -> TemplateFormat { -// -//} - - #[cfg(test)] pub mod test { use super::*; @@ -141,7 +124,7 @@ pub mod test { header.push(' '); LineTemplate { ops: vec![ - Literal(header), + Literal(header.into()), ValueAsText, Literal(" ".into()), ScaledValueAsText(1000),