Description
One oftentimes has a struct
of metrics like:
struct Metrics {
a: Counter,
b: Gauge,
}
Code to register the metrics in Metrics
with a Registry
could be generated via a derive macro on Metrics
.
- The metric name would be taken from the field name.
- The metric help text would be taken from the Rust doc String.
- The metric unit could be provided via a macro attribute.
#[derive(Register)]
struct Metrics {
/// My Gauge tracking the number of xxx
a: Counter,
/// My Counter, tracking the event xxx
#[prometheus-unit(Seconds)]
b: Gauge,
}
Where the Register
trait is something along the lines of:
trait Register {
fn create_and_register(registry: &mut Registry) -> Self;
}