mirror of
https://git.ghostchain.io/proxmio/ghost-node.git
synced 2025-12-27 11:19:57 +00:00
inital commit, which is clearly not initial
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
47
metrics/src/lib.rs
Normal file
47
metrics/src/lib.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user