From 8ecbb5f15220b29c5a5ddba87ae9595725bced0c Mon Sep 17 00:00:00 2001 From: Lukas Wagner Date: Tue, 15 Oct 2024 10:46:33 +0200 Subject: [PATCH] pbs-api-types: add types for the new metrics endpoint Signed-off-by: Lukas Wagner --- pbs-api-types/src/metrics.rs | 66 ++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/pbs-api-types/src/metrics.rs b/pbs-api-types/src/metrics.rs index 234210354..262665292 100644 --- a/pbs-api-types/src/metrics.rs +++ b/pbs-api-types/src/metrics.rs @@ -187,3 +187,69 @@ pub struct MetricServerInfo { #[serde(skip_serializing_if = "Option::is_none")] pub comment: Option, } + +#[derive(Clone, Debug, Deserialize, Serialize)] +#[api( + properties: { + data: { + type: Array, + items: { + type: MetricDataPoint, + } + } + } +)] +/// Return type for the metric API endpoint +pub struct Metrics { + /// List of metric data points, sorted by timestamp + pub data: Vec, +} + +#[api( + properties: { + id: { + type: String, + }, + metric: { + type: String, + }, + timestamp: { + type: Integer, + }, + }, +)] +/// Metric data point +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct MetricDataPoint { + /// Unique identifier for this metric object, for instance 'node/' + /// or 'qemu/'. + pub id: String, + + /// Name of the metric. + pub metric: String, + + /// Time at which this metric was observed + pub timestamp: i64, + + #[serde(rename = "type")] + pub ty: MetricDataType, + + /// Metric value. + pub value: f64, +} + +#[api] +/// Type of the metric. +#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum MetricDataType { + /// gauge. + Gauge, + /// counter. + Counter, + /// derive. + Derive, +} + +serde_plain::derive_display_from_serialize!(MetricDataType); +serde_plain::derive_fromstr_from_deserialize!(MetricDataType);