macro_rules! build_metrics_service {
($service:ident, $($metric_attribute:ident:$metric_type:ident ($name:literal, $help:literal $(, $labels:expr)?)),*) => { ... };
}Expand description
Create a MetricService.
To build the service you need to provide the structure name and a list of metrics. Each metrics is defined by an attribute name, a type, a metric name and a help message.
The attribute name will be used to create a getter method for the metric.
Crate that use this macro should have paste as dependency.
§Example of ‘build_metrics_service’ and metrics usage
use slog::Logger;
use mithril_common::{entities::Epoch, StdResult};
use mithril_metric::build_metrics_service;
use mithril_metric::{MetricCollector, MetricCounter, MetricCounterWithLabels, MetricGauge, MetricsServiceExporter};
build_metrics_service!(
MetricsService,
counter_example: MetricCounter(
"custom_counter_example_name",
"Example of a counter metric"
),
gauge_example: MetricGauge(
"custom_gauge_example_name",
"Example of a gauge metric"
),
counter_with_labels_example: MetricCounterWithLabels(
"custom_counter_with_labels_example_name",
"Example of a counter with labels metric",
&["label"]
)
);
let service = MetricsService::new(Logger::root(slog::Discard, slog::o!())).unwrap();
service.get_counter_example().increment();
service.get_gauge_example().record(Epoch(12));
service.get_counter_with_labels_example().increment(&["guest"]);