You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
3.2 KiB
148 lines
3.2 KiB
4 years ago
|
// +build linux
|
||
5 years ago
|
|
||
|
/*
|
||
|
* 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"
|
||
5 years ago
|
"net/http"
|
||
5 years ago
|
"strings"
|
||
4 years ago
|
"syscall"
|
||
5 years ago
|
|
||
|
"github.com/minio/minio/pkg/madmin"
|
||
4 years ago
|
"github.com/minio/minio/pkg/smart"
|
||
5 years ago
|
diskhw "github.com/shirou/gopsutil/disk"
|
||
4 years ago
|
"github.com/shirou/gopsutil/host"
|
||
5 years ago
|
)
|
||
|
|
||
4 years ago
|
func getLocalOsInfo(ctx context.Context, r *http.Request) madmin.ServerOsInfo {
|
||
4 years ago
|
addr := r.Host
|
||
|
if globalIsDistErasure {
|
||
|
addr = GetLocalPeer(globalEndpoints)
|
||
|
}
|
||
|
|
||
|
info, err := host.InfoWithContext(ctx)
|
||
|
if err != nil {
|
||
4 years ago
|
return madmin.ServerOsInfo{
|
||
4 years ago
|
Addr: addr,
|
||
|
Error: err.Error(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sensors, err := host.SensorsTemperaturesWithContext(ctx)
|
||
|
if err != nil {
|
||
4 years ago
|
return madmin.ServerOsInfo{
|
||
4 years ago
|
Addr: addr,
|
||
|
Error: err.Error(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ignore user err, as it cannot be obtained reliably inside containers
|
||
|
users, _ := host.UsersWithContext(ctx)
|
||
|
|
||
4 years ago
|
return madmin.ServerOsInfo{
|
||
4 years ago
|
Addr: addr,
|
||
|
Info: info,
|
||
|
Sensors: sensors,
|
||
|
Users: users,
|
||
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
func getLocalDiskHwInfo(ctx context.Context, r *http.Request) madmin.ServerDiskHwInfo {
|
||
5 years ago
|
addr := r.Host
|
||
5 years ago
|
if globalIsDistErasure {
|
||
5 years ago
|
addr = GetLocalPeer(globalEndpoints)
|
||
|
}
|
||
|
|
||
4 years ago
|
parts, err := diskhw.PartitionsWithContext(ctx, true)
|
||
5 years ago
|
if err != nil {
|
||
4 years ago
|
return madmin.ServerDiskHwInfo{
|
||
5 years ago
|
Addr: addr,
|
||
|
Error: err.Error(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
drives := []string{}
|
||
|
paths := []string{}
|
||
4 years ago
|
partitions := []madmin.PartitionStat{}
|
||
|
|
||
|
for _, part := range parts {
|
||
|
device := part.Device
|
||
|
path := part.Mountpoint
|
||
5 years ago
|
if strings.Index(device, "/dev/") == 0 {
|
||
|
if strings.Contains(device, "loop") {
|
||
|
continue
|
||
|
}
|
||
4 years ago
|
|
||
|
if strings.Contains(device, "/dev/fuse") {
|
||
|
continue
|
||
|
}
|
||
|
|
||
5 years ago
|
drives = append(drives, device)
|
||
|
paths = append(paths, path)
|
||
4 years ago
|
smartInfo, err := smart.GetInfo(device)
|
||
|
if err != nil {
|
||
|
if syscall.EACCES == err {
|
||
|
smartInfo.Error = err.Error()
|
||
|
} else {
|
||
4 years ago
|
return madmin.ServerDiskHwInfo{
|
||
4 years ago
|
Addr: addr,
|
||
|
Error: err.Error(),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
partition := madmin.PartitionStat{
|
||
|
Device: part.Device,
|
||
|
Mountpoint: part.Mountpoint,
|
||
|
Fstype: part.Fstype,
|
||
|
Opts: part.Opts,
|
||
|
SmartInfo: smartInfo,
|
||
|
}
|
||
|
partitions = append(partitions, partition)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
ioCounters, err := diskhw.IOCountersWithContext(ctx, drives...)
|
||
|
if err != nil {
|
||
4 years ago
|
return madmin.ServerDiskHwInfo{
|
||
5 years ago
|
Addr: addr,
|
||
|
Error: err.Error(),
|
||
|
}
|
||
|
}
|
||
|
usages := []*diskhw.UsageStat{}
|
||
|
for _, path := range paths {
|
||
|
usage, err := diskhw.UsageWithContext(ctx, path)
|
||
|
if err != nil {
|
||
4 years ago
|
return madmin.ServerDiskHwInfo{
|
||
5 years ago
|
Addr: addr,
|
||
|
Error: err.Error(),
|
||
|
}
|
||
|
}
|
||
|
usages = append(usages, usage)
|
||
|
}
|
||
|
|
||
4 years ago
|
return madmin.ServerDiskHwInfo{
|
||
5 years ago
|
Addr: addr,
|
||
|
Usage: usages,
|
||
|
Partitions: partitions,
|
||
|
Counters: ioCounters,
|
||
|
Error: "",
|
||
|
}
|
||
|
}
|