From 3dc30fedc2e1e4f1aa1597be707fa19d1ef66527 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Tue, 23 Nov 2021 23:08:37 +0000 Subject: [PATCH] Initial example of using a counter --- bare-metrics-recorder/examples/counter.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 bare-metrics-recorder/examples/counter.rs diff --git a/bare-metrics-recorder/examples/counter.rs b/bare-metrics-recorder/examples/counter.rs new file mode 100644 index 0000000..683d273 --- /dev/null +++ b/bare-metrics-recorder/examples/counter.rs @@ -0,0 +1,20 @@ +use bare_metrics_recorder::recording::BareMetricsRecorderCore; +use metrics::{increment_counter, register_counter, Unit}; +use std::fs::File; +use std::time::Duration; + +pub fn main() -> anyhow::Result<()> { + let (shard, stopper) = + BareMetricsRecorderCore::new(File::create("/tmp/counter-example.baremetrics")?).start()?; + shard.install_as_metrics_recorder()?; + register_counter!("my_counter", Unit::BitsPerSecond, "Some counter thing :)."); + + for _ in 0..300 { + increment_counter!("my_counter"); + std::thread::sleep(Duration::from_secs(1)); + } + + stopper.stop(); + + Ok(()) +}