Skip to main content

proxmox_api/generated/cluster/metrics/
export.rs

1#[derive(Debug, Clone)]
2pub struct ExportClient<T> {
3    client: T,
4    path: String,
5}
6impl<T> ExportClient<T>
7where
8    T: crate::client::Client,
9{
10    pub fn new(client: T, parent_path: &str) -> Self {
11        Self {
12            client,
13            path: format!("{}{}", parent_path, "/export"),
14        }
15    }
16}
17impl<T> ExportClient<T>
18where
19    T: crate::client::Client,
20{
21    #[doc = "Retrieve metrics of the cluster."]
22    #[doc = ""]
23    #[doc = "Permission check: perm(\"/\", [\"Sys.Audit\"])"]
24    pub async fn get(&self, params: GetParams) -> Result<GetOutput, T::Error> {
25        let path = self.path.to_string();
26        self.client.get(&path, &params).await
27    }
28}
29impl DataGetOutputDataItems {
30    pub fn new(id: String, metric: String, timestamp: i64, ty: Type, value: f64) -> Self {
31        Self {
32            id,
33            metric,
34            timestamp,
35            ty,
36            value,
37        }
38    }
39}
40#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
41pub struct DataGetOutputDataItems {
42    #[doc = "Unique identifier for this metric object, for instance 'node/\\\\<nodename\\\\>' or 'qemu/\\\\<vmid\\\\>'."]
43    #[doc = ""]
44    pub id: String,
45    #[doc = "Name of the metric."]
46    #[doc = ""]
47    pub metric: String,
48    #[serde(
49        serialize_with = "crate::types::serialize_int",
50        deserialize_with = "crate::types::deserialize_int"
51    )]
52    #[doc = "Time at which this metric was observed"]
53    #[doc = ""]
54    pub timestamp: i64,
55    #[serde(rename = "type")]
56    #[doc = "Type of the metric."]
57    #[doc = ""]
58    pub ty: Type,
59    #[serde(
60        serialize_with = "crate::types::serialize_number",
61        deserialize_with = "crate::types::deserialize_number"
62    )]
63    #[doc = "Metric value."]
64    #[doc = ""]
65    pub value: f64,
66}
67impl GetOutput {
68    pub fn new(data: Vec<DataGetOutputDataItems>) -> Self {
69        Self { data }
70    }
71}
72#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
73pub struct GetOutput {
74    #[serde(skip_serializing_if = "::std::vec::Vec::is_empty", default)]
75    #[doc = "Array of system metrics. Metrics are sorted by their timestamp."]
76    #[doc = ""]
77    pub data: Vec<DataGetOutputDataItems>,
78}
79#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, Default)]
80pub struct GetParams {
81    #[serde(
82        serialize_with = "crate::types::serialize_bool_optional",
83        deserialize_with = "crate::types::deserialize_bool_optional"
84    )]
85    #[serde(skip_serializing_if = "Option::is_none", default)]
86    #[doc = "Also return historic values. Returns full available metric history unless `start-time` is also set"]
87    #[doc = ""]
88    pub history: Option<bool>,
89    #[serde(rename = "local-only")]
90    #[serde(
91        serialize_with = "crate::types::serialize_bool_optional",
92        deserialize_with = "crate::types::deserialize_bool_optional"
93    )]
94    #[serde(skip_serializing_if = "Option::is_none", default)]
95    #[doc = "Only return metrics for the current node instead of the whole cluster"]
96    #[doc = ""]
97    pub local_only: Option<bool>,
98    #[serde(rename = "node-list")]
99    #[serde(skip_serializing_if = "Option::is_none", default)]
100    #[doc = "Only return metrics from nodes passed as comma-separated list"]
101    #[doc = ""]
102    pub node_list: Option<String>,
103    #[serde(rename = "start-time")]
104    #[serde(
105        serialize_with = "crate::types::serialize_int_optional",
106        deserialize_with = "crate::types::deserialize_int_optional"
107    )]
108    #[serde(skip_serializing_if = "Option::is_none", default)]
109    #[doc = "Only include metrics with a timestamp \\\\> start-time."]
110    #[doc = ""]
111    pub start_time: Option<i64>,
112    #[serde(
113        flatten,
114        default,
115        skip_serializing_if = "::std::collections::HashMap::is_empty"
116    )]
117    pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
118}
119#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
120#[doc = "Type of the metric."]
121#[doc = ""]
122pub enum Type {
123    #[serde(rename = "counter")]
124    Counter,
125    #[serde(rename = "derive")]
126    Derive,
127    #[serde(rename = "gauge")]
128    Gauge,
129}
130impl TryFrom<&str> for Type {
131    type Error = String;
132    fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
133        match value {
134            "counter" => Ok(Self::Counter),
135            "derive" => Ok(Self::Derive),
136            "gauge" => Ok(Self::Gauge),
137            v => Err(format!("Unknown variant {v}")),
138        }
139    }
140}