add admin speedtest drive command (#3939)
This commit is contained in:
+50
-6
@@ -47,6 +47,20 @@ var adminSpeedtestFlags = []cli.Flag{
|
||||
Usage: "number of concurrent requests per server",
|
||||
Value: 32,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "filesize",
|
||||
Usage: "total amount of data read/written to each drive",
|
||||
Value: "1GiB",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "blocksize",
|
||||
Usage: "read/write block size",
|
||||
Value: "4MiB",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "serial",
|
||||
Usage: "run tests on drives one-by-one",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "verbose, v",
|
||||
Usage: "Show per-server stats",
|
||||
@@ -65,7 +79,11 @@ var adminSpeedtestCmd = cli.Command{
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET
|
||||
{{.HelpName}} [COMMAND] [FLAGS] TARGET
|
||||
|
||||
COMMAND:
|
||||
drives Run speed test on the drives in the cluster
|
||||
objects measure speed of writing and reading objects
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
@@ -76,6 +94,13 @@ EXAMPLES:
|
||||
|
||||
2. Run speedtest for 20 seconds with object size of 128MiB, 32 concurrent requests per server:
|
||||
{{.Prompt}} {{.HelpName}} myminio/ --duration 20s --size 128MiB --concurrent 32
|
||||
|
||||
3. Run drive speedtest where only one drive is tested at a time in any given node :
|
||||
{{.Prompt}} {{.HelpName}} drives myminio/ --serial
|
||||
|
||||
4. Run drive speedtest with blocksize of 8MiB, and 2GiB of data read/written from each drive:
|
||||
{{.Prompt}} {{.HelpName}} drives myminio/ --blocksize 8MiB --filesize 2GiB
|
||||
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -121,14 +146,33 @@ func (s speedTestResult) JSON() string {
|
||||
var globalSpeedTestVerbose bool
|
||||
|
||||
func mainAdminSpeedtest(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
args := ctx.Args()
|
||||
// the alias parameter from cli
|
||||
aliasedURL := ""
|
||||
switch len(args) {
|
||||
case 1:
|
||||
// cannot use alias by the name 'drives'
|
||||
if args[0] == "drives" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "speedtest", 1)
|
||||
}
|
||||
aliasedURL = args[0]
|
||||
case 2:
|
||||
switch args[0] {
|
||||
case "drives":
|
||||
aliasedURL = args[1]
|
||||
return mainAdminSpeedtestDrive(ctx, aliasedURL)
|
||||
case "objects":
|
||||
aliasedURL = args[1]
|
||||
case "net":
|
||||
aliasedURL = args[1]
|
||||
cli.ShowCommandHelpAndExit(ctx, "speedtest", 1)
|
||||
default:
|
||||
cli.ShowCommandHelpAndExit(ctx, "speedtest", 1) // last argument is exit code
|
||||
}
|
||||
default:
|
||||
cli.ShowCommandHelpAndExit(ctx, "speedtest", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
client, perr := newAdminClient(aliasedURL)
|
||||
if perr != nil {
|
||||
fatalIf(perr.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
// Copyright (c) 2015-2022 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/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
func mainAdminSpeedtestDrive(ctx *cli.Context, aliasedURL string) error {
|
||||
client, perr := newAdminClient(aliasedURL)
|
||||
if perr != nil {
|
||||
fatalIf(perr.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
}
|
||||
|
||||
ctxt, cancel := context.WithCancel(globalContext)
|
||||
defer cancel()
|
||||
|
||||
blocksize, e := humanize.ParseBytes(ctx.String("blocksize"))
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e), "Unable to parse blocksize")
|
||||
return nil
|
||||
}
|
||||
if blocksize < 0 {
|
||||
fatalIf(errInvalidArgument(), "blocksize cannot be <= 0")
|
||||
return nil
|
||||
}
|
||||
|
||||
filesize, e := humanize.ParseBytes(ctx.String("filesize"))
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e), "Unable to parse filesize")
|
||||
return nil
|
||||
}
|
||||
if filesize < 0 {
|
||||
fatalIf(errInvalidArgument(), "filesize cannot be <= 0")
|
||||
return nil
|
||||
}
|
||||
|
||||
serial := ctx.Bool("serial")
|
||||
|
||||
resultCh, err := client.DriveSpeedtest(ctxt, madmin.DriveSpeedTestOpts{
|
||||
Serial: serial,
|
||||
BlockSize: uint64(blocksize),
|
||||
FileSize: uint64(filesize),
|
||||
})
|
||||
fatalIf(probe.NewError(err), "Failed to execute drive speedtest")
|
||||
|
||||
for result := range resultCh {
|
||||
if result.Version != "" {
|
||||
if globalJSON {
|
||||
jsonBytes, e := json.MarshalIndent(result, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
fmt.Println(string(jsonBytes))
|
||||
continue
|
||||
}
|
||||
tbl := console.NewTable(func() []*color.Color {
|
||||
colors := []*color.Color{
|
||||
color.New(color.FgWhite, color.BgBlack, color.Bold),
|
||||
}
|
||||
for range result.DrivePerf {
|
||||
colors = append(colors, color.New(color.FgGreen))
|
||||
}
|
||||
return colors
|
||||
}(), []bool{false, false, false, false}, 0)
|
||||
cellText := make([][]string, len(result.DrivePerf)+1)
|
||||
cellText[0] = []string{
|
||||
"Node",
|
||||
"Path",
|
||||
"Read",
|
||||
"Write",
|
||||
}
|
||||
trailerIfGreaterThan := func(in string, max int) string {
|
||||
if len(in) < max {
|
||||
return ""
|
||||
}
|
||||
return "..."
|
||||
}
|
||||
for i, item := range result.DrivePerf {
|
||||
cellText[i+1] = []string{
|
||||
fmt.Sprintf("%.64s%s", result.Endpoint,
|
||||
trailerIfGreaterThan(result.Endpoint, 64)),
|
||||
fmt.Sprintf("%.64s%s", filepath.Dir(item.Path),
|
||||
trailerIfGreaterThan(result.Endpoint, 64)),
|
||||
humanize.IBytes(item.ReadThroughput) + "/s",
|
||||
humanize.IBytes(item.WriteThroughput) + "/s",
|
||||
}
|
||||
}
|
||||
if len(result.DrivePerf) > 0 {
|
||||
tbl.DisplayTable(cellText)
|
||||
}
|
||||
if result.Error != "" {
|
||||
fmt.Println(color.New(color.FgRed, color.Bold).Sprintf("ERROR"), result.Error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user