[pdm-devel] [PATCH proxmox-datacenter-manager v2 24/28] pdm-client: add metric collection API methods

Lukas Wagner l.wagner at proxmox.com
Fri Feb 14 14:06:49 CET 2025


This adds bindings for collection settings, trigger, and status APIs.

Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 lib/pdm-client/src/lib.rs | 87 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/lib/pdm-client/src/lib.rs b/lib/pdm-client/src/lib.rs
index a41b82ca..70880576 100644
--- a/lib/pdm-client/src/lib.rs
+++ b/lib/pdm-client/src/lib.rs
@@ -320,6 +320,93 @@ impl<T: HttpApiClient> PdmClient<T> {
             .ok_or_else(|| Error::BadApi("api returned no webauthn entry id".to_string(), None))
     }
 
+    /// Get global metric collection settings.
+    pub async fn get_metric_collection_settings(
+        &self,
+    ) -> Result<pdm_api_types::CollectionSettings, Error> {
+        let path = "/api2/extjs/config/metric-collection/default";
+        Ok(self.0.get(path).await?.expect_json()?.data)
+    }
+
+    /// Update global metric collection settings.
+    pub async fn update_metric_collection_settings(
+        &self,
+        updater: pdm_api_types::CollectionSettingsUpdater,
+        delete: Option<Vec<pdm_api_types::DeletableCollectionSettingsProperty>>,
+    ) -> Result<(), Error> {
+        let path = "/api2/extjs/config/metric-collection/default";
+
+        #[derive(Serialize)]
+        struct UpdateSettings<'a> {
+            updater: &'a pdm_api_types::CollectionSettingsUpdater,
+            #[serde(skip_serializing_if = "Option::is_none")]
+            delete: Option<Vec<pdm_api_types::DeletableCollectionSettingsProperty>>,
+        }
+
+        let params = UpdateSettings {
+            updater: &updater,
+            delete,
+        };
+        self.0.put(path, &params).await?.nodata()?;
+        Ok(())
+    }
+
+    /// Trigger metric collection for a single remote or for all remotes, if no remote is provided.
+    pub async fn trigger_metric_collection(
+        &self,
+        remote: Option<&str>,
+    ) -> Result<(), proxmox_client::Error> {
+        let path = "/api2/extjs/metric-collection/trigger";
+
+        #[derive(Serialize)]
+        struct TriggerParams<'a> {
+            #[serde(skip_serializing_if = "Option::is_none")]
+            remote: Option<&'a str>,
+        }
+
+        self.0
+            .post(path, &TriggerParams { remote })
+            .await?
+            .nodata()?;
+
+        Ok(())
+    }
+
+    /// Get global metric collection status.
+    pub async fn get_metric_collection_status(
+        &self,
+    ) -> Result<Vec<pdm_api_types::MetricCollectionStatus>, Error> {
+        let path = "/api2/extjs/metric-collection/status";
+        Ok(self.0.get(path).await?.expect_json()?.data)
+    }
+
+    /// Get global metric collection status.
+    pub async fn get_metric_collection_rrddata(
+        &self,
+        mode: RrdMode,
+        timeframe: RrdTimeframe,
+    ) -> Result<pdm_api_types::rrddata::FullCollectionDatapoint, Error> {
+        let mut path = "/api2/extjs/metric-collection/rrddata".to_string();
+        let mut sep = '?';
+        add_query_arg(&mut path, &mut sep, "cf", &Some(mode));
+        add_query_arg(&mut path, &mut sep, "timeframe", &Some(timeframe));
+        Ok(self.0.get(&path).await?.expect_json()?.data)
+    }
+
+    /// Get per-remote metric collection status.
+    pub async fn get_per_remote_metric_collection_rrddata(
+        &self,
+        remote: &str,
+        mode: RrdMode,
+        timeframe: RrdTimeframe,
+    ) -> Result<pdm_api_types::rrddata::RemoteCollectionDatapoint, Error> {
+        let mut path = format!("/api2/extjs/remotes/{remote}/metric-collection-rrddata");
+        let mut sep = '?';
+        add_query_arg(&mut path, &mut sep, "cf", &Some(mode));
+        add_query_arg(&mut path, &mut sep, "timeframe", &Some(timeframe));
+        Ok(self.0.get(&path).await?.expect_json()?.data)
+    }
+
     pub async fn pve_list_nodes(
         &self,
         remote: &str,
-- 
2.39.5





More information about the pdm-devel mailing list