fix: remove unusued PerfInfoHandler code (#9328)

- Removes PerfInfo admin API as its not OBDInfo
- Keep the drive path without the metaBucket in OBD
  global latency map.
- Remove all the unused code related to PerfInfo API
- Do not redefined global mib,gib constants use
  humanize.MiByte and humanize.GiByte instead always
This commit is contained in:
Harshavardhana
2020-04-12 19:37:09 -07:00
committed by GitHub
parent 7d636a7c13
commit 4314ee1670
28 changed files with 53 additions and 2080 deletions

View File

@@ -1,37 +0,0 @@
/*
* MinIO Cloud Storage, (C) 2019 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 cpu
import (
"syscall"
"time"
"unsafe"
"golang.org/x/sys/unix"
)
func newCounter() (counter, error) {
return counter{}, nil
}
func (c counter) now() time.Time {
var ts syscall.Timespec
// Retrieve Per-process CPU-time clock
syscall.Syscall(syscall.SYS_CLOCK_GETTIME, unix.CLOCK_PROCESS_CPUTIME_ID, uintptr(unsafe.Pointer(&ts)), 0)
sec, nsec := ts.Unix()
return time.Unix(sec, nsec)
}

View File

@@ -1,33 +0,0 @@
// +build !linux
/*
* MinIO Cloud Storage, (C) 2019-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 cpu
import (
"fmt"
"runtime"
"time"
)
func newCounter() (counter, error) {
return counter{}, fmt.Errorf("cpu metrics not implemented for %s platform", runtime.GOOS)
}
func (c counter) now() time.Time {
return time.Time{}
}

View File

@@ -1,143 +0,0 @@
/*
* MinIO Cloud Storage, (C) 2019 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 cpu
import (
"sync"
"time"
)
// rollingAvg holds the rolling average of the cpu load on the minio
// server over its lifetime
var rollingAvg *Load
// cpuMeasureInterval is the interval of time between two
// measurements of CPU load
const cpuLoadMeasureInterval = 5 * time.Second
// triggers the average load computation at server spawn
func init() {
rollingAvg = &Load{
Min: float64(0),
Max: float64(0),
Avg: float64(0),
}
var rollingSum float64
var cycles float64
go func() {
for {
time.Sleep(cpuLoadMeasureInterval)
cycles = cycles + 1
currLoad := GetLoad()
if rollingAvg.Max < currLoad.Max || rollingAvg.Max == 0 {
rollingAvg.Max = currLoad.Max
}
if rollingAvg.Min > currLoad.Min || rollingAvg.Min == 0 {
rollingAvg.Min = currLoad.Min
}
rollingSum = rollingSum + currLoad.Avg
rollingAvg.Avg = rollingSum / cycles
}
}()
}
const (
// cpuLoadWindow is the interval of time for which the
// cpu utilization is measured
cpuLoadWindow = 200 * time.Millisecond
// cpuLoadSampleSize is the number of samples measured
// for calculating cpu utilization
cpuLoadSampleSize = 3
// endOfTime represents the end of time
endOfTime = time.Duration(1<<63 - 1)
)
// Load holds CPU utilization % measured in three intervals of 200ms each
type Load struct {
Avg float64 `json:"avg"`
Max float64 `json:"max"`
Min float64 `json:"min"`
Error string `json:"error,omitempty"`
}
type counter struct{}
// GetHistoricLoad returns the historic CPU utilization of the current process
func GetHistoricLoad() Load {
return *rollingAvg
}
// GetLoad returns the CPU utilization of the current process
// This function works by calcualating the amount of cpu clock
// cycles the current process used in a given time window
//
// This corresponds to the CPU utilization calculation done by
// tools like top. Here, we use the getclocktime with the
// CLOCK_PROCESS_CPUTIME_ID parameter to obtain the total number of
// clock ticks used by the process so far. Then we sleep for
// 200ms and obtain the the total number of clock ticks again. The
// difference between the two counts provides us the number of
// clock ticks used by the process in the 200ms interval.
//
// The ratio of clock ticks used (measured in nanoseconds) to number
// of nanoseconds in 200 milliseconds provides us the CPU usage
// for the process currently
func GetLoad() Load {
vals := make(chan time.Duration, 3)
var wg sync.WaitGroup
for i := 0; i < cpuLoadSampleSize; i++ {
cpuCounter, err := newCounter()
if err != nil {
return Load{
Error: err.Error(),
}
}
wg.Add(1)
go func() {
start := cpuCounter.now()
time.Sleep(cpuLoadWindow)
end := cpuCounter.now()
vals <- end.Sub(start)
wg.Done()
}()
}
wg.Wait()
sum := time.Duration(0)
max := time.Duration(0)
min := (endOfTime)
for i := 0; i < cpuLoadSampleSize; i++ {
val := <-vals
sum = sum + val
if val > max {
max = val
}
if val < min {
min = val
}
}
close(vals)
avg := sum / 3
return Load{
Avg: toFixed4(float64(avg)/float64(200*time.Millisecond)) * 100,
Max: toFixed4(float64(max)/float64(200*time.Millisecond)) * 100,
Min: toFixed4(float64(min)/float64(200*time.Millisecond)) * 100,
Error: "",
}
}

View File

@@ -1,30 +0,0 @@
/*
* MinIO Cloud Storage, (C) 2019 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 cpu
import (
"math"
)
func round(num float64) int {
return int(num + math.Copysign(0.5, num))
}
func toFixed4(num float64) float64 {
output := math.Pow(10, float64(4))
return float64(round(num*output)) / output
}

View File

@@ -16,10 +16,6 @@
package disk
import (
"os"
)
// Info stat fs struct is container which holds following values
// Total - total size of the volume / disk
// Free - free size of the volume / disk
@@ -36,60 +32,3 @@ type Info struct {
// Usage is calculated per tenant.
Usage uint64
}
// Performance holds informantion about read and write speed of a disk
type Performance struct {
Path string `json:"path"`
Error string `json:"error,omitempty"`
WriteSpeed float64 `json:"writeSpeed"`
ReadSpeed float64 `json:"readSpeed"`
}
// GetPerformance returns given disk's read and write performance
func GetPerformance(path string, size int64) Performance {
perf := Performance{}
write, read, err := doPerfMeasure(path, size)
if err != nil {
perf.Error = err.Error()
return perf
}
perf.WriteSpeed = write
perf.ReadSpeed = read
return perf
}
// Calculate the write and read performance - write and read 10 tmp (1 MiB)
// files and find the average time taken (Bytes / Sec)
func doPerfMeasure(fsPath string, size int64) (writeSpeed, readSpeed float64, err error) {
// Remove the file created for speed test purposes
defer os.RemoveAll(fsPath)
// Create a file with O_DIRECT flag
w, err := OpenFileDirectIO(fsPath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0666)
if err != nil {
return 0, 0, err
}
// Fetch aligned buf for direct-io
buf := AlignedBlock(speedTestBlockSize)
writeSpeed, err = speedTestWrite(w, buf, size)
w.Close()
if err != nil {
return 0, 0, err
}
// Open file to compute read speed
r, err := OpenFileDirectIO(fsPath, os.O_RDONLY, 0666)
if err != nil {
return 0, 0, err
}
defer r.Close()
readSpeed, err = speedTestRead(r, buf, size)
if err != nil {
return 0, 0, err
}
return writeSpeed, readSpeed, nil
}

View File

@@ -21,19 +21,13 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"runtime"
"time"
"github.com/dustin/go-humanize"
"github.com/montanaflynn/stats"
)
const (
kb = uint64(1 << 10)
mb = uint64(kb << 10)
gb = uint64(mb << 10)
)
var globalLatency = map[string]Latency{}
var globalThroughput = map[string]Throughput{}
@@ -58,19 +52,20 @@ type Throughput struct {
}
// GetOBDInfo about the drive
func GetOBDInfo(ctx context.Context, endpoint string) (Latency, Throughput, error) {
func GetOBDInfo(ctx context.Context, drive string, fsPath string) (Latency, Throughput, error) {
runtime.LockOSThread()
f, err := OpenFileDirectIO(endpoint, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0755)
// Create a file with O_DIRECT flag, choose default umask and also make sure
// we are exclusively writing to a new file using O_EXCL.
w, err := OpenFileDirectIO(fsPath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0666)
if err != nil {
return Latency{}, Throughput{}, err
}
defer func() {
f.Close()
os.Remove(f.Name())
}()
drive := filepath.Dir(endpoint)
defer func() {
w.Close()
os.Remove(fsPath)
}()
// going to leave this here incase we decide to go back to caching again
// if gl, ok := globalLatency[drive]; ok {
@@ -79,27 +74,26 @@ func GetOBDInfo(ctx context.Context, endpoint string) (Latency, Throughput, erro
// }
// }
blockSize := 4 * mb
fileSize := 256 * mb
blockSize := 4 * humanize.MiByte
fileSize := 256 * humanize.MiByte
latencies := make([]float64, fileSize/blockSize)
throughputs := make([]float64, fileSize/blockSize)
dioFile := os.NewFile(uintptr(f.Fd()), endpoint)
data := make([]byte, blockSize)
data := AlignedBlock(blockSize)
for i := uint64(0); i < (fileSize / blockSize); i++ {
for i := 0; i < (fileSize / blockSize); i++ {
if ctx.Err() != nil {
return Latency{}, Throughput{}, ctx.Err()
}
startTime := time.Now()
if n, err := dioFile.Write(data); err != nil {
if n, err := w.Write(data); err != nil {
return Latency{}, Throughput{}, err
} else if uint64(n) != blockSize {
} else if n != blockSize {
return Latency{}, Throughput{}, fmt.Errorf("Expected to write %d, but only wrote %d", blockSize, n)
}
latency := time.Since(startTime)
latencies[i] = float64(latency.Seconds())
latencyInSecs := time.Since(startTime).Seconds()
latencies[i] = float64(latencyInSecs)
}
runtime.UnlockOSThread()

View File

@@ -1,97 +0,0 @@
/*
* MinIO Cloud Storage, (C) 2019 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 disk
import (
"io"
"math"
"time"
humanize "github.com/dustin/go-humanize"
)
var speedTestBlockSize = 4 * humanize.MiByte
// speedTestWrite computes the write speed by writing
// `speedTestFileSize` bytes of data to `w` in 4MiB direct-aligned
// blocks present in `buf`
func speedTestWrite(w io.Writer, buf []byte, size int64) (float64, error) {
// Write speedTestFileSize of data and record write speed
startTime := time.Now()
remaining := size
for remaining > 0 {
var toWrite int
// there's more remaining to write than the buffer can hold
if int64(len(buf)) < remaining {
toWrite = len(buf)
} else { // buffer can hold all there is to write
toWrite = int(remaining)
}
written, err := w.Write(buf[:toWrite])
if err != nil {
return 0, err
}
remaining = remaining - int64(written)
}
elapsedTime := time.Since(startTime).Seconds()
totalWriteMBs := float64(size) / humanize.MiByte
writeSpeed := totalWriteMBs / elapsedTime
return roundToTwoDecimals(writeSpeed), nil
}
// speedTestRead computes the read speed by reading
// `speedTestFileSize` bytes from the reader `r` using 4MiB size `buf`
func speedTestRead(r io.Reader, buf []byte, size int64) (float64, error) {
// Read speedTestFileSize and record read speed
startTime := time.Now()
remaining := size
for remaining > 0 {
// reads `speedTestBlockSize` on every read
n, err := io.ReadFull(r, buf)
if err == io.ErrUnexpectedEOF || err == nil {
remaining = remaining - int64(n)
continue
}
// Nothing more left to read from the Reader
if err == io.EOF {
break
}
// Error while reading from the underlying Reader
if err != nil {
return 0, err
}
}
if remaining > 0 {
return 0, io.ErrUnexpectedEOF
}
elapsedTime := time.Since(startTime).Seconds()
totalReadMBs := float64(size) / humanize.MiByte
readSpeed := totalReadMBs / elapsedTime
return roundToTwoDecimals(readSpeed), nil
}
func roundToTwoDecimals(num float64) float64 {
return math.Round(num*100) / 100
}

View File

@@ -35,8 +35,6 @@ const (
AccountingUsageInfoAdminAction = "admin:AccountingUsageInfo"
// DataUsageInfoAdminAction - allow listing data usage info
DataUsageInfoAdminAction = "admin:DataUsageInfo"
// PerfInfoAdminAction - allow listing performance info
PerfInfoAdminAction = "admin:PerfInfo"
// TopLocksAdminAction - allow listing top locks
TopLocksAdminAction = "admin:TopLocksInfo"
// ProfilingAdminAction - allow profiling
@@ -47,8 +45,6 @@ const (
ConsoleLogAdminAction = "admin:ConsoleLog"
// KMSKeyStatusAdminAction - allow getting KMS key status
KMSKeyStatusAdminAction = "admin:KMSKeyStatus"
// ServerHardwareInfoAdminAction - allow listing server hardware info
ServerHardwareInfoAdminAction = "admin:HardwareInfo"
// ServerInfoAdminAction - allow listing server info
ServerInfoAdminAction = "admin:ServerInfo"
// OBDInfoAdminAction - allow obtaining cluster on-board diagnostics
@@ -115,13 +111,11 @@ var supportedAdminActions = map[AdminAction]struct{}{
ServerInfoAdminAction: {},
StorageInfoAdminAction: {},
DataUsageInfoAdminAction: {},
PerfInfoAdminAction: {},
TopLocksAdminAction: {},
ProfilingAdminAction: {},
TraceAdminAction: {},
ConsoleLogAdminAction: {},
KMSKeyStatusAdminAction: {},
ServerHardwareInfoAdminAction: {},
ServerUpdateAdminAction: {},
ConfigUpdateAdminAction: {},
CreateUserAdminAction: {},
@@ -164,13 +158,11 @@ var adminActionConditionKeyMap = map[Action]condition.KeySet{
StorageInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
ServerInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
DataUsageInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
PerfInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
TopLocksAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
ProfilingAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
TraceAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
ConsoleLogAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
KMSKeyStatusAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
ServerHardwareInfoAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
ServerUpdateAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
ConfigUpdateAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),
CreateUserAdminAction: condition.NewKeySet(condition.AllSupportedAdminKeys...),

View File

@@ -70,9 +70,11 @@ var AdminDiagnostics = Policy{
Version: DefaultVersion,
Statements: []Statement{
{
SID: policy.ID(""),
Effect: policy.Allow,
Actions: NewActionSet(PerfInfoAdminAction, ProfilingAdminAction, TraceAdminAction, ConsoleLogAdminAction, ServerInfoAdminAction, ServerHardwareInfoAdminAction, TopLocksAdminAction),
SID: policy.ID(""),
Effect: policy.Allow,
Actions: NewActionSet(ProfilingAdminAction, TraceAdminAction,
ConsoleLogAdminAction, ServerInfoAdminAction,
TopLocksAdminAction, OBDInfoAdminAction),
Resources: NewResourceSet(NewResource("*", "")),
},
},

View File

@@ -45,12 +45,12 @@ func main() {
| Service operations | Info operations | Healing operations | Config operations | Top operations | IAM operations | Misc | KMS |
|:------------------------------------|:--------------------------------------------------|:-------------------|:--------------------------|:------------------------|:--------------------------------------|:--------------------------------------------------|:--------------------------------|
| [`ServiceRestart`](#ServiceRestart) | [`ServerInfo`](#ServerInfo) | [`Heal`](#Heal) | [`GetConfig`](#GetConfig) | [`TopLocks`](#TopLocks) | [`AddUser`](#AddUser) | | [`GetKeyStatus`](#GetKeyStatus) |
| [`ServiceStop`](#ServiceStop) | [`ServerCPULoadInfo`](#ServerCPULoadInfo) | | [`SetConfig`](#SetConfig) | | [`SetUserPolicy`](#SetUserPolicy) | [`StartProfiling`](#StartProfiling) | |
| | [`ServerMemUsageInfo`](#ServerMemUsageInfo) | | | | [`ListUsers`](#ListUsers) | [`DownloadProfilingData`](#DownloadProfilingData) | |
| [`ServiceTrace`](#ServiceTrace) | [`ServerDrivesPerfInfo`](#ServerDrivesPerfInfo) | | | | [`AddCannedPolicy`](#AddCannedPolicy) | [`ServerUpdate`](#ServerUpdate) | |
| | [`NetPerfInfo`](#NetPerfInfo) | | | | | | |
| | [`ServerCPUHardwareInfo`](#ServerCPUHardwareInfo) | | | | | | |
| | [`ServerNetworkHardwareInfo`](#ServerNetworkHardwareInfo) | | | | | | |
| [`ServiceStop`](#ServiceStop) | | | [`SetConfig`](#SetConfig) | | [`SetUserPolicy`](#SetUserPolicy) | [`StartProfiling`](#StartProfiling) | |
| | | | | | [`ListUsers`](#ListUsers) | [`DownloadProfilingData`](#DownloadProfilingData) | |
| [`ServiceTrace`](#ServiceTrace) | | | | | [`AddCannedPolicy`](#AddCannedPolicy) | [`ServerUpdate`](#ServerUpdate) | |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
| | [`StorageInfo`](#StorageInfo) | | | | | | |
## 1. Constructor
@@ -210,116 +210,6 @@ Fetches information for all cluster nodes, such as server properties, storage in
```
<a name="ServerDrivesPerfInfo"></a>
### ServerDrivesPerfInfo(ctx context.Context) ([]ServerDrivesPerfInfo, error)
Fetches drive performance information for all cluster nodes.
| Param | Type | Description |
|-----------------|--------------------|--------------------------------------------------------------------|
| `di.Addr` | _string_ | Address of the server the following information is retrieved from. |
| `di.Error` | _string_ | Errors (if any) encountered while reaching this node |
| `di.DrivesPerf` | _disk.Performance_ | Path of the drive mount on above server and read, write speed. |
| Param | Type | Description |
|-------------------------------|-----------|--------------------------------------------------------|
| `disk.Performance.Path` | _string_ | Path of drive mount. |
| `disk.Performance.Error` | _string_ | Error (if any) encountered while accessing this drive. |
| `disk.Performance.WriteSpeed` | _float64_ | Write speed on above path in Bytes/s. |
| `disk.Performance.ReadSpeed` | _float64_ | Read speed on above path in Bytes/s. |
<a name="ServerCPULoadInfo"></a>
### ServerCPULoadInfo(ctx context.Context) ([]ServerCPULoadInfo, error)
Fetches CPU utilization for all cluster nodes.
| Param | Type | Description |
|----------------|------------|---------------------------------------------------------------------|
| `cpui.Addr` | _string_ | Address of the server the following information is retrieved from. |
| `cpui.Error` | _string_ | Errors (if any) encountered while reaching this node |
| `cpui.CPULoad` | _cpu.Load_ | The load on the CPU. |
| Param | Type | Description |
|------------------|-----------|-----------------------------------------------------------------|
| `cpu.Load.Avg` | _float64_ | The average utilization of the CPU measured in a 200ms interval |
| `cpu.Load.Min` | _float64_ | The minimum utilization of the CPU measured in a 200ms interval |
| `cpu.Load.Max` | _float64_ | The maximum utilization of the CPU measured in a 200ms interval |
| `cpu.Load.Error` | _string_ | Error (if any) encountered while accessing the CPU info |
<a name="ServerMemUsageInfo"></a>
### ServerMemUsageInfo(ctx context.Context) ([]ServerMemUsageInfo, error)
Fetches Mem utilization for all cluster nodes.
| Param | Type | Description |
|-----------------|-------------|---------------------------------------------------------------------|
| `memi.Addr` | _string_ | Address of the server the following information is retrieved from. |
| `memi.Error` | _string_ | Errors (if any) encountered while reaching this node |
| `memi.MemUsage` | _mem.Usage_ | The utilitzation of Memory |
| Param | Type | Description |
|-------------------|----------|--------------------------------------------------------|
| `mem.Usage.Mem` | _uint64_ | The total number of bytes obtained from the OS |
| `mem.Usage.Error` | _string_ | Error (if any) encountered while accessing the CPU info |
<a name="NetPerfInfo"></a>
### NetPerfInfo(ctx context.Context, int size) (map[string][]NetPerfInfo, error)
Fetches network performance of all cluster nodes using given sized payload. Returned value is a map containing each node indexed list of performance of other nodes.
| Param | Type | Description |
|------------------|-----------|--------------------------------------------------------------------|
| `Addr` | _string_ | Address of the server the following information is retrieved from. |
| `Error` | _string_ | Errors (if any) encountered while reaching this node |
| `ReadThroughput` | _uint64_ | Network read throughput of the server in bytes per second |
<a name="ServerCPUHardwareInfo"></a>
### ServerCPUHardwareInfo(ctx context.Context) ([]ServerCPUHardwareInfo, error)
Fetches hardware information of CPU.
| Param | Type | Description |
|-------------------|---------------------|---------------------------------------------------------------------|
| `hwi.Addr` | _string_ | Address of the server the following information is retrieved from. |
| `hwi.Error` | _string_ | Errors (if any) encountered while reaching this node |
| `hwi.CPUInfo` | _[]cpu.InfoStat_ | The CPU hardware info. |
| Param | Type | Description |
|----------------------------|----------|--------------------------------------------------------|
| `CPUInfo.CPU` | _int32_ | CPU |
| `CPUInfo.VendorID` | _string_ | Vendor Id |
| `CPUInfo.Family` | _string_ | CPU Family |
| `CPUInfo.Model` | _string_ | Model |
| `CPUInfo.Stepping` | _int32_ | Stepping |
| `CPUInfo.PhysicalId` | _string_ | Physical Id |
| `CPUInfo.CoreId` | _string_ | Core Id |
| `CPUInfo.Cores` | _int32_ | Cores |
| `CPUInfo.ModelName` | _string_ | Model Name |
| `CPUInfo.Mhz` | _float64_| Mhz |
| `CPUInfo.CacheZSize` | _int32_ | cache sizes |
| `CPUInfo.Flags` |_[]string_| Flags |
| `CPUInfo.Microcode` | _string_ | Micro codes |
<a name="ServerNetworkHardwareInfo"></a>
### ServerNetworkHardwareInfo(ctx context.Context) ([]ServerNetworkHardwareInfo, error)
Fetches hardware information of CPU.
| Param | Type | Description |
|-------------------|---------------------|---------------------------------------------------------------------|
| `hwi.Addr` | _string_ | Address of the server the following information is retrieved from. |
| `hwi.Error` | _string_ | Errors (if any) encountered while reaching this node |
| `hwi.NetworkInfo` | _[]net.Interface_ | The network hardware info |
| Param | Type | Description |
|----------------------------|----------|-----------------------------------------------------------|
| `NetworkInfo.Index` | _int32_ | positive integer that starts at one, zero is never used. |
| `NetworkInfo.MTU` | _int32_ | maximum transmission unit |
| `NetworkInfo.Name` | _string_ | e.g., "en0", "lo0", "eth0.100" |
| `NetworkInfo.HardwareAddr` | _[]byte_ | IEEE MAC-48, EUI-48 and EUI-64 form |
| `NetworkInfo.Flags` | _uint32_ | e.g., FlagUp, FlagLoopback, FlagMulticast |
<a name="StorageInfo"></a>
### StorageInfo(ctx context.Context) (StorageInfo, error)

View File

@@ -1,45 +0,0 @@
// +build ignore
/*
* MinIO Cloud Storage, (C) 2019 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 main
import (
"context"
"log"
"github.com/minio/minio/pkg/madmin"
)
func main() {
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.
// API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise.
// New returns an MinIO Admin client object.
madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
if err != nil {
log.Fatalln(err)
}
st, err := madmClnt.ServerCPULoadInfo(context.Background())
if err != nil {
log.Fatalln(err)
}
log.Println(st)
}

View File

@@ -1,45 +0,0 @@
// +build ignore
/*
* MinIO Cloud Storage, (C) 2018 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 main
import (
"context"
"log"
"github.com/minio/minio/pkg/madmin"
)
func main() {
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.
// API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise.
// New returns an MinIO Admin client object.
madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
if err != nil {
log.Fatalln(err)
}
st, err := madmClnt.ServerDrivesPerfInfo(context.Background(), madmin.DefaultDrivePerfSize)
if err != nil {
log.Fatalln(err)
}
log.Println(st)
}

View File

@@ -1,45 +0,0 @@
// +build ignore
/*
* MinIO Cloud Storage, (C) 2019 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 main
import (
"context"
"log"
"github.com/minio/minio/pkg/madmin"
)
func main() {
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with correct values.
// API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise.
// New returns an MinIO Admin client object.
madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
if err != nil {
log.Fatalln(err)
}
st, err := madmClnt.ServerCPUHardwareInfo(context.Background())
if err != nil {
log.Fatalln(err)
}
log.Println(st)
}

View File

@@ -1,45 +0,0 @@
// +build ignore
/*
* MinIO Cloud Storage, (C) 2019 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 main
import (
"context"
"log"
"github.com/minio/minio/pkg/madmin"
)
func main() {
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with correct values.
// API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise.
// New returns an MinIO Admin client object.
madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
if err != nil {
log.Fatalln(err)
}
st, err := madmClnt.ServerNetworkHardwareInfo(context.Background())
if err != nil {
log.Fatalln(err)
}
log.Println(st)
}

View File

@@ -1,45 +0,0 @@
// +build ignore
/*
* MinIO Cloud Storage, (C) 2019 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 main
import (
"context"
"log"
"github.com/minio/minio/pkg/madmin"
)
func main() {
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.
// API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise.
// New returns an MinIO Admin client object.
madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
if err != nil {
log.Fatalln(err)
}
st, err := madmClnt.ServerMemUsageInfo(context.Background())
if err != nil {
log.Fatalln(err)
}
log.Println(st)
}

View File

@@ -1,45 +0,0 @@
// +build ignore
/*
* MinIO Cloud Storage, (C) 2019 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 main
import (
"context"
"log"
"github.com/minio/minio/pkg/madmin"
)
func main() {
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.
// API requests are secure (HTTPS) if secure=true and insecure (HTTP) otherwise.
// New returns an MinIO Admin client object.
madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
if err != nil {
log.Fatalln(err)
}
st, err := madmClnt.NetPerfInfo(context.Background(), madmin.DefaultNetPerfSize)
if err != nil {
log.Fatalln(err)
}
log.Println(st)
}

View File

@@ -1,127 +0,0 @@
/*
* MinIO Cloud Storage, (C) 2019 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 madmin
import (
"context"
"encoding/json"
"io/ioutil"
"net"
"net/http"
"net/url"
"github.com/shirou/gopsutil/cpu"
)
// HardwareType - type to hardware
type HardwareType string
const (
// HARDWARE represents hardware type
HARDWARE = "hwType"
// CPU represents hardware as cpu
CPU HardwareType = "cpu"
// NETWORK hardware Info
NETWORK HardwareType = "network"
)
// ServerCPUHardwareInfo holds informantion about cpu hardware
type ServerCPUHardwareInfo struct {
Addr string `json:"addr"`
Error string `json:"error,omitempty"`
CPUInfo []cpu.InfoStat `json:"cpu"`
}
// ServerCPUHardwareInfo - Returns cpu hardware information
func (adm *AdminClient) ServerCPUHardwareInfo(ctx context.Context) ([]ServerCPUHardwareInfo, error) {
v := url.Values{}
v.Set(HARDWARE, string(CPU))
resp, err := adm.executeMethod(ctx,
http.MethodGet, requestData{
relPath: adminAPIPrefix + "/hardware",
queryValues: v,
},
)
defer closeResponse(resp)
if err != nil {
return nil, err
}
// Check response http status code
if resp.StatusCode != http.StatusOK {
return nil, httpRespToErrorResponse(resp)
}
// Unmarshal the server's json response
var cpuInfo []ServerCPUHardwareInfo
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(respBytes, &cpuInfo)
if err != nil {
return nil, err
}
return cpuInfo, nil
}
// ServerNetworkHardwareInfo holds informantion about cpu hardware
type ServerNetworkHardwareInfo struct {
Addr string `json:"addr"`
Error string `json:"error,omitempty"`
NetworkInfo []net.Interface `json:"network"`
}
// ServerNetworkHardwareInfo - Returns network hardware information
func (adm *AdminClient) ServerNetworkHardwareInfo(ctx context.Context) ([]ServerNetworkHardwareInfo, error) {
v := url.Values{}
v.Set(HARDWARE, string(NETWORK))
resp, err := adm.executeMethod(ctx,
http.MethodGet, requestData{
relPath: "/v1/hardware",
queryValues: v,
},
)
defer closeResponse(resp)
if err != nil {
return nil, err
}
// Check response http status code
if resp.StatusCode != http.StatusOK {
return nil, httpRespToErrorResponse(resp)
}
// Unmarshal the server's json response
var networkInfo []ServerNetworkHardwareInfo
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(respBytes, &networkInfo)
if err != nil {
return nil, err
}
return networkInfo, nil
}

View File

@@ -20,25 +20,10 @@ package madmin
import (
"context"
"encoding/json"
"errors"
"io/ioutil"
"math"
"net/http"
"net/url"
"strconv"
"time"
humanize "github.com/dustin/go-humanize"
"github.com/minio/minio/pkg/cpu"
"github.com/minio/minio/pkg/disk"
"github.com/minio/minio/pkg/mem"
)
const (
// DefaultNetPerfSize - default payload size used for network performance.
DefaultNetPerfSize = 100 * humanize.MiByte
// DefaultDrivePerfSize - default file size for testing drive performance
DefaultDrivePerfSize = 100 * humanize.MiByte
)
// BackendType - represents different backend types.
@@ -251,200 +236,6 @@ func (adm *AdminClient) AccountingUsageInfo(ctx context.Context) (map[string]Buc
return accountingUsageInfo, nil
}
// ServerDrivesPerfInfo holds informantion about address and write speed of
// all drives in a single server node
type ServerDrivesPerfInfo struct {
Addr string `json:"addr"`
Error string `json:"error,omitempty"`
Perf []disk.Performance `json:"perf"`
Size int64 `json:"size,omitempty"`
}
// ServerDrivesPerfInfo - Returns drive's read and write performance information
func (adm *AdminClient) ServerDrivesPerfInfo(ctx context.Context, size int64) ([]ServerDrivesPerfInfo, error) {
v := url.Values{}
v.Set("perfType", string("drive"))
v.Set("size", strconv.FormatInt(size, 10))
resp, err := adm.executeMethod(ctx, http.MethodGet,
requestData{
relPath: adminAPIPrefix + "/performance",
queryValues: v,
},
)
defer closeResponse(resp)
if err != nil {
return nil, err
}
// Check response http status code
if resp.StatusCode != http.StatusOK {
return nil, httpRespToErrorResponse(resp)
}
// Unmarshal the server's json response
var info []ServerDrivesPerfInfo
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(respBytes, &info)
if err != nil {
return nil, err
}
return info, nil
}
// ServerCPULoadInfo holds information about address and cpu load of
// a single server node
type ServerCPULoadInfo struct {
Addr string `json:"addr"`
Error string `json:"error,omitempty"`
Load []cpu.Load `json:"load"`
HistoricLoad []cpu.Load `json:"historicLoad"`
}
// ServerCPULoadInfo - Returns cpu utilization information
func (adm *AdminClient) ServerCPULoadInfo(ctx context.Context) ([]ServerCPULoadInfo, error) {
v := url.Values{}
v.Set("perfType", string("cpu"))
resp, err := adm.executeMethod(ctx,
http.MethodGet, requestData{
relPath: adminAPIPrefix + "/performance",
queryValues: v,
},
)
defer closeResponse(resp)
if err != nil {
return nil, err
}
// Check response http status code
if resp.StatusCode != http.StatusOK {
return nil, httpRespToErrorResponse(resp)
}
// Unmarshal the server's json response
var info []ServerCPULoadInfo
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(respBytes, &info)
if err != nil {
return nil, err
}
return info, nil
}
// ServerMemUsageInfo holds information about address and memory utilization of
// a single server node
type ServerMemUsageInfo struct {
Addr string `json:"addr"`
Error string `json:"error,omitempty"`
Usage []mem.Usage `json:"usage"`
HistoricUsage []mem.Usage `json:"historicUsage"`
}
// ServerMemUsageInfo - Returns mem utilization information
func (adm *AdminClient) ServerMemUsageInfo(ctx context.Context) ([]ServerMemUsageInfo, error) {
v := url.Values{}
v.Set("perfType", string("mem"))
resp, err := adm.executeMethod(ctx,
http.MethodGet,
requestData{
relPath: adminAPIPrefix + "/performance",
queryValues: v,
},
)
defer closeResponse(resp)
if err != nil {
return nil, err
}
// Check response http status code
if resp.StatusCode != http.StatusOK {
return nil, httpRespToErrorResponse(resp)
}
// Unmarshal the server's json response
var info []ServerMemUsageInfo
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(respBytes, &info)
if err != nil {
return nil, err
}
return info, nil
}
// NetPerfInfo network performance information.
type NetPerfInfo struct {
Addr string `json:"addr"`
ReadThroughput uint64 `json:"readThroughput"`
Error string `json:"error,omitempty"`
}
// NetPerfInfo - Returns network performance information of all cluster nodes.
func (adm *AdminClient) NetPerfInfo(ctx context.Context, size int) (map[string][]NetPerfInfo, error) {
v := url.Values{}
v.Set("perfType", "net")
if size > 0 {
v.Set("size", strconv.Itoa(size))
}
resp, err := adm.executeMethod(ctx,
http.MethodGet,
requestData{
relPath: adminAPIPrefix + "/performance",
queryValues: v,
},
)
defer closeResponse(resp)
if err != nil {
return nil, err
}
// Check response http status code
if resp.StatusCode == http.StatusMethodNotAllowed {
return nil, errors.New("NetPerfInfo is meant for multi-node MinIO deployments")
}
if resp.StatusCode != http.StatusOK {
return nil, httpRespToErrorResponse(resp)
}
// Unmarshal the server's json response
info := map[string][]NetPerfInfo{}
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(respBytes, &info)
if err != nil {
return nil, err
}
return info, nil
}
// InfoMessage container to hold server admin related information.
type InfoMessage struct {
Mode string `json:"mode,omitempty"`

View File

@@ -1,68 +0,0 @@
/*
* MinIO Cloud Storage, (C) 2019 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 mem
import (
"runtime"
"time"
)
// historicUsage holds the rolling average of memory used by
// minio server
var historicUsage *Usage
// memUsageMeasureInterval is the window of time between
// two measurements of memory usage
const memUsageMeasureInterval = 5 * time.Second
// triggers the collection of historic stats about the memory
// utilized by minio server
func init() {
historicUsage = &Usage{}
var cycles uint64
go func() {
for {
time.Sleep(memUsageMeasureInterval)
currUsage := GetUsage()
currSum := cycles * historicUsage.Mem
cycles = cycles + 1
historicUsage.Mem = (currSum + currUsage.Mem) / cycles
}
}()
}
// Usage holds memory utilization information in human readable format
type Usage struct {
Mem uint64 `json:"mem"`
Error string `json:"error,omitempty"`
}
// GetHistoricUsage measures the historic average of memory utilized by
// current process
func GetHistoricUsage() Usage {
return *historicUsage
}
// GetUsage measures the total memory provisioned for the current process
// from the OS
func GetUsage() Usage {
memStats := new(runtime.MemStats)
runtime.ReadMemStats(memStats)
return Usage{
Mem: memStats.Sys,
}
}