Unify metric names (#1209)

* unify metric names

* refactor standalone metrics

* headers sync metrics

* post-merge fix

* fix compilation

* fmt

* fix dashboards

* fix local dashboards

* update Rococo/Wococo runtime version

* remove commented code

* fixed grumbles

* fmt

* fixed widget names
This commit is contained in:
Svyatoslav Nikolsky
2021-11-22 15:38:42 +03:00
committed by Bastian Köcher
parent 940d7e463b
commit bbf8b51f9c
33 changed files with 509 additions and 515 deletions
+21 -17
View File
@@ -46,28 +46,38 @@ pub struct MetricsParams {
/// Interface and TCP port to be used when exposing Prometheus metrics.
pub address: Option<MetricsAddress>,
/// Metrics registry. May be `Some(_)` if several components share the same endpoint.
pub registry: Option<Registry>,
/// Prefix that must be used in metric names.
pub metrics_prefix: Option<String>,
pub registry: Registry,
}
/// Metrics API.
pub trait Metrics: Clone + Send + Sync + 'static {}
/// Metric API.
pub trait Metric: Clone + Send + Sync + 'static {
fn register(&self, registry: &Registry) -> Result<(), PrometheusError>;
}
impl<T: Clone + Send + Sync + 'static> Metrics for T {}
/// Standalone metrics API.
/// Standalone metric API.
///
/// Metrics of this kind know how to update themselves, so we may just spawn and forget the
/// asynchronous self-update task.
#[async_trait]
pub trait StandaloneMetrics: Metrics {
pub trait StandaloneMetric: Metric {
/// Update metric values.
async fn update(&self);
/// Metrics update interval.
fn update_interval(&self) -> Duration;
/// Register and spawn metric. Metric is only spawned if it is registered for the first time.
fn register_and_spawn(self, registry: &Registry) -> Result<(), PrometheusError> {
match self.register(registry) {
Ok(()) => {
self.spawn();
Ok(())
},
Err(PrometheusError::AlreadyReg) => Ok(()),
Err(e) => Err(e),
}
}
/// Spawn the self update task that will keep update metric value at given intervals.
fn spawn(self) {
async_std::task::spawn(async move {
@@ -89,7 +99,7 @@ impl Default for MetricsAddress {
impl MetricsParams {
/// Creates metrics params so that metrics are not exposed.
pub fn disabled() -> Self {
MetricsParams { address: None, registry: None, metrics_prefix: None }
MetricsParams { address: None, registry: Registry::new() }
}
/// Do not expose metrics.
@@ -97,17 +107,11 @@ impl MetricsParams {
self.address = None;
self
}
/// Set prefix to use in metric names.
pub fn metrics_prefix(mut self, prefix: String) -> Self {
self.metrics_prefix = Some(prefix);
self
}
}
impl From<Option<MetricsAddress>> for MetricsParams {
fn from(address: Option<MetricsAddress>) -> Self {
MetricsParams { address, registry: None, metrics_prefix: None }
MetricsParams { address, registry: Registry::new() }
}
}