8 releases (5 breaking)

0.5.1 Jan 18, 2024
0.5.0 Jan 17, 2024
0.4.1 Jan 18, 2024
0.3.4 Jan 18, 2024
0.0.0 Jan 17, 2023

#17 in #declare

Download history 211/week @ 2024-06-16 434/week @ 2024-06-23 386/week @ 2024-06-30 165/week @ 2024-07-07 65/week @ 2024-07-14 365/week @ 2024-07-21 476/week @ 2024-07-28 459/week @ 2024-08-04 457/week @ 2024-08-11 288/week @ 2024-08-18 240/week @ 2024-08-25 189/week @ 2024-09-01 633/week @ 2024-09-08 224/week @ 2024-09-15 721/week @ 2024-09-22 513/week @ 2024-09-29

2,092 downloads per month
Used in 5 crates (via metriken)

Apache-2.0

15KB
300 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.4–2MB
~41K SLoC