Initial example of using a counter

This commit is contained in:
Olivier 'reivilibre' 2021-11-23 23:08:37 +00:00
parent d570d35112
commit 3dc30fedc2
1 changed files with 20 additions and 0 deletions

View File

@ -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(())
}