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 std::sync::Arc;

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

#[derive(Debug, Default, MetricsGroup)]
#[metrics(name = "my_metrics")]
pub struct Metrics {
    /// things_added tracks the number of things we have added
    pub things_added: Counter,
}

Core::init(|reg, metrics| {
    let m = Arc::new(Metrics::default());
    reg.register(m.clone());
    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.