Crates.io | prom-timer-macro |
lib.rs | prom-timer-macro |
version | 0.1.1 |
source | src |
created_at | 2022-06-30 11:36:27.526583 |
updated_at | 2022-06-30 11:36:27.526583 |
description | RAII Prometheus Timer for monitoring & tracing |
homepage | https://github.com/neogenie/prom-timer |
repository | https://github.com/neogenie/prom-timer |
max_upload_size | |
id | 616340 |
size | 6,254 |
Rust RAII Prometheus timer
use std::collections::HashMap;
use std::thread::sleep;
use std::time::Duration;
use prometheus::{self, HistogramVec, histogram_opts};
use prom_timer_macro::timer;
use lazy_static::lazy_static;
lazy_static! { static ref TIMER: HistogramVec = HistogramVec::new(
histogram_opts!("timer", "Timer")
.namespace("api")
.const_labels(HashMap::new())
.buckets(
[
0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 1.0, 2.0,
3.0, 4.0, 5.0, 10.0,
]
.into(),
),
&["function"],
)
.unwrap();}
#[timer(TIMER.clone(), "f")]
fn f() {
sleep(Duration::from_secs(1));
}
#[test]
fn test() {
f();
}