19 releases (11 breaking)

0.12.3 Mar 10, 2025
0.12.0 Feb 26, 2025
0.10.0 Sep 18, 2024
0.9.0 Jul 31, 2024
0.4.0 Mar 29, 2024

#516 in Math

Download history 172/week @ 2024-12-13 160/week @ 2024-12-20 322/week @ 2024-12-27 127/week @ 2025-01-03 413/week @ 2025-01-10 111/week @ 2025-01-17 175/week @ 2025-01-24 308/week @ 2025-01-31 601/week @ 2025-02-07 203/week @ 2025-02-14 668/week @ 2025-02-21 845/week @ 2025-02-28 460/week @ 2025-03-07 457/week @ 2025-03-14 458/week @ 2025-03-21 138/week @ 2025-03-28

1,696 downloads per month

MIT/Apache

45KB
905 lines

Exposition of Metriken metrics

Provides a standardized struct for a snapshot of the metric readings as well as a way of producing the snapshots.


metriken

Easily registered distributed metrics.

metriken allows you to easily declare static metrics throughout your codebase. Then, when you want to expose those metrics, you can access them all in one place.

use metriken::{metric, Counter, Gauge, Value};

/// A counter metric named "<crate name>::COUNTER"
#[metric]
static COUNTER: Counter = Counter::new();

/// A gauge metric named "my.metric"
#[metric(name = "my.metric")]
static GAUGE: Gauge = Gauge::new();

fn main() {
    COUNTER.increment();

    for metric in &metriken::metrics() {
        let name = metric.name();

        match metric.value() {
            Some(Value::Counter(val)) => println!("{name}: {val}"),
            Some(Value::Gauge(val)) => println!("{name}: {val}"),
            _ => println!("{name}: <custom>")
        }
    }
}

Code updating the metrics can always access them without needing to go through any indirections. (It just means accessing a static!). Using linkme, the metrics are all gathered into a single global array that can then be used to read all of them and expose them.

Dependencies

~4–14MB
~214K SLoC