6 releases (breaking)

0.5.0 May 10, 2022
0.4.0 Oct 6, 2021
0.3.0 Sep 14, 2021
0.2.0 Sep 8, 2021
0.1.1 Sep 7, 2021

#73 in #detail

Download history 13/week @ 2023-12-06 56/week @ 2023-12-13 36/week @ 2023-12-20 32/week @ 2023-12-27 51/week @ 2024-01-03 119/week @ 2024-01-10 97/week @ 2024-01-17 80/week @ 2024-01-24 107/week @ 2024-01-31 141/week @ 2024-02-07 177/week @ 2024-02-14 168/week @ 2024-02-21 104/week @ 2024-02-28 145/week @ 2024-03-06 98/week @ 2024-03-13 125/week @ 2024-03-20

503 downloads per month
Used in 3 crates (via prometheus-metric-storage)

MIT license

15KB
319 lines

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);
}

lib.rs:

This crate is an implementation detail for prometheus-metric-storage.

Dependencies

~1.5MB
~34K SLoC