use polkadot_node_subsystem_util::{
metrics,
metrics::{
prometheus,
prometheus::{Gauge, PrometheusError, Registry, U64},
},
};
#[derive(Clone, Default)]
pub struct Metrics(Option<MetricsInner>);
#[derive(Clone)]
struct MetricsInner {
is_authority: Gauge<U64>,
is_parachain_validator: Gauge<U64>,
}
impl Metrics {
#[cfg(test)]
pub fn new_dummy() -> Self {
Self(None)
}
pub fn on_is_authority(&self) {
if let Some(metrics) = &self.0 {
metrics.is_authority.set(1);
}
}
pub fn on_is_not_authority(&self) {
if let Some(metrics) = &self.0 {
metrics.is_authority.set(0);
}
}
pub fn on_is_parachain_validator(&self) {
if let Some(metrics) = &self.0 {
metrics.is_parachain_validator.set(1);
}
}
pub fn on_is_not_parachain_validator(&self) {
if let Some(metrics) = &self.0 {
metrics.is_parachain_validator.set(0);
}
}
}
impl metrics::Metrics for Metrics {
fn try_register(registry: &Registry) -> Result<Self, PrometheusError> {
let metrics = MetricsInner {
is_authority: prometheus::register(
Gauge::new("polkadot_node_is_active_validator", "Tracks if the validator is in the active set. \
Updates at session boundary.")?,
registry,
)?,
is_parachain_validator: prometheus::register(
Gauge::new("polkadot_node_is_parachain_validator",
"Tracks if the validator participates in parachain consensus. Parachain validators are a \
subset of the active set validators that perform approval checking of all parachain candidates in a session.\
Updates at session boundary.")?,
registry,
)?,
};
Ok(Metrics(Some(metrics)))
}
}