#prometheus-metrics #macro-derive #boilerplate #instantiation #write #storage #generate

prometheus-metric-storage

派生宏用于实例化和注册 Prometheus 度量值,无需编写大量样板代码

6 个版本 (破坏性)

0.5.0 2022 年 5 月 10 日
0.4.0 2021 年 10 月 6 日
0.3.0 2021 年 9 月 14 日
0.2.0 2021 年 9 月 8 日
0.1.1 2021 年 9 月 7 日

Rust 模式 中排名 1304

Download history 112/week @ 2024-03-14 133/week @ 2024-03-21 269/week @ 2024-03-28 167/week @ 2024-04-04 109/week @ 2024-04-11 161/week @ 2024-04-18 158/week @ 2024-04-25 210/week @ 2024-05-02 181/week @ 2024-05-09 162/week @ 2024-05-16 107/week @ 2024-05-23 185/week @ 2024-05-30 237/week @ 2024-06-06 233/week @ 2024-06-13 204/week @ 2024-06-20 106/week @ 2024-06-27

每月下载量 819
2 crates 中使用

MIT 许可证

28KB
216

Prometheus 度量值存储

tests



当使用 Prometheus 度量值对代码进行仪表化时,需要编写相当多的样板代码。

此 crate 将为您生成大部分此类样板代码

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

依赖项

~3.5–9MB
~87K SLoC