github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/metrics-v3-cluster-health.go (about) 1 // Copyright (c) 2015-2024 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import "context" 21 22 const ( 23 healthDrivesOfflineCount = "drives_offline_count" 24 healthDrivesOnlineCount = "drives_online_count" 25 healthDrivesCount = "drives_count" 26 ) 27 28 var ( 29 healthDrivesOfflineCountMD = NewGaugeMD(healthDrivesOfflineCount, 30 "Count of offline drives in the cluster") 31 healthDrivesOnlineCountMD = NewGaugeMD(healthDrivesOnlineCount, 32 "Count of online drives in the cluster") 33 healthDrivesCountMD = NewGaugeMD(healthDrivesCount, 34 "Count of all drives in the cluster") 35 ) 36 37 // loadClusterHealthDriveMetrics - `MetricsLoaderFn` for cluster storage drive metrics 38 // such as online, offline and total drives. 39 func loadClusterHealthDriveMetrics(ctx context.Context, m MetricValues, 40 c *metricsCache, 41 ) error { 42 clusterDriveMetrics, _ := c.clusterDriveMetrics.Get() 43 44 m.Set(healthDrivesOfflineCount, float64(clusterDriveMetrics.offlineDrives)) 45 m.Set(healthDrivesOnlineCount, float64(clusterDriveMetrics.onlineDrives)) 46 m.Set(healthDrivesCount, float64(clusterDriveMetrics.totalDrives)) 47 48 return nil 49 } 50 51 const ( 52 healthNodesOfflineCount = "nodes_offline_count" 53 healthNodesOnlineCount = "nodes_online_count" 54 ) 55 56 var ( 57 healthNodesOfflineCountMD = NewGaugeMD(healthNodesOfflineCount, 58 "Count of offline nodes in the cluster") 59 healthNodesOnlineCountMD = NewGaugeMD(healthNodesOnlineCount, 60 "Count of online nodes in the cluster") 61 ) 62 63 // loadClusterHealthNodeMetrics - `MetricsLoaderFn` for cluster health node 64 // metrics. 65 func loadClusterHealthNodeMetrics(ctx context.Context, m MetricValues, 66 c *metricsCache, 67 ) error { 68 nodesUpDown, _ := c.nodesUpDown.Get() 69 70 m.Set(healthNodesOfflineCount, float64(nodesUpDown.Offline)) 71 m.Set(healthNodesOnlineCount, float64(nodesUpDown.Online)) 72 73 return nil 74 } 75 76 const ( 77 healthCapacityRawTotalBytes = "capacity_raw_total_bytes" 78 healthCapacityRawFreeBytes = "capacity_raw_free_bytes" 79 healthCapacityUsableTotalBytes = "capacity_usable_total_bytes" 80 healthCapacityUsableFreeBytes = "capacity_usable_free_bytes" 81 ) 82 83 var ( 84 healthCapacityRawTotalBytesMD = NewGaugeMD(healthCapacityRawTotalBytes, 85 "Total cluster raw storage capacity in bytes") 86 healthCapacityRawFreeBytesMD = NewGaugeMD(healthCapacityRawFreeBytes, 87 "Total cluster raw storage free in bytes") 88 healthCapacityUsableTotalBytesMD = NewGaugeMD(healthCapacityUsableTotalBytes, 89 "Total cluster usable storage capacity in bytes") 90 healthCapacityUsableFreeBytesMD = NewGaugeMD(healthCapacityUsableFreeBytes, 91 "Total cluster usable storage free in bytes") 92 ) 93 94 // loadClusterHealthCapacityMetrics - `MetricsLoaderFn` for cluster storage 95 // capacity metrics. 96 func loadClusterHealthCapacityMetrics(ctx context.Context, m MetricValues, 97 c *metricsCache, 98 ) error { 99 clusterDriveMetrics, _ := c.clusterDriveMetrics.Get() 100 101 storageInfo := clusterDriveMetrics.storageInfo 102 103 m.Set(healthCapacityRawTotalBytes, float64(GetTotalCapacity(storageInfo.Disks))) 104 m.Set(healthCapacityRawFreeBytes, float64(GetTotalCapacityFree(storageInfo.Disks))) 105 m.Set(healthCapacityUsableTotalBytes, float64(GetTotalUsableCapacity(storageInfo.Disks, storageInfo))) 106 m.Set(healthCapacityUsableFreeBytes, float64(GetTotalUsableCapacityFree(storageInfo.Disks, storageInfo))) 107 108 return nil 109 }