From 6b17939074262b1729b923c55d1358e420be98a1 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 10 Jun 2020 11:50:27 +0200 Subject: [PATCH] Add a [prefix]_process_start_time_seconds metric --- client/service/src/metrics.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/service/src/metrics.rs b/client/service/src/metrics.rs index f3463ffdbe616..4a47d412166ef 100644 --- a/client/service/src/metrics.rs +++ b/client/service/src/metrics.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::convert::TryFrom; +use std::{convert::TryFrom, time::SystemTime}; use crate::NetworkStatus; use prometheus_endpoint::{register, Gauge, U64, F64, Registry, PrometheusError, Opts, GaugeVec}; @@ -79,6 +79,13 @@ impl PrometheusMetrics { register_globals(registry)?; + let start_time_since_epoch = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) + .unwrap_or_default(); + register(Gauge::::new( + "process_start_time_seconds", + "Number of seconds between the UNIX epoch and the moment the process started", + )?, registry)?.set(start_time_since_epoch.as_secs()); + Ok(Self { // system #[cfg(all(any(unix, windows), not(target_os = "android")))]