[pdm-devel] [PATCH proxmox-datacenter-manager 20/25] api: add endpoint to trigger metric collection

Lukas Wagner l.wagner at proxmox.com
Tue Feb 11 13:05:36 CET 2025


This one lives under /metric-collection/trigger.
Doing a POST will trigger metric collection for a remote provided in the
'remote' parameter, or all remotes if the parameter is not provided.

Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 server/src/api/metric_collection.rs | 35 +++++++++++++++++++++++++++++
 server/src/api/mod.rs               |  2 ++
 2 files changed, 37 insertions(+)
 create mode 100644 server/src/api/metric_collection.rs

diff --git a/server/src/api/metric_collection.rs b/server/src/api/metric_collection.rs
new file mode 100644
index 0000000..f0a8ea8
--- /dev/null
+++ b/server/src/api/metric_collection.rs
@@ -0,0 +1,35 @@
+use anyhow::Error;
+
+use pdm_api_types::remotes::REMOTE_ID_SCHEMA;
+use proxmox_router::{Router, SubdirMap};
+use proxmox_schema::api;
+use proxmox_sortable_macro::sortable;
+
+pub const ROUTER: Router = Router::new().subdirs(SUBDIRS);
+
+#[sortable]
+const SUBDIRS: SubdirMap = &sorted!([(
+    "trigger",
+    &Router::new().post(&API_METHOD_TRIGGER_METRIC_COLLECTION)
+),]);
+
+#[api(
+    input: {
+        properties: {
+            remote: {
+                schema: REMOTE_ID_SCHEMA,
+                optional: true,
+            },
+        },
+    },
+)]
+/// Trigger metric collection for a given remote.
+pub async fn trigger_metric_collection(remote: Option<String>) -> Result<(), Error> {
+    if let Some(remote) = remote {
+        crate::metric_collection::trigger_metric_collection_for_remote(&remote).await?;
+    } else {
+        crate::metric_collection::trigger_metric_collection().await?;
+    }
+
+    Ok(())
+}
diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs
index 6c4831b..ff875fc 100644
--- a/server/src/api/mod.rs
+++ b/server/src/api/mod.rs
@@ -9,6 +9,7 @@ use proxmox_sortable_macro::sortable;
 
 pub mod access;
 pub mod config;
+pub mod metric_collection;
 pub mod nodes;
 pub mod pbs;
 pub mod pve;
@@ -21,6 +22,7 @@ mod rrd_common;
 const SUBDIRS: SubdirMap = &sorted!([
     ("access", &access::ROUTER),
     ("config", &config::ROUTER),
+    ("metric-collection", &metric_collection::ROUTER),
     ("ping", &Router::new().get(&API_METHOD_PING)),
     ("pve", &pve::ROUTER),
     ("pbs", &pbs::ROUTER),
-- 
2.39.5





More information about the pdm-devel mailing list