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.
- Global
Registry service
This struct can be used with the functions incrate::service
to use them with the global staticCore
defined in this module.