[pdm-devel] [RFC datacenter-manager 3/5] server: resources: account for datastores with upwards usage trend

Christian Ebner c.ebner at proxmox.com
Mon Oct 27 15:25:49 CET 2025


Count datastores for which the estimated full date is within 7 days
as uptrend usage. This is in preparation for showing these in the
PBS datastore statistics panel.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 server/src/api/resources.rs | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/server/src/api/resources.rs b/server/src/api/resources.rs
index 586c732..97224f7 100644
--- a/server/src/api/resources.rs
+++ b/server/src/api/resources.rs
@@ -1,6 +1,7 @@
 use std::collections::HashMap;
 use std::str::FromStr;
 use std::sync::{LazyLock, RwLock};
+use std::time::{SystemTime, UNIX_EPOCH};
 
 use anyhow::{bail, format_err, Error};
 use futures::future::join_all;
@@ -14,7 +15,7 @@ use pdm_api_types::resource::{
     FailedRemote, PbsDatastoreResource, PbsNodeResource, PveLxcResource, PveNodeResource,
     PveQemuResource, PveSdnResource, PveStorageResource, RemoteResources, Resource, ResourceType,
     ResourcesStatus, SdnStatus, SdnZoneResource, TopEntities,
-    PBS_DATASTORE_CRITICAL_USAGE_THRESHOLD,
+    PBS_DATASTORE_CRITICAL_USAGE_THRESHOLD, PBS_DATASTORE_FILLUP_THRESHOLD,
 };
 use pdm_api_types::subscription::{
     NodeSubscriptionInfo, RemoteSubscriptionState, RemoteSubscriptions, SubscriptionLevel,
@@ -468,6 +469,20 @@ pub async fn get_status(
                     if r.usage > PBS_DATASTORE_CRITICAL_USAGE_THRESHOLD {
                         *counts.pbs_datastores.critical_usage.get_or_insert_default() += 1;
                     }
+                    if let Some(estimated_full) = r.estimated_full_date {
+                        if let Ok(now) = SystemTime::now().duration_since(UNIX_EPOCH) {
+                            let threshold = now.as_secs() + PBS_DATASTORE_FILLUP_THRESHOLD;
+                            if estimated_full > 0
+                                && (estimated_full as u64) > now.as_secs()
+                                && (estimated_full as u64) < threshold
+                            {
+                                *counts
+                                    .pbs_datastores
+                                    .uptrending_usage
+                                    .get_or_insert_default() += 1;
+                            }
+                        }
+                    }
                     if r.backing_device.is_some() {
                         *counts.pbs_datastores.removable.get_or_insert_default() += 1;
                     }
@@ -1074,6 +1089,7 @@ fn map_pbs_datastore_status(
             maintenance: store_config.maintenance_mode.clone(),
             backing_device: store_config.backing_device.clone(),
             backend_type,
+            estimated_full_date: status.estimated_full_date,
         })
     } else {
         Resource::PbsDatastore(PbsDatastoreResource {
@@ -1082,6 +1098,7 @@ fn map_pbs_datastore_status(
             maxdisk,
             disk,
             usage,
+            estimated_full_date: status.estimated_full_date,
             ..Default::default()
         })
     }
-- 
2.47.3





More information about the pdm-devel mailing list