Expose the startup timestamp to Prometheus (#2233)
## Issue Addressed Resolves #1788 ## Proposed Changes As per #1788, expose the time at which the process started via the `process_start_time_seconds` Prometheus metric. This will help users track uptime. ## Additional Info NA Co-authored-by: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
parent
da8791abd7
commit
b30ff6affc
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3721,6 +3721,8 @@ dependencies = [
|
||||
"environment",
|
||||
"eth2_network_config",
|
||||
"futures 0.3.13",
|
||||
"lazy_static",
|
||||
"lighthouse_metrics",
|
||||
"lighthouse_version",
|
||||
"logging",
|
||||
"remote_signer",
|
||||
|
@ -41,6 +41,8 @@ directory = { path = "../common/directory" }
|
||||
lighthouse_version = { path = "../common/lighthouse_version" }
|
||||
account_utils = { path = "../common/account_utils" }
|
||||
remote_signer = { "path" = "../remote_signer" }
|
||||
lighthouse_metrics = { path = "../common/lighthouse_metrics" }
|
||||
lazy_static = "1.4.0"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.1.0"
|
||||
|
@ -1,3 +1,5 @@
|
||||
mod metrics;
|
||||
|
||||
use beacon_node::{get_eth2_network_config, ProductionBeaconNode};
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use env_logger::{Builder, Env};
|
||||
@ -219,6 +221,9 @@ fn run<E: EthSpec>(
|
||||
|
||||
let log = environment.core_context().log().clone();
|
||||
|
||||
// Allow Prometheus to export the time at which the process was started.
|
||||
metrics::expose_process_start_time(&log);
|
||||
|
||||
if matches.is_present("spec") {
|
||||
warn!(
|
||||
log,
|
||||
|
22
lighthouse/src/metrics.rs
Normal file
22
lighthouse/src/metrics.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use lazy_static::lazy_static;
|
||||
pub use lighthouse_metrics::*;
|
||||
use slog::{error, Logger};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref PROCESS_START_TIME_SECONDS: Result<IntGauge> = try_create_int_gauge(
|
||||
"process_start_time_seconds",
|
||||
"The unix timestamp at which the process was started"
|
||||
);
|
||||
}
|
||||
|
||||
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),
|
||||
Err(e) => error!(
|
||||
log,
|
||||
"Failed to read system time";
|
||||
"error" => %e
|
||||
),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user