From 206486006cd6a913b1e0dcb1959f75dcd639a4a7 Mon Sep 17 00:00:00 2001 From: Mac L Date: Fri, 2 Jul 2021 01:33:30 +0000 Subject: [PATCH] Add Lighthouse version and commit hash to Prometheus metrics (#2427) ## Issue Addressed #2225 ## Proposed Changes Exposes the version given from the `lighthouse_version` crate to the Prometheus metrics server. ## Additional Info - This metric appears in both the Beacon Node and Validator Client metrics servers. - This is the simplest solution. It might be better to include the version and commit hash as separate labels rather than combined, however this would be more involved. Happy to do it that way if this is too cumbersome to use. - The metric appears as: ``` # HELP lighthouse_info The build of Lighthouse running on the server # TYPE lighthouse_info gauge lighthouse_info{version="Lighthouse/v1.4.0-379664a+"} 1 ``` --- lighthouse/src/main.rs | 3 +++ lighthouse/src/metrics.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index e49e29f3f..7eda9bfe8 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -274,6 +274,9 @@ fn run( // Allow Prometheus to export the time at which the process was started. metrics::expose_process_start_time(&log); + // Allow Prometheus access to the version and commit of the Lighthouse build. + metrics::expose_lighthouse_version(); + if matches.is_present("spec") { warn!( log, diff --git a/lighthouse/src/metrics.rs b/lighthouse/src/metrics.rs index ac880602f..ef3c33d29 100644 --- a/lighthouse/src/metrics.rs +++ b/lighthouse/src/metrics.rs @@ -1,5 +1,6 @@ use lazy_static::lazy_static; pub use lighthouse_metrics::*; +use lighthouse_version::VERSION; use slog::{error, Logger}; use std::time::{SystemTime, UNIX_EPOCH}; @@ -10,6 +11,14 @@ lazy_static! { ); } +lazy_static! { + pub static ref LIGHTHOUSE_VERSION: Result = try_create_int_gauge_vec( + "lighthouse_info", + "The build of Lighthouse running on the server", + &["version"], + ); +} + pub fn expose_process_start_time(log: &Logger) { match SystemTime::now().duration_since(UNIX_EPOCH) { Ok(duration) => set_gauge(&PROCESS_START_TIME_SECONDS, duration.as_secs() as i64), @@ -20,3 +29,7 @@ pub fn expose_process_start_time(log: &Logger) { ), } } + +pub fn expose_lighthouse_version() { + set_gauge_vec(&LIGHTHOUSE_VERSION, &[VERSION], 1); +}