feat: expose version information over prometheus (#6195)

This commit is contained in:
Dan Cline
2024-01-24 12:52:15 -05:00
committed by GitHub
parent 92908b190a
commit 575b5d3f53
6 changed files with 30 additions and 3 deletions

View File

@@ -14,11 +14,14 @@ pub mod dirs;
pub mod engine_api_store;
pub mod events;
pub mod init;
pub mod metrics;
pub mod node_config;
pub mod prometheus_exporter;
pub mod utils;
pub mod version;
// Re-export for backwards compatibility.
pub use metrics::prometheus_exporter;
/// Re-exported from `reth_primitives`.
pub mod primitives {
pub use reth_primitives::*;

View File

@@ -0,0 +1,4 @@
//! Metrics utilities for the node.
pub mod prometheus_exporter;
pub mod version_metrics;

View File

@@ -1,5 +1,6 @@
//! Prometheus exporter
use crate::metrics::version_metrics::register_version_metrics;
use eyre::WrapErr;
use hyper::{
service::{make_service_fn, service_fn},
@@ -104,6 +105,7 @@ where
process.describe();
describe_memory_stats();
describe_io_stats();
register_version_metrics();
Ok(())
}

View File

@@ -0,0 +1,18 @@
//! This exposes reth's version information over prometheus.
use crate::version::build_profile_name;
use metrics::register_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", env!("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() {
register_gauge!("info", &LABELS);
}

View File

@@ -16,7 +16,7 @@ use crate::{
engine_api_store::EngineApiStore,
events,
init::init_genesis,
prometheus_exporter,
metrics::prometheus_exporter,
utils::{get_single_header, write_peers_to_file},
version::SHORT_VERSION,
};

View File

@@ -79,7 +79,7 @@ pub fn default_extradata() -> String {
format!("reth/v{}/{}", env!("CARGO_PKG_VERSION"), std::env::consts::OS)
}
const fn build_profile_name() -> &'static str {
pub(crate) const fn build_profile_name() -> &'static str {
// Derived from https://stackoverflow.com/questions/73595435/how-to-get-profile-from-cargo-toml-in-build-rs-or-at-runtime
// We split on the path separator of the *host* machine, which may be different from
// `std::path::MAIN_SEPARATOR_STR`.