github.com/minio/madmin-go@v1.7.5/health-old.go (about)

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