mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor(node-core/matrics): refactor the register version metrics function (#9149)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
//! Prometheus exporter
|
||||
|
||||
use crate::metrics::version_metrics::register_version_metrics;
|
||||
use crate::metrics::version_metrics::VersionInfo;
|
||||
use eyre::WrapErr;
|
||||
use futures::{future::FusedFuture, FutureExt};
|
||||
use http::Response;
|
||||
@ -151,7 +151,7 @@ where
|
||||
process.describe();
|
||||
describe_memory_stats();
|
||||
describe_io_stats();
|
||||
register_version_metrics();
|
||||
VersionInfo::default().register_version_metrics();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -3,16 +3,48 @@
|
||||
use crate::version::{build_profile_name, VERGEN_GIT_SHA};
|
||||
use metrics::gauge;
|
||||
|
||||
const LABELS: [(&str, &str); 6] = [
|
||||
("version", env!("CARGO_PKG_VERSION")),
|
||||
("build_timestamp", env!("VERGEN_BUILD_TIMESTAMP")),
|
||||
("cargo_features", env!("VERGEN_CARGO_FEATURES")),
|
||||
("git_sha", VERGEN_GIT_SHA),
|
||||
("target_triple", env!("VERGEN_CARGO_TARGET_TRIPLE")),
|
||||
("build_profile", build_profile_name()),
|
||||
];
|
||||
|
||||
/// This exposes reth's version information over prometheus.
|
||||
pub fn register_version_metrics() {
|
||||
let _gauge = gauge!("info", &LABELS);
|
||||
/// Contains version information for the application.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct VersionInfo {
|
||||
/// The version of the application.
|
||||
pub version: &'static str,
|
||||
/// The build timestamp of the application.
|
||||
pub build_timestamp: &'static str,
|
||||
/// The cargo features enabled for the build.
|
||||
pub cargo_features: &'static str,
|
||||
/// The Git SHA of the build.
|
||||
pub git_sha: &'static str,
|
||||
/// The target triple for the build.
|
||||
pub target_triple: &'static str,
|
||||
/// The build profile (e.g., debug or release).
|
||||
pub build_profile: &'static str,
|
||||
}
|
||||
|
||||
impl Default for VersionInfo {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
version: env!("CARGO_PKG_VERSION"),
|
||||
build_timestamp: env!("VERGEN_BUILD_TIMESTAMP"),
|
||||
cargo_features: env!("VERGEN_CARGO_FEATURES"),
|
||||
git_sha: VERGEN_GIT_SHA,
|
||||
target_triple: env!("VERGEN_CARGO_TARGET_TRIPLE"),
|
||||
build_profile: build_profile_name(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VersionInfo {
|
||||
/// This exposes reth's version information over prometheus.
|
||||
pub fn register_version_metrics(&self) {
|
||||
let labels: [(&str, &str); 6] = [
|
||||
("version", self.version),
|
||||
("build_timestamp", self.build_timestamp),
|
||||
("cargo_features", self.cargo_features),
|
||||
("git_sha", self.git_sha),
|
||||
("target_triple", self.target_triple),
|
||||
("build_profile", self.build_profile),
|
||||
];
|
||||
|
||||
let _gauge = gauge!("info", &labels);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user