LCOV - code coverage report
Current view: top level - libs/metrics/src - launch_timestamp.rs (source / functions) Coverage Total Hit
Test: fabb29a6339542ee130cd1d32b534fafdc0be240.info Lines: 0.0 % 16 0
Test Date: 2024-06-25 13:20:00 Functions: 0.0 % 3 0

            Line data    Source code
       1              : //! A timestamp captured at process startup to identify restarts of the process, e.g., in logs and metrics.
       2              : 
       3              : use chrono::Utc;
       4              : 
       5              : use super::register_uint_gauge;
       6              : use std::fmt::Display;
       7              : 
       8              : pub struct LaunchTimestamp(chrono::DateTime<Utc>);
       9              : 
      10              : impl LaunchTimestamp {
      11            0 :     pub fn generate() -> Self {
      12            0 :         LaunchTimestamp(Utc::now())
      13            0 :     }
      14              : }
      15              : 
      16              : impl Display for LaunchTimestamp {
      17            0 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      18            0 :         write!(f, "{}", self.0)
      19            0 :     }
      20              : }
      21              : 
      22            0 : pub fn set_launch_timestamp_metric(launch_ts: &'static LaunchTimestamp) {
      23            0 :     let millis_since_epoch: u64 = launch_ts
      24            0 :         .0
      25            0 :         .timestamp_millis()
      26            0 :         .try_into()
      27            0 :         .expect("we're after the epoch, this should be positive");
      28            0 :     let metric = register_uint_gauge!(
      29              :         "libmetrics_launch_timestamp",
      30              :         "Timestamp (millis since epoch) at wich the process launched."
      31              :     )
      32            0 :     .unwrap();
      33            0 :     metric.set(millis_since_epoch);
      34            0 : }
        

Generated by: LCOV version 2.1-beta