21 releases (6 breaking)

0.6.0 Apr 2, 2024
0.5.1 Jan 18, 2024
0.4.2 Jan 20, 2024
0.3.3 Oct 25, 2023
0.1.3 Mar 24, 2023

#40 in Value formatting

Download history 22/week @ 2024-01-06 271/week @ 2024-01-13 599/week @ 2024-01-20 98427/week @ 2024-01-27 7669/week @ 2024-02-03 61/week @ 2024-02-10 932/week @ 2024-02-17 90/week @ 2024-02-24 527/week @ 2024-03-02 237/week @ 2024-03-09 332/week @ 2024-03-16 716/week @ 2024-03-23 777/week @ 2024-03-30 504/week @ 2024-04-06 340/week @ 2024-04-13 410/week @ 2024-04-20

2,107 downloads per month
Used in 4 crates

Apache-2.0

100KB
2K SLoC

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

~2.2–8MB
~60K SLoC