vector/api/schema/metrics/
uptime.rs

1use async_graphql::Object;
2use chrono::{DateTime, Utc};
3
4use crate::event::{Metric, MetricValue};
5
6pub struct Uptime(Metric);
7
8impl Uptime {
9    pub const fn new(m: Metric) -> Self {
10        Self(m)
11    }
12}
13
14#[Object]
15impl Uptime {
16    /// Metric timestamp
17    pub async fn timestamp(&self) -> Option<DateTime<Utc>> {
18        self.0.timestamp()
19    }
20
21    /// Number of seconds the Vector instance has been alive
22    pub async fn seconds(&self) -> f64 {
23        match self.0.value() {
24            MetricValue::Gauge { value } => *value,
25            _ => 0.00,
26        }
27    }
28}
29
30impl From<Metric> for Uptime {
31    fn from(m: Metric) -> Self {
32        Self(m)
33    }
34}