22 releases (7 breaking)

0.7.0 Jun 12, 2024
0.5.1 Jan 18, 2024
0.3.3 Oct 25, 2023
0.2.1 Jul 26, 2023
0.1.3 Mar 24, 2023

#3 in #gauge

Download history 440/week @ 2024-07-26 603/week @ 2024-08-02 394/week @ 2024-08-09 373/week @ 2024-08-16 279/week @ 2024-08-23 201/week @ 2024-08-30 579/week @ 2024-09-06 259/week @ 2024-09-13 612/week @ 2024-09-20 567/week @ 2024-09-27 392/week @ 2024-10-04 245/week @ 2024-10-11 467/week @ 2024-10-18 381/week @ 2024-10-25 254/week @ 2024-11-01 162/week @ 2024-11-08

1,270 downloads per month
Used in 4 crates

Apache-2.0

110KB
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.1–7.5MB
~60K SLoC