iroh_metrics

Module static_core

Source
Available on crate feature static_core only.
Expand description

Metrics collection in a static, process-level global metrics collector.

Enables and manages a global registry of metrics. Divided up into modules, each module has its own metrics.

  • To increment a counter, use the crate::inc macro with a value.
  • To increment a counter by 1, use the crate::inc_by macro.

To expose the metrics, start the metrics service with start_metrics_server().

§Example:

use iroh_metrics::{inc, inc_by, iterable::Iterable, static_core::Core, Counter, MetricsGroup};

#[derive(Debug, Clone, Iterable)]
pub struct Metrics {
    pub things_added: Counter,
}

impl Default for Metrics {
    fn default() -> Self {
        Self {
            things_added: Counter::new(
                "things_added tracks the number of things we have added",
            ),
        }
    }
}

impl MetricsGroup for Metrics {
    fn name(&self) -> &'static str {
        "my_metrics"
    }
}

Core::init(|reg, metrics| {
    let m = Metrics::default();
    m.register(reg);
    metrics.insert(m);
});

inc_by!(Metrics, things_added, 2);
inc!(Metrics, things_added);

Structs§

  • Core is the base metrics struct.
  • This struct can be used with the functions in crate::service to use them with the global static Core defined in this module.