1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use async_graphql::Object;
use chrono::{DateTime, Utc};

use crate::event::{Metric, MetricValue};

pub struct Uptime(Metric);

impl Uptime {
    pub const fn new(m: Metric) -> Self {
        Self(m)
    }
}

#[Object]
impl Uptime {
    /// Metric timestamp
    pub async fn timestamp(&self) -> Option<DateTime<Utc>> {
        self.0.timestamp()
    }

    /// Number of seconds the Vector instance has been alive
    pub async fn seconds(&self) -> f64 {
        match self.0.value() {
            MetricValue::Gauge { value } => *value,
            _ => 0.00,
        }
    }
}

impl From<Metric> for Uptime {
    fn from(m: Metric) -> Self {
        Self(m)
    }
}