prometheus-metric-storage

Crates.ioprometheus-metric-storage
lib.rsprometheus-metric-storage
version0.5.0
sourcesrc
created_at2021-09-02 10:17:17.461262
updated_at2022-05-10 16:37:25.988856
descriptionDerive macro to instantiate and register prometheus metrics without having to write tons of boilerplate code
homepagehttps://github.com/taminomara/prometheus-metric-storage
repositoryhttps://github.com/taminomara/prometheus-metric-storage
max_upload_size
id445923
size26,441
Tamika Nomara (taminomara)

documentation

https://docs.rs/prometheus-metric-storage

README

Prometheus metric storage

tests



When instrumenting code with prometheus metrics, one is required to write quite a bit of boilerplate code.

This crate will generate most of said boilerplate for you:

#[derive(prometheus_metric_storage::MetricStorage)]
#[metric(subsystem = "transport", labels("endpoint"))]
struct Metrics {
    /// Number of requests that are currently inflight.
    inflight: prometheus::IntGauge,

    /// Number of finished requests by response code.
    #[metric(labels("status"))]
    requests_finished: prometheus::IntCounterVec,

    /// Number of finished requests by total processing duration.
    #[metric(buckets(0.1, 0.2, 0.5, 1, 2, 4, 8))]
    requests_duration_seconds: prometheus::Histogram,
}

fn main() {
    let metrics = Metrics::new(
        prometheus::default_registry(),
        /* endpoint = */ "0.0.0.0:8080"
    ).unwrap();

    metrics.inflight.inc();
    metrics.requests_finished.with_label_values(&["200"]).inc();
    metrics.requests_duration_seconds.observe(0.015);
}
Commit count: 29

cargo fmt