-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
da8791a
commit b30ff6a
Showing
4 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
), | ||
} | ||
} |