From e54632653939aa50ab77fa1217b15617acf5fdf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Tue, 12 Nov 2024 11:35:06 +0800 Subject: [PATCH] fix(region): add actual capacity used usage (#21574) --- pkg/compute/models/storages.go | 26 ++++++++++++++++---------- pkg/compute/usages/handler.go | 1 + 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index 18eb237696..8ae191f0e2 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -1288,6 +1288,7 @@ func (manager *SStorageManager) totalCapacityQ( storages.Field("capacity"), storages.Field("reserved"), storages.Field("cmtbound"), + storages.Field("actual_capacity_used"), storages.Field("storage_type"), storages.Field("medium_type"), stmt.Field("used_capacity"), @@ -1311,6 +1312,7 @@ type StorageStat struct { Capacity int Reserved int Cmtbound float32 + ActualCapacityUsed int64 StorageType string MediumType string UsedCapacity int @@ -1324,16 +1326,17 @@ type StorageStat struct { } type StoragesCapacityStat struct { - Capacity int64 - CapacityVirtual float64 - CapacityUsed int64 - CountUsed int - CapacityUnready int64 - CountUnready int - AttachedCapacity int64 - CountAttached int - DetachedCapacity int64 - CountDetached int + Capacity int64 + CapacityVirtual float64 + CapacityUsed int64 + ActualCapacityUsed int64 + CountUsed int + CapacityUnready int64 + CountUnready int + AttachedCapacity int64 + CountAttached int + DetachedCapacity int64 + CountDetached int MediumeCapacity map[string]int64 StorageTypeCapacity map[string]int64 @@ -1355,6 +1358,7 @@ func (manager *SStorageManager) calculateCapacity(q *sqlchemy.SQuery) StoragesCa tCapa int64 = 0 tVCapa float64 = 0 tUsed int64 = 0 + aUsed int64 = 0 cUsed int = 0 tFailed int64 = 0 cFailed int = 0 @@ -1397,6 +1401,7 @@ func (manager *SStorageManager) calculateCapacity(q *sqlchemy.SQuery) StoragesCa tVCapa += float64(stat.Capacity-stat.Reserved) * float64(stat.Cmtbound) mCapaUsed, sCapaUsed = add(mCapaUsed, sCapaUsed, stat.MediumType, stat.StorageType, int64(stat.UsedCapacity)) tUsed += int64(stat.UsedCapacity) + aUsed += int64(stat.ActualCapacityUsed) cUsed += stat.UsedCount tFailed += int64(stat.FailedCapacity) mFailed, sFailed = add(mFailed, sFailed, stat.MediumType, stat.StorageType, int64(stat.FailedCapacity)) @@ -1414,6 +1419,7 @@ func (manager *SStorageManager) calculateCapacity(q *sqlchemy.SQuery) StoragesCa StorageTypeCapacity: sCapa, CapacityVirtual: tVCapa, CapacityUsed: tUsed, + ActualCapacityUsed: aUsed, MediumeCapacityUsed: mCapaUsed, StorageTypeCapacityUsed: sCapaUsed, CountUsed: cUsed, diff --git a/pkg/compute/usages/handler.go b/pkg/compute/usages/handler.go index 5e06418596..891e070e79 100644 --- a/pkg/compute/usages/handler.go +++ b/pkg/compute/usages/handler.go @@ -687,6 +687,7 @@ func StorageUsage( count[fmt.Sprintf("%s.medium_type.%s", sPrefix, m)] = capa } count[fmt.Sprintf("%s.virtual", sPrefix)] = result.CapacityVirtual + count[fmt.Sprintf("%s.actual_capacity_used", sPrefix)] = result.ActualCapacityUsed count[fmt.Sprintf("%s.owner", dPrefix)] = result.CapacityUsed count[fmt.Sprintf("%s.count.owner", dPrefix)] = result.CountUsed count[fmt.Sprintf("%s.unready.owner", dPrefix)] = result.CapacityUnready