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-06-01 11:55:49 -04:00
|
|
|
"math"
|
2020-03-27 00:07:39 -04:00
|
|
|
"os"
|
|
|
|
"sync"
|
|
|
|
|
2021-05-06 11:52:02 -04:00
|
|
|
"github.com/minio/madmin-go"
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/disk"
|
2020-03-27 00:07:39 -04:00
|
|
|
)
|
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
// round returns value rounding to specified decimal places.
|
|
|
|
func round(f float64, n int) float64 {
|
|
|
|
if n <= 0 {
|
|
|
|
return math.Round(f)
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
p := math.Pow10(n)
|
|
|
|
return math.Round(f*p) / p
|
|
|
|
}
|
2020-03-27 00:07:39 -04:00
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
func getDrivePerfInfo(ctx context.Context, parallel bool) []madmin.DrivePerfInfo {
|
|
|
|
pools := globalEndpoints
|
|
|
|
info := []madmin.DrivePerfInfo{}
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
for _, pool := range pools {
|
|
|
|
for _, endpoint := range pool.Endpoints {
|
|
|
|
if !endpoint.IsLocal {
|
|
|
|
continue
|
|
|
|
}
|
2020-03-27 00:07:39 -04:00
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
if _, err := os.Stat(endpoint.Path); err != nil {
|
|
|
|
info = append(info, madmin.DrivePerfInfo{
|
|
|
|
Path: endpoint.Path,
|
|
|
|
Error: err.Error(),
|
|
|
|
})
|
|
|
|
continue
|
|
|
|
}
|
2020-03-27 00:07:39 -04:00
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
getHealthInfo := func(path string) {
|
|
|
|
defer wg.Done()
|
2020-03-27 00:07:39 -04:00
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
latency, throughput, err := disk.GetHealthInfo(
|
|
|
|
ctx, path, pathJoin(path, minioMetaTmpBucket, mustGetUUID()),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
info = append(info, madmin.DrivePerfInfo{
|
|
|
|
Path: path,
|
|
|
|
Error: err.Error(),
|
2020-03-27 00:07:39 -04:00
|
|
|
})
|
|
|
|
} else {
|
2021-06-01 11:55:49 -04:00
|
|
|
info = append(info, madmin.DrivePerfInfo{
|
|
|
|
Path: path,
|
|
|
|
Latency: madmin.Latency{
|
|
|
|
Avg: round(latency.Avg, 3),
|
|
|
|
Max: round(latency.Max, 3),
|
|
|
|
Min: round(latency.Min, 3),
|
|
|
|
Percentile50: round(latency.Percentile50, 3),
|
|
|
|
Percentile90: round(latency.Percentile90, 3),
|
|
|
|
Percentile99: round(latency.Percentile99, 3),
|
|
|
|
},
|
|
|
|
Throughput: madmin.Throughput{
|
|
|
|
Avg: uint64(round(throughput.Avg, 0)),
|
|
|
|
Max: uint64(round(throughput.Max, 0)),
|
|
|
|
Min: uint64(round(throughput.Min, 0)),
|
|
|
|
Percentile50: uint64(round(throughput.Percentile50, 0)),
|
|
|
|
Percentile90: uint64(round(throughput.Percentile90, 0)),
|
|
|
|
Percentile99: uint64(round(throughput.Percentile99, 0)),
|
|
|
|
},
|
|
|
|
})
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
wg.Add(1)
|
|
|
|
if parallel {
|
|
|
|
go getHealthInfo(endpoint.Path)
|
|
|
|
} else {
|
|
|
|
getHealthInfo(endpoint.Path)
|
|
|
|
}
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
wg.Wait()
|
|
|
|
return info
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
|
2021-06-01 11:55:49 -04:00
|
|
|
func getDrivePerfInfos(ctx context.Context, addr string) madmin.DrivePerfInfos {
|
|
|
|
serialPerf := getDrivePerfInfo(ctx, false)
|
|
|
|
parallelPerf := getDrivePerfInfo(ctx, true)
|
|
|
|
return madmin.DrivePerfInfos{
|
2021-07-12 13:16:10 -04:00
|
|
|
NodeCommon: madmin.NodeCommon{Addr: addr},
|
2021-06-01 11:55:49 -04:00
|
|
|
SerialPerf: serialPerf,
|
|
|
|
ParallelPerf: parallelPerf,
|
2020-03-27 00:07:39 -04:00
|
|
|
}
|
|
|
|
}
|