github.com/minio/madmin-go/v2@v2.2.1/health-old.go (about) 1 // 2 // Copyright (c) 2015-2022 MinIO, Inc. 3 // 4 // This file is part of MinIO Object Storage stack 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU Affero General Public License as 8 // published by the Free Software Foundation, either version 3 of the 9 // License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU Affero General Public License for more details. 15 // 16 // You should have received a copy of the GNU Affero General Public License 17 // along with this program. If not, see <http://www.gnu.org/licenses/>. 18 // 19 20 package madmin 21 22 import ( 23 "encoding/json" 24 "math/big" 25 "time" 26 27 "github.com/shirou/gopsutil/v3/cpu" 28 diskhw "github.com/shirou/gopsutil/v3/disk" 29 "github.com/shirou/gopsutil/v3/host" 30 "github.com/shirou/gopsutil/v3/mem" 31 "github.com/shirou/gopsutil/v3/process" 32 ) 33 34 // HealthInfoV0 - MinIO cluster's health Info version 0 35 type HealthInfoV0 struct { 36 TimeStamp time.Time `json:"timestamp,omitempty"` 37 Error string `json:"error,omitempty"` 38 Perf PerfInfoV0 `json:"perf,omitempty"` 39 Minio MinioHealthInfoV0 `json:"minio,omitempty"` 40 Sys SysHealthInfo `json:"sys,omitempty"` 41 } 42 43 // HealthInfoV2 - MinIO cluster's health Info version 2 44 type HealthInfoV2 struct { 45 Version string `json:"version"` 46 Error string `json:"error,omitempty"` 47 48 TimeStamp time.Time `json:"timestamp,omitempty"` 49 Sys SysInfo `json:"sys,omitempty"` 50 Perf PerfInfo `json:"perf,omitempty"` 51 Minio MinioHealthInfo `json:"minio,omitempty"` 52 } 53 54 func (info HealthInfoV2) String() string { 55 data, err := json.Marshal(info) 56 if err != nil { 57 panic(err) // This never happens. 58 } 59 return string(data) 60 } 61 62 // JSON returns this structure as JSON formatted string. 63 func (info HealthInfoV2) JSON() string { 64 data, err := json.MarshalIndent(info, " ", " ") 65 if err != nil { 66 panic(err) // This never happens. 67 } 68 return string(data) 69 } 70 71 // GetError - returns error from the cluster health info v2 72 func (info HealthInfoV2) GetError() string { 73 return info.Error 74 } 75 76 // GetStatus - returns status of the cluster health info v2 77 func (info HealthInfoV2) GetStatus() string { 78 if info.Error != "" { 79 return "error" 80 } 81 return "success" 82 } 83 84 // GetTimestamp - returns timestamp from the cluster health info v2 85 func (info HealthInfoV2) GetTimestamp() time.Time { 86 return info.TimeStamp 87 } 88 89 // Latency contains write operation latency in seconds of a disk drive. 90 type Latency struct { 91 Avg float64 `json:"avg"` 92 Max float64 `json:"max"` 93 Min float64 `json:"min"` 94 Percentile50 float64 `json:"percentile_50"` 95 Percentile90 float64 `json:"percentile_90"` 96 Percentile99 float64 `json:"percentile_99"` 97 } 98 99 // Throughput contains write performance in bytes per second of a disk drive. 100 type Throughput struct { 101 Avg uint64 `json:"avg"` 102 Max uint64 `json:"max"` 103 Min uint64 `json:"min"` 104 Percentile50 uint64 `json:"percentile_50"` 105 Percentile90 uint64 `json:"percentile_90"` 106 Percentile99 uint64 `json:"percentile_99"` 107 } 108 109 // DrivePerfInfo contains disk drive's performance information. 110 type DrivePerfInfo struct { 111 Error string `json:"error,omitempty"` 112 113 Path string `json:"path"` 114 Latency Latency `json:"latency,omitempty"` 115 Throughput Throughput `json:"throughput,omitempty"` 116 } 117 118 // DrivePerfInfos contains all disk drive's performance information of a node. 119 type DrivePerfInfos struct { 120 NodeCommon 121 122 SerialPerf []DrivePerfInfo `json:"serial_perf,omitempty"` 123 ParallelPerf []DrivePerfInfo `json:"parallel_perf,omitempty"` 124 } 125 126 // PeerNetPerfInfo contains network performance information of a node. 127 type PeerNetPerfInfo struct { 128 NodeCommon 129 130 Latency Latency `json:"latency,omitempty"` 131 Throughput Throughput `json:"throughput,omitempty"` 132 } 133 134 // NetPerfInfo contains network performance information of a node to other nodes. 135 type NetPerfInfo struct { 136 NodeCommon 137 138 RemotePeers []PeerNetPerfInfo `json:"remote_peers,omitempty"` 139 } 140 141 // PerfInfo - Includes Drive and Net perf info for the entire MinIO cluster 142 type PerfInfo struct { 143 Drives []DrivePerfInfos `json:"drives,omitempty"` 144 Net []NetPerfInfo `json:"net,omitempty"` 145 NetParallel NetPerfInfo `json:"net_parallel,omitempty"` 146 } 147 148 func (info HealthInfoV0) String() string { 149 data, err := json.Marshal(info) 150 if err != nil { 151 panic(err) // This never happens. 152 } 153 return string(data) 154 } 155 156 // JSON returns this structure as JSON formatted string. 157 func (info HealthInfoV0) JSON() string { 158 data, err := json.MarshalIndent(info, " ", " ") 159 if err != nil { 160 panic(err) // This never happens. 161 } 162 return string(data) 163 } 164 165 // SysHealthInfo - Includes hardware and system information of the MinIO cluster 166 type SysHealthInfo struct { 167 CPUInfo []ServerCPUInfo `json:"cpus,omitempty"` 168 DiskHwInfo []ServerDiskHwInfo `json:"drives,omitempty"` 169 OsInfo []ServerOsInfo `json:"osinfos,omitempty"` 170 MemInfo []ServerMemInfo `json:"meminfos,omitempty"` 171 ProcInfo []ServerProcInfo `json:"procinfos,omitempty"` 172 Error string `json:"error,omitempty"` 173 } 174 175 // ServerProcInfo - Includes host process lvl information 176 type ServerProcInfo struct { 177 Addr string `json:"addr"` 178 Processes []SysProcess `json:"processes,omitempty"` 179 Error string `json:"error,omitempty"` 180 } 181 182 // SysProcess - Includes process lvl information about a single process 183 type SysProcess struct { 184 Pid int32 `json:"pid"` 185 Background bool `json:"background,omitempty"` 186 CPUPercent float64 `json:"cpupercent,omitempty"` 187 Children []int32 `json:"children,omitempty"` 188 CmdLine string `json:"cmd,omitempty"` 189 ConnectionCount int `json:"connection_count,omitempty"` 190 CreateTime int64 `json:"createtime,omitempty"` 191 Cwd string `json:"cwd,omitempty"` 192 Exe string `json:"exe,omitempty"` 193 Gids []int32 `json:"gids,omitempty"` 194 IOCounters *process.IOCountersStat `json:"iocounters,omitempty"` 195 IsRunning bool `json:"isrunning,omitempty"` 196 MemInfo *process.MemoryInfoStat `json:"meminfo,omitempty"` 197 MemMaps *[]process.MemoryMapsStat `json:"memmaps,omitempty"` 198 MemPercent float32 `json:"mempercent,omitempty"` 199 Name string `json:"name,omitempty"` 200 Nice int32 `json:"nice,omitempty"` 201 NumCtxSwitches *process.NumCtxSwitchesStat `json:"numctxswitches,omitempty"` 202 NumFds int32 `json:"numfds,omitempty"` 203 NumThreads int32 `json:"numthreads,omitempty"` 204 PageFaults *process.PageFaultsStat `json:"pagefaults,omitempty"` 205 Parent int32 `json:"parent,omitempty"` 206 Ppid int32 `json:"ppid,omitempty"` 207 Status string `json:"status,omitempty"` 208 Tgid int32 `json:"tgid,omitempty"` 209 Times *cpu.TimesStat `json:"cputimes,omitempty"` 210 Uids []int32 `json:"uids,omitempty"` 211 Username string `json:"username,omitempty"` 212 } 213 214 // GetOwner - returns owner of the process 215 func (sp SysProcess) GetOwner() string { 216 return sp.Username 217 } 218 219 // ServerMemInfo - Includes host virtual and swap mem information 220 type ServerMemInfo struct { 221 Addr string `json:"addr"` 222 SwapMem *mem.SwapMemoryStat `json:"swap,omitempty"` 223 VirtualMem *mem.VirtualMemoryStat `json:"virtualmem,omitempty"` 224 Error string `json:"error,omitempty"` 225 } 226 227 // ServerOsInfo - Includes host os information 228 type ServerOsInfo struct { 229 Addr string `json:"addr"` 230 Info *host.InfoStat `json:"info,omitempty"` 231 Sensors []host.TemperatureStat `json:"sensors,omitempty"` 232 Users []host.UserStat `json:"users,omitempty"` 233 Error string `json:"error,omitempty"` 234 } 235 236 // ServerCPUInfo - Includes cpu and timer stats of each node of the MinIO cluster 237 type ServerCPUInfo struct { 238 Addr string `json:"addr"` 239 CPUStat []cpu.InfoStat `json:"cpu,omitempty"` 240 TimeStat []cpu.TimesStat `json:"time,omitempty"` 241 Error string `json:"error,omitempty"` 242 } 243 244 // MinioHealthInfoV0 - Includes MinIO confifuration information 245 type MinioHealthInfoV0 struct { 246 Info InfoMessage `json:"info,omitempty"` 247 Config interface{} `json:"config,omitempty"` 248 Error string `json:"error,omitempty"` 249 } 250 251 // ServerDiskHwInfo - Includes usage counters, disk counters and partitions 252 type ServerDiskHwInfo struct { 253 Addr string `json:"addr"` 254 Usage []*diskhw.UsageStat `json:"usages,omitempty"` 255 Partitions []PartitionStat `json:"partitions,omitempty"` 256 Counters map[string]diskhw.IOCountersStat `json:"counters,omitempty"` 257 Error string `json:"error,omitempty"` 258 } 259 260 // GetTotalCapacity gets the total capacity a server holds. 261 func (s *ServerDiskHwInfo) GetTotalCapacity() (capacity uint64) { 262 for _, u := range s.Usage { 263 capacity += u.Total 264 } 265 return 266 } 267 268 // GetTotalFreeCapacity gets the total capacity that is free. 269 func (s *ServerDiskHwInfo) GetTotalFreeCapacity() (capacity uint64) { 270 for _, u := range s.Usage { 271 capacity += u.Free 272 } 273 return 274 } 275 276 // GetTotalUsedCapacity gets the total capacity used. 277 func (s *ServerDiskHwInfo) GetTotalUsedCapacity() (capacity uint64) { 278 for _, u := range s.Usage { 279 capacity += u.Used 280 } 281 return 282 } 283 284 // SmartInfo contains S.M.A.R.T data about the drive 285 type SmartInfo struct { 286 Device string `json:"device"` 287 Scsi *SmartScsiInfo `json:"scsi,omitempty"` 288 Nvme *SmartNvmeInfo `json:"nvme,omitempty"` 289 Ata *SmartAtaInfo `json:"ata,omitempty"` 290 } 291 292 // SmartNvmeInfo contains NVMe drive info 293 type SmartNvmeInfo struct { 294 SerialNum string `json:"serialNum,omitempty"` 295 VendorID string `json:"vendorId,omitempty"` 296 FirmwareVersion string `json:"firmwareVersion,omitempty"` 297 ModelNum string `json:"modelNum,omitempty"` 298 SpareAvailable string `json:"spareAvailable,omitempty"` 299 SpareThreshold string `json:"spareThreshold,omitempty"` 300 Temperature string `json:"temperature,omitempty"` 301 CriticalWarning string `json:"criticalWarning,omitempty"` 302 303 MaxDataTransferPages int `json:"maxDataTransferPages,omitempty"` 304 ControllerBusyTime *big.Int `json:"controllerBusyTime,omitempty"` 305 PowerOnHours *big.Int `json:"powerOnHours,omitempty"` 306 PowerCycles *big.Int `json:"powerCycles,omitempty"` 307 UnsafeShutdowns *big.Int `json:"unsafeShutdowns,omitempty"` 308 MediaAndDataIntegrityErrors *big.Int `json:"mediaAndDataIntgerityErrors,omitempty"` 309 DataUnitsReadBytes *big.Int `json:"dataUnitsReadBytes,omitempty"` 310 DataUnitsWrittenBytes *big.Int `json:"dataUnitsWrittenBytes,omitempty"` 311 HostReadCommands *big.Int `json:"hostReadCommands,omitempty"` 312 HostWriteCommands *big.Int `json:"hostWriteCommands,omitempty"` 313 } 314 315 // SmartScsiInfo contains SCSI drive Info 316 type SmartScsiInfo struct { 317 CapacityBytes int64 `json:"scsiCapacityBytes,omitempty"` 318 ModeSenseBuf string `json:"scsiModeSenseBuf,omitempty"` 319 RespLen int64 `json:"scsirespLen,omitempty"` 320 BdLen int64 `json:"scsiBdLen,omitempty"` 321 Offset int64 `json:"scsiOffset,omitempty"` 322 RPM int64 `json:"sciRpm,omitempty"` 323 } 324 325 // SmartAtaInfo contains ATA drive info 326 type SmartAtaInfo struct { 327 LUWWNDeviceID string `json:"scsiLuWWNDeviceID,omitempty"` 328 SerialNum string `json:"serialNum,omitempty"` 329 ModelNum string `json:"modelNum,omitempty"` 330 FirmwareRevision string `json:"firmwareRevision,omitempty"` 331 RotationRate string `json:"RotationRate,omitempty"` 332 ATAMajorVersion string `json:"MajorVersion,omitempty"` 333 ATAMinorVersion string `json:"MinorVersion,omitempty"` 334 SmartSupportAvailable bool `json:"smartSupportAvailable,omitempty"` 335 SmartSupportEnabled bool `json:"smartSupportEnabled,omitempty"` 336 ErrorLog string `json:"smartErrorLog,omitempty"` 337 Transport string `json:"transport,omitempty"` 338 } 339 340 // PartitionStat - includes data from both shirou/psutil.diskHw.PartitionStat as well as SMART data 341 type PartitionStat struct { 342 Device string `json:"device"` 343 Mountpoint string `json:"mountpoint,omitempty"` 344 Fstype string `json:"fstype,omitempty"` 345 Opts string `json:"opts,omitempty"` 346 SmartInfo SmartInfo `json:"smartInfo,omitempty"` 347 } 348 349 // PerfInfoV0 - Includes Drive and Net perf info for the entire MinIO cluster 350 type PerfInfoV0 struct { 351 DriveInfo []ServerDrivesInfo `json:"drives,omitempty"` 352 Net []ServerNetHealthInfo `json:"net,omitempty"` 353 NetParallel ServerNetHealthInfo `json:"net_parallel,omitempty"` 354 Error string `json:"error,omitempty"` 355 } 356 357 // ServerDrivesInfo - Drive info about all drives in a single MinIO node 358 type ServerDrivesInfo struct { 359 Addr string `json:"addr"` 360 Serial []DrivePerfInfoV0 `json:"serial,omitempty"` // Drive perf info collected one drive at a time 361 Parallel []DrivePerfInfoV0 `json:"parallel,omitempty"` // Drive perf info collected in parallel 362 Error string `json:"error,omitempty"` 363 } 364 365 // DiskLatency holds latency information for write operations to the drive 366 type DiskLatency struct { 367 Avg float64 `json:"avg_secs,omitempty"` 368 Percentile50 float64 `json:"percentile50_secs,omitempty"` 369 Percentile90 float64 `json:"percentile90_secs,omitempty"` 370 Percentile99 float64 `json:"percentile99_secs,omitempty"` 371 Min float64 `json:"min_secs,omitempty"` 372 Max float64 `json:"max_secs,omitempty"` 373 } 374 375 // DiskThroughput holds throughput information for write operations to the drive 376 type DiskThroughput struct { 377 Avg float64 `json:"avg_bytes_per_sec,omitempty"` 378 Percentile50 float64 `json:"percentile50_bytes_per_sec,omitempty"` 379 Percentile90 float64 `json:"percentile90_bytes_per_sec,omitempty"` 380 Percentile99 float64 `json:"percentile99_bytes_per_sec,omitempty"` 381 Min float64 `json:"min_bytes_per_sec,omitempty"` 382 Max float64 `json:"max_bytes_per_sec,omitempty"` 383 } 384 385 // DrivePerfInfoV0 - Stats about a single drive in a MinIO node 386 type DrivePerfInfoV0 struct { 387 Path string `json:"endpoint"` 388 Latency DiskLatency `json:"latency,omitempty"` 389 Throughput DiskThroughput `json:"throughput,omitempty"` 390 Error string `json:"error,omitempty"` 391 } 392 393 // ServerNetHealthInfo - Network health info about a single MinIO node 394 type ServerNetHealthInfo struct { 395 Addr string `json:"addr"` 396 Net []NetPerfInfoV0 `json:"net,omitempty"` 397 Error string `json:"error,omitempty"` 398 } 399 400 // NetLatency holds latency information for read/write operations to the drive 401 type NetLatency struct { 402 Avg float64 `json:"avg_secs,omitempty"` 403 Percentile50 float64 `json:"percentile50_secs,omitempty"` 404 Percentile90 float64 `json:"percentile90_secs,omitempty"` 405 Percentile99 float64 `json:"percentile99_secs,omitempty"` 406 Min float64 `json:"min_secs,omitempty"` 407 Max float64 `json:"max_secs,omitempty"` 408 } 409 410 // NetThroughput holds throughput information for read/write operations to the drive 411 type NetThroughput struct { 412 Avg float64 `json:"avg_bytes_per_sec,omitempty"` 413 Percentile50 float64 `json:"percentile50_bytes_per_sec,omitempty"` 414 Percentile90 float64 `json:"percentile90_bytes_per_sec,omitempty"` 415 Percentile99 float64 `json:"percentile99_bytes_per_sec,omitempty"` 416 Min float64 `json:"min_bytes_per_sec,omitempty"` 417 Max float64 `json:"max_bytes_per_sec,omitempty"` 418 } 419 420 // NetPerfInfoV0 - one-to-one network connectivity Stats between 2 MinIO nodes 421 type NetPerfInfoV0 struct { 422 Addr string `json:"remote"` 423 Latency NetLatency `json:"latency,omitempty"` 424 Throughput NetThroughput `json:"throughput,omitempty"` 425 Error string `json:"error,omitempty"` 426 }