2020-10-04 13:18:46 -04:00
|
|
|
// +build linux
|
2020-03-27 00:07:39 -04:00
|
|
|
|
2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-03-27 00:07:39 -04:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-02-05 15:37:15 -05:00
|
|
|
"fmt"
|
2020-05-18 12:59:45 -04:00
|
|
|
"net/http"
|
2020-03-27 00:07:39 -04:00
|
|
|
"strings"
|
|
|
|
|
2021-05-06 11:52:02 -04:00
|
|
|
"github.com/minio/madmin-go"
|
2020-10-04 13:18:46 -04:00
|
|
|
"github.com/minio/minio/pkg/smart"
|
2021-03-01 03:15:46 -05:00
|
|
|
diskhw "github.com/shirou/gopsutil/v3/disk"
|
|
|
|
"github.com/shirou/gopsutil/v3/host"
|
2020-03-27 00:07:39 -04:00
|
|
|
)
|
|
|
|
|
2020-11-20 15:52:53 -05:00
|
|
|
func getLocalOsInfo(ctx context.Context, r *http.Request) madmin.ServerOsInfo {
|
2020-07-01 13:57:23 -04:00
|
|
|
addr := r.Host
|
|
|
|
if globalIsDistErasure {
|
2021-03-26 14:37:58 -04:00
|
|
|
addr = globalLocalNodeName
|
2020-07-01 13:57:23 -04:00
|
|
|
}
|
|
|
|
|
2021-02-12 20:57:57 -05:00
|
|
|
srvrOsInfo := madmin.ServerOsInfo{Addr: addr}
|
|
|
|
var err error
|
|
|
|
|
|
|
|
srvrOsInfo.Info, err = host.InfoWithContext(ctx)
|
2020-07-01 13:57:23 -04:00
|
|
|
if err != nil {
|
2020-11-20 15:52:53 -05:00
|
|
|
return madmin.ServerOsInfo{
|
2020-07-01 13:57:23 -04:00
|
|
|
Addr: addr,
|
2021-02-05 15:37:15 -05:00
|
|
|
Error: fmt.Sprintf("info: %v", err),
|
2020-07-01 13:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 20:57:57 -05:00
|
|
|
srvrOsInfo.Sensors, err = host.SensorsTemperaturesWithContext(ctx)
|
2020-07-01 13:57:23 -04:00
|
|
|
if err != nil {
|
2021-02-12 20:57:57 -05:00
|
|
|
// Set error only when it's not of WARNINGS type
|
|
|
|
if _, isWarning := err.(*host.Warnings); !isWarning {
|
|
|
|
srvrOsInfo.Error = fmt.Sprintf("sensors-temp: %v", err)
|
2020-07-01 13:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore user err, as it cannot be obtained reliably inside containers
|
2021-02-12 20:57:57 -05:00
|
|
|
srvrOsInfo.Users, _ = host.UsersWithContext(ctx)
|
2020-07-01 13:57:23 -04:00
|
|
|
|
2021-02-12 20:57:57 -05:00
|
|
|
return srvrOsInfo
|
2020-07-01 13:57:23 -04:00
|
|
|
}
|
|
|
|
|
2020-11-20 15:52:53 -05:00
|
|
|
func getLocalDiskHwInfo(ctx context.Context, r *http.Request) madmin.ServerDiskHwInfo {
|
2020-05-18 12:59:45 -04:00
|
|
|
addr := r.Host
|
2020-06-12 23:04:01 -04:00
|
|
|
if globalIsDistErasure {
|
2021-03-26 14:37:58 -04:00
|
|
|
addr = globalLocalNodeName
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
|
2020-10-04 13:18:46 -04:00
|
|
|
parts, err := diskhw.PartitionsWithContext(ctx, true)
|
2020-03-27 00:07:39 -04:00
|
|
|
if err != nil {
|
2020-11-20 15:52:53 -05:00
|
|
|
return madmin.ServerDiskHwInfo{
|
2020-03-27 00:07:39 -04:00
|
|
|
Addr: addr,
|
2021-02-05 15:37:15 -05:00
|
|
|
Error: fmt.Sprintf("partitions: %v", err),
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drives := []string{}
|
|
|
|
paths := []string{}
|
2020-10-04 13:18:46 -04:00
|
|
|
partitions := []madmin.PartitionStat{}
|
|
|
|
|
|
|
|
for _, part := range parts {
|
|
|
|
device := part.Device
|
|
|
|
path := part.Mountpoint
|
2020-03-27 00:07:39 -04:00
|
|
|
if strings.Index(device, "/dev/") == 0 {
|
|
|
|
if strings.Contains(device, "loop") {
|
|
|
|
continue
|
|
|
|
}
|
2020-10-04 13:18:46 -04:00
|
|
|
|
|
|
|
if strings.Contains(device, "/dev/fuse") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-03-27 00:07:39 -04:00
|
|
|
drives = append(drives, device)
|
|
|
|
paths = append(paths, path)
|
2020-10-04 13:18:46 -04:00
|
|
|
smartInfo, err := smart.GetInfo(device)
|
|
|
|
if err != nil {
|
2021-02-10 11:48:14 -05:00
|
|
|
smartInfo.Error = fmt.Sprintf("smart: %v", err)
|
2020-10-04 13:18:46 -04:00
|
|
|
}
|
|
|
|
partition := madmin.PartitionStat{
|
|
|
|
Device: part.Device,
|
|
|
|
Mountpoint: part.Mountpoint,
|
|
|
|
Fstype: part.Fstype,
|
2021-03-01 03:15:46 -05:00
|
|
|
Opts: strings.Join(part.Opts, ","),
|
2020-10-04 13:18:46 -04:00
|
|
|
SmartInfo: smartInfo,
|
|
|
|
}
|
|
|
|
partitions = append(partitions, partition)
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ioCounters, err := diskhw.IOCountersWithContext(ctx, drives...)
|
|
|
|
if err != nil {
|
2020-11-20 15:52:53 -05:00
|
|
|
return madmin.ServerDiskHwInfo{
|
2020-03-27 00:07:39 -04:00
|
|
|
Addr: addr,
|
2021-02-05 15:37:15 -05:00
|
|
|
Error: fmt.Sprintf("iocounters: %v", err),
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
usages := []*diskhw.UsageStat{}
|
|
|
|
for _, path := range paths {
|
|
|
|
usage, err := diskhw.UsageWithContext(ctx, path)
|
|
|
|
if err != nil {
|
2020-11-20 15:52:53 -05:00
|
|
|
return madmin.ServerDiskHwInfo{
|
2020-03-27 00:07:39 -04:00
|
|
|
Addr: addr,
|
2021-02-05 15:37:15 -05:00
|
|
|
Error: fmt.Sprintf("usage: %v", err),
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
usages = append(usages, usage)
|
|
|
|
}
|
|
|
|
|
2020-11-20 15:52:53 -05:00
|
|
|
return madmin.ServerDiskHwInfo{
|
2020-03-27 00:07:39 -04:00
|
|
|
Addr: addr,
|
|
|
|
Usage: usages,
|
|
|
|
Partitions: partitions,
|
|
|
|
Counters: ioCounters,
|
|
|
|
Error: "",
|
|
|
|
}
|
|
|
|
}
|