MrBoec/metrics/src/lib.rs
Uncle Stretch 66719626bb
inital commit, which is clearly not initial
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2024-10-03 15:38:52 +03:00

48 lines
1.3 KiB
Rust

pub use metered;
pub mod metronome;
pub use self::metronome::Metronome;
#[cfg(feature = "runtime-metrics")]
pub mod runtime;
#[cfg(feature = "runtime-metrics")]
pub use self::runtime::logger_hook;
/// Export a dummy logger hook when the `runtime-metrics` feature is not enbaled.
#[cfg(not(feature = "runtime-metrics"))]
pub fn logger_hook() -> impl FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration) {
|_logger_builder, _config| {}
}
/// This module exports Prometheus types an:d defines
/// the [`Metrics`](metrics::Metrics) trait.
pub mod metrics {
pub use prometheus_endpoint as prometheus;
pub trait Metrics: Default + Clone {
fn try_register(
registry: &prometheus::Registry,
) -> Result<Self, prometheus::PrometheusError>;
fn register(
registry: Option<&prometheus::Registry>,
) -> Result<Self, prometheus::PrometheusError> {
match registry {
None => Ok(Self::default()),
Some(registry) => Self::try_register(registry),
}
}
}
impl Metrics for () {
fn try_register(
_registry: &prometheus::Registry,
) -> Result<(), prometheus::PrometheusError> {
Ok(())
}
}
}
#[cfg(all(feature = "runtime-metrics", not(feature = "runtime-benchmarks"), test))]
mod tests;