[pdm-devel] [PATCH proxmox-datacenter-manager v6 05/23] metric collection: skip if last_collection < MIN_COLLECTION_INTERVAL

Lukas Wagner l.wagner at proxmox.com
Thu Aug 21 11:53:01 CEST 2025


It makes sense to limit the collection frequency per remote, especially
since we will have the ability to trigger collection manually.

Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
Reviewed-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 server/src/metric_collection/collection_task.rs | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/server/src/metric_collection/collection_task.rs b/server/src/metric_collection/collection_task.rs
index c771f4d5..27e097f7 100644
--- a/server/src/metric_collection/collection_task.rs
+++ b/server/src/metric_collection/collection_task.rs
@@ -31,6 +31,8 @@ pub const MAX_CONCURRENT_CONNECTIONS: usize = 20;
 
 /// Default metric collection interval.
 pub const DEFAULT_COLLECTION_INTERVAL: u64 = 600;
+/// Minimum metric collection interval.
+pub const MIN_COLLECTION_INTERVAL: u64 = 10;
 
 /// Control messages for the metric collection task.
 pub(super) enum ControlMsg {
@@ -145,6 +147,7 @@ impl MetricCollectionTask {
     ) {
         let semaphore = Arc::new(Semaphore::new(MAX_CONCURRENT_CONNECTIONS));
         let mut handles = Vec::new();
+        let now = proxmox_time::epoch_i64();
 
         for remote_name in remotes_to_fetch {
             let status = self
@@ -153,6 +156,13 @@ impl MetricCollectionTask {
                 .cloned()
                 .unwrap_or_default();
 
+            if now - status.last_collection.unwrap_or(0) < MIN_COLLECTION_INTERVAL as i64 {
+                log::debug!(
+                    "skipping metric collection for remote '{remote_name}' - data is recent enough"
+                );
+                continue;
+            }
+
             // unwrap is okay here, acquire_* will only fail if `close` has been
             // called on the semaphore.
             let permit = Arc::clone(&semaphore).acquire_owned().await.unwrap();
-- 
2.47.2





More information about the pdm-devel mailing list