2020-10-04 13:18:46 -04:00
|
|
|
// +build linux
|
2020-03-27 00:07:39 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MinIO Cloud Storage, (C) 2020 MinIO, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
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"
|
2020-10-04 13:18:46 -04:00
|
|
|
"syscall"
|
2020-03-27 00:07:39 -04:00
|
|
|
|
|
|
|
"github.com/minio/minio/pkg/madmin"
|
2020-10-04 13:18:46 -04:00
|
|
|
"github.com/minio/minio/pkg/smart"
|
2020-03-27 00:07:39 -04:00
|
|
|
diskhw "github.com/shirou/gopsutil/disk"
|
2020-07-01 13:57:23 -04:00
|
|
|
"github.com/shirou/gopsutil/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 {
|
|
|
|
addr = GetLocalPeer(globalEndpoints)
|
|
|
|
}
|
|
|
|
|
|
|
|
info, err := host.InfoWithContext(ctx)
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sensors, err := host.SensorsTemperaturesWithContext(ctx)
|
|
|
|
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("sensors-temp: %v", err),
|
2020-07-01 13:57:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore user err, as it cannot be obtained reliably inside containers
|
|
|
|
users, _ := host.UsersWithContext(ctx)
|
|
|
|
|
2020-11-20 15:52:53 -05:00
|
|
|
return madmin.ServerOsInfo{
|
2020-07-01 13:57:23 -04:00
|
|
|
Addr: addr,
|
|
|
|
Info: info,
|
|
|
|
Sensors: sensors,
|
|
|
|
Users: users,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2020-03-27 00:07:39 -04:00
|
|
|
addr = GetLocalPeer(globalEndpoints)
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
if syscall.EACCES == err {
|
2021-02-05 15:37:15 -05:00
|
|
|
smartInfo.Error = fmt.Sprintf("smart: %v", err)
|
2020-10-04 13:18:46 -04:00
|
|
|
} else {
|
2020-11-20 15:52:53 -05:00
|
|
|
return madmin.ServerDiskHwInfo{
|
2020-10-04 13:18:46 -04:00
|
|
|
Addr: addr,
|
2021-02-05 15:37:15 -05:00
|
|
|
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,
|
|
|
|
Opts: part.Opts,
|
|
|
|
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: "",
|
|
|
|
}
|
|
|
|
}
|