2 releases

0.1.1 Jan 18, 2024
0.1.0 Jan 17, 2024

#6 in #registered

Download history 284/week @ 2024-07-25 501/week @ 2024-08-01 526/week @ 2024-08-08 385/week @ 2024-08-15 291/week @ 2024-08-22 209/week @ 2024-08-29 418/week @ 2024-09-05 421/week @ 2024-09-12 514/week @ 2024-09-19 567/week @ 2024-09-26 421/week @ 2024-10-03 321/week @ 2024-10-10 447/week @ 2024-10-17 203/week @ 2024-10-24 339/week @ 2024-10-31 228/week @ 2024-11-07

1,321 downloads per month
Used in 5 crates (via metriken)

Apache-2.0

32KB
592 lines

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

~1–6MB
~35K SLoC