vector/api/schema/metrics/
allocated_bytes.rs1use async_graphql::Object;
2use chrono::{DateTime, Utc};
3
4use crate::{
5 config::ComponentKey,
6 event::{Metric, MetricValue},
7};
8
9pub struct AllocatedBytes(Metric);
10
11impl AllocatedBytes {
12 pub const fn new(m: Metric) -> Self {
13 Self(m)
14 }
15}
16
17#[Object]
18impl AllocatedBytes {
19 pub async fn timestamp(&self) -> Option<DateTime<Utc>> {
21 self.0.timestamp()
22 }
23
24 pub async fn allocated_bytes(&self) -> f64 {
26 match self.0.value() {
27 MetricValue::Gauge { value } => *value,
28 _ => 0.00,
29 }
30 }
31}
32
33impl From<Metric> for AllocatedBytes {
34 fn from(m: Metric) -> Self {
35 Self(m)
36 }
37}
38
39pub struct ComponentAllocatedBytes {
40 component_key: ComponentKey,
41 metric: Metric,
42}
43
44impl ComponentAllocatedBytes {
45 pub fn new(metric: Metric) -> Self {
48 let component_key = metric.tag_value("component_id").expect(
49 "Returned a metric without a `component_id`, which shouldn't happen. Please report.",
50 );
51 let component_key = ComponentKey::from(component_key);
52
53 Self {
54 component_key,
55 metric,
56 }
57 }
58}
59
60#[Object]
61impl ComponentAllocatedBytes {
62 async fn component_id(&self) -> &str {
64 self.component_key.id()
65 }
66
67 async fn metric(&self) -> AllocatedBytes {
69 AllocatedBytes::new(self.metric.clone())
70 }
71}