Skip to content

Commit

Permalink
Expose the startup timestamp to Prometheus (#2233)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
paulhauner committed Mar 2, 2021
1 parent 02846e9 commit debc61e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lighthouse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions lighthouse/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod metrics;

use beacon_node::{get_eth2_network_config, ProductionBeaconNode};
use clap::{App, Arg, ArgMatches};
use env_logger::{Builder, Env};
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions lighthouse/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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
),
}
}

0 comments on commit debc61e

Please sign in to comment.