From 67a8f37df0ebd1c263278e1ccdd0dd53ce020f90 Mon Sep 17 00:00:00 2001 From: Ritesh H Shukla Date: Thu, 4 Feb 2021 12:26:58 -0800 Subject: [PATCH] fix: disk usage capacity metric reporting (#11435) --- cmd/metrics-v2.go | 10 +++++----- cmd/metrics.go | 8 ++++---- cmd/notification-summary.go | 25 ++++++++++++------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/cmd/metrics-v2.go b/cmd/metrics-v2.go index 027e3f937..083dae60a 100644 --- a/cmd/metrics-v2.go +++ b/cmd/metrics-v2.go @@ -387,7 +387,7 @@ func getS3RequestsInFlightMD() MetricDescription { Subsystem: requestsSubsystem, Name: inflightTotal, Help: "Total number of S3 requests currently in flight.", - Type: counterMetric, + Type: gaugeMetric, } } func getS3RequestsTotalMD() MetricDescription { @@ -1106,23 +1106,23 @@ func getClusterStorageMetrics() MetricsGroup { metrics.Metrics = append(metrics.Metrics, Metric{ Description: getClusterCapacityTotalBytesMD(), - Value: float64(GetTotalCapacity(ctx)), + Value: float64(GetTotalCapacity(storageInfo.Disks)), }) metrics.Metrics = append(metrics.Metrics, Metric{ Description: getClusterCapacityFreeBytesMD(), - Value: float64(GetTotalCapacityFree(ctx)), + Value: float64(GetTotalCapacityFree(storageInfo.Disks)), }) s, _ := objLayer.StorageInfo(GlobalContext) metrics.Metrics = append(metrics.Metrics, Metric{ Description: getClusterCapacityUsageBytesMD(), - Value: GetTotalUsableCapacity(ctx, s), + Value: GetTotalUsableCapacity(storageInfo.Disks, s), }) metrics.Metrics = append(metrics.Metrics, Metric{ Description: getClusterCapacityUsageFreeBytesMD(), - Value: GetTotalUsableCapacityFree(ctx, s), + Value: GetTotalUsableCapacityFree(storageInfo.Disks, s), }) metrics.Metrics = append(metrics.Metrics, Metric{ diff --git a/cmd/metrics.go b/cmd/metrics.go index 0606f7d20..285e162ce 100644 --- a/cmd/metrics.go +++ b/cmd/metrics.go @@ -535,7 +535,7 @@ func storageMetricsPrometheus(ch chan<- prometheus.Metric) { "Total capacity online in the cluster", nil, nil), prometheus.GaugeValue, - float64(GetTotalCapacity(GlobalContext)), + float64(GetTotalCapacity(server.Disks)), ) // Report total capacity free @@ -545,7 +545,7 @@ func storageMetricsPrometheus(ch chan<- prometheus.Metric) { "Total free capacity online in the cluster", nil, nil), prometheus.GaugeValue, - float64(GetTotalCapacityFree(GlobalContext)), + float64(GetTotalCapacityFree(server.Disks)), ) s, _ := objLayer.StorageInfo(GlobalContext) @@ -556,7 +556,7 @@ func storageMetricsPrometheus(ch chan<- prometheus.Metric) { "Total usable capacity online in the cluster", nil, nil), prometheus.GaugeValue, - GetTotalUsableCapacity(GlobalContext, s), + GetTotalUsableCapacity(server.Disks, s), ) // Report total usable capacity free ch <- prometheus.MustNewConstMetric( @@ -565,7 +565,7 @@ func storageMetricsPrometheus(ch chan<- prometheus.Metric) { "Total free usable capacity online in the cluster", nil, nil), prometheus.GaugeValue, - GetTotalUsableCapacityFree(GlobalContext, s), + GetTotalUsableCapacityFree(server.Disks, s), ) // MinIO Offline Disks per node diff --git a/cmd/notification-summary.go b/cmd/notification-summary.go index bb9c6f927..fceafa891 100644 --- a/cmd/notification-summary.go +++ b/cmd/notification-summary.go @@ -18,22 +18,22 @@ package cmd import ( - "context" + "github.com/minio/minio/pkg/madmin" ) // GetTotalCapacity gets the total capacity in the cluster. -func GetTotalCapacity(ctx context.Context) (capacity uint64) { - d := globalNotificationSys.DiskHwInfo(ctx) - for _, s := range d { - capacity += s.GetTotalCapacity() +func GetTotalCapacity(diskInfo []madmin.Disk) (capacity uint64) { + + for _, disk := range diskInfo { + capacity += disk.TotalSpace } return } // GetTotalUsableCapacity gets the total usable capacity in the cluster. // This value is not an accurate representation of total usable in a multi-tenant deployment. -func GetTotalUsableCapacity(ctx context.Context, s StorageInfo) (capacity float64) { - raw := GetTotalCapacity(ctx) +func GetTotalUsableCapacity(diskInfo []madmin.Disk, s StorageInfo) (capacity float64) { + raw := GetTotalCapacity(diskInfo) var approxDataBlocks float64 var actualDisks float64 for _, scData := range s.Backend.StandardSCData { @@ -45,18 +45,17 @@ func GetTotalUsableCapacity(ctx context.Context, s StorageInfo) (capacity float6 } // GetTotalCapacityFree gets the total capacity free in the cluster. -func GetTotalCapacityFree(ctx context.Context) (capacity uint64) { - d := globalNotificationSys.DiskHwInfo(ctx) - for _, s := range d { - capacity += s.GetTotalFreeCapacity() +func GetTotalCapacityFree(diskInfo []madmin.Disk) (capacity uint64) { + for _, d := range diskInfo { + capacity += d.AvailableSpace } return } // GetTotalUsableCapacityFree gets the total usable capacity free in the cluster. // This value is not an accurate representation of total free in a multi-tenant deployment. -func GetTotalUsableCapacityFree(ctx context.Context, s StorageInfo) (capacity float64) { - raw := GetTotalCapacityFree(ctx) +func GetTotalUsableCapacityFree(diskInfo []madmin.Disk, s StorageInfo) (capacity float64) { + raw := GetTotalCapacityFree(diskInfo) var approxDataBlocks float64 var actualDisks float64 for _, scData := range s.Backend.StandardSCData {