Re: [PATCH datacenter-manager 1/4] api: return global cpu/memory/storage statistics

Dominik Csapak
2026-03-26T07:59:05Z

On 3/25/26 5:48 PM, Thomas Lamprecht wrote:
> Am 23.03.26 um 12:06 schrieb Dominik Csapak:
>> Global CPU/memory/storage usage (per remote type) is useful and
>> interesting from an administration POV. Calculate and return these so
>> we can use them on the dashboards.
>>
>> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
>> ---
>> lib/pdm-api-types/src/lib.rs | 2 +-
>> lib/pdm-api-types/src/resource.rs | 27 +++++++++++++
>> server/src/api/resources.rs | 65 ++++++++++++++++++++++++-------
>> 3 files changed, 80 insertions(+), 14 deletions(-)
>>
>> diff --git a/lib/pdm-api-types/src/lib.rs b/lib/pdm-api-types/src/lib.rs
>> index d4cc7ef0..9bccd50f 100644
>> --- a/lib/pdm-api-types/src/lib.rs
>> +++ b/lib/pdm-api-types/src/lib.rs
>> @@ -191,7 +191,7 @@ pub const PVE_STORAGE_ID_SCHEMA: Schema = StringSchema::new("Storage ID.")
>> // Complex type definitions
>>
>> #[api()]
>> -#[derive(Default, Serialize, Deserialize)]
>> +#[derive(Default, Serialize, Deserialize, PartialEq, Clone)]
>> /// Storage space usage information.
>> pub struct StorageStatus {
>> /// Total space (bytes).
>> diff --git a/lib/pdm-api-types/src/resource.rs b/lib/pdm-api-types/src/resource.rs
>> index d2db3b5a..1f74e09c 100644
>> --- a/lib/pdm-api-types/src/resource.rs
>> +++ b/lib/pdm-api-types/src/resource.rs
>
>> @@ -666,6 +668,18 @@ pub struct SdnZoneCount {
>> pub unknown: u64,
>> }
>>
>> +#[api]
>> +#[derive(Default, Serialize, Deserialize, Clone, PartialEq)]
>> +/// Statistics for CPU utilization
>> +pub struct CpuStatistics {
>> + /// Amount of threads utilized
>> + pub used: f64,
>> + /// Amount of physically available cpu threads
>> + pub max: f64,
>> + /// Currently allocated cores of running guests (only on PVE)
>> + pub allocated: Option<f64>,
>> +}
>> +
>> #[api(
>> properties: {
>> "failed_remotes_list": {
>> @@ -697,6 +711,19 @@ pub struct ResourcesStatus {
>> pub pbs_nodes: NodeStatusCount,
>> /// Status of PBS Datastores
>> pub pbs_datastores: PbsDatastoreStatusCount,
>> + /// Combined CPU statistics for all PVE remotes
>> + pub pve_cpu_stats: CpuStatistics,
>> + /// Combined CPU statistics for all PBS remotes
>> + pub pbs_cpu_stats: CpuStatistics,
>> + /// Combined Memory statistics for all PVE remotes
>> + pub pve_memory_stats: StorageStatus,
>> + /// Combined Memory statistics for all PBS remotes
>> + pub pbs_memory_stats: StorageStatus,
>
> should above two memory fields also use a type named MemoryStatus or the
> like, or is this reused because the fields are basically the same anyway?
> A type alias might still make sense to have in the latter case for more
> clarity that this is on purpose and nothing against dedicated types even
> if they got the same fields, as they refer to different things nonetheless,
> as e.g. a hypothetical Display impl would likely differ (IEC vs SI units).

I just reused it because of the same fields, but having a
different struct makes yeah.

>
>> + /// Combined Storage statistics for all PVE remotes (shared storages are only counted once per
>> + /// remote).
>> + pub pve_storage_stats: StorageStatus,
>> + /// Combined Storage statistics for all PBS remotes
>> + pub pbs_storage_stats: StorageStatus,
>> /// List of the failed remotes including type and error
>> #[serde(default, skip_serializing_if = "Vec::is_empty")]
>> pub failed_remotes_list: Vec<FailedRemote>,
>