derive-prom-metrics

Crates.ioderive-prom-metrics
lib.rsderive-prom-metrics
version0.1.0
sourcesrc
created_at2024-11-18 10:30:12.656727
updated_at2024-11-18 10:30:12.656727
descriptionBuild Prometheus metrics declaratively as structs
homepage
repositoryhttps://github.com/0xangelo/derive-prom-metrics
max_upload_size
id1452080
size49,457
Ângelo (0xangelo)

documentation

README

derive-prom-metrics

Crates.io Docs.rs CI Rust GitHub Template

Build Prometheus metrics declaratively as structs.

This crate is in the very early stages of development.

Example

use derive_prom_metrics::Metrics;
use prometheus::{linear_buckets, Gauge};

#[derive(Metrics, Debug)]
struct Metrics {
    /// A simple counter.
    counter: prometheus::Counter,

    /// A simple gauge.
    /// Is this in the same line? No.
    ///
    /// This will make it into the help text.
    gauge: Gauge,

    /**
     * My help
     *
     * This will make it into the help text, as well as all of the leading asterisks.
     */
    int_counter: prometheus::IntCounter,

    /// An integer gauge.
    int_gauge: prometheus::IntGauge,

    /// A histogram.
    #[prometheus(buckets = linear_buckets(0.005, 0.005, 999)?)]
    histogram: prometheus::Histogram,

    /// A vector of counters, one for each label.
    #[prometheus(label_names = &["label"])]
    counter_vec: prometheus::CounterVec,

    /// A vector of gauges, one for each label.
    #[prometheus(label_names = &["label"])]
    gauge_vec: prometheus::GaugeVec,

    /// A vector of integer counters, one for each label.
    #[prometheus(label_names = &["label"])]
    int_counter_vec: prometheus::IntCounterVec,

    /// A vector of integer gauges, one for each label.
    #[prometheus(label_names = &["label"])]
    int_gauge_vec: prometheus::GaugeVec,

    /// A vector of histograms, one for each label.
    #[prometheus(
        buckets = linear_buckets(0.005, 0.005, 999)?,
        label_names = &["label"],
    )]
    histogram_vec: prometheus::HistogramVec,
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

See CONTRIBUTING.md.

Credits

Created using https://rust-github.github.io/.

Commit count: 13

cargo fmt