modify support profile command (#4061)

This commit is contained in:
Ashish Kumar Sinha
2022-05-12 06:43:21 -07:00
committed by GitHub
parent 8ca59cdebf
commit aa60a8db1e
7 changed files with 209 additions and 294 deletions
+8 -9
View File
@@ -403,15 +403,14 @@ var completeCmds = map[string]complete.Predictor{
"/alias/remove": aliasCompleter,
"/alias/import": nil,
"/support/callhome/set": aliasCompleter,
"/support/callhome/get": aliasCompleter,
"/support/register": aliasCompleter,
"/support/diag": aliasCompleter,
"/support/profile/start": aliasCompleter,
"/support/profile/stop": aliasCompleter,
"/support/inspect": aliasCompleter,
"/support/perf": aliasCompleter,
"/support/metrics": aliasCompleter,
"/support/callhome/set": aliasCompleter,
"/support/callhome/get": aliasCompleter,
"/support/register": aliasCompleter,
"/support/diag": aliasCompleter,
"/support/profile": aliasCompleter,
"/support/inspect": aliasCompleter,
"/support/perf": aliasCompleter,
"/support/metrics": aliasCompleter,
"/update": nil,
}
-125
View File
@@ -1,125 +0,0 @@
// 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/>.
package cmd
import (
"strings"
"github.com/minio/cli"
"github.com/minio/madmin-go"
"github.com/minio/mc/pkg/probe"
"github.com/minio/minio-go/v7/pkg/set"
"github.com/minio/pkg/console"
)
var supportProfileStartFlags = []cli.Flag{
cli.StringFlag{
Name: "type",
Usage: "start profiler type, possible values are 'cpu', 'cpuio', 'mem', 'block', 'mutex', 'trace', 'threads' and 'goroutines'",
Value: "cpu,mem,block,mutex,threads,goroutines",
},
}
var supportProfileStartCmd = cli.Command{
Name: "start",
Usage: "start recording profile data",
Action: mainSupportProfileStart,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: append(supportProfileStartFlags, globalFlags...),
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} [FLAGS] TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Start CPU profiling only
{{.Prompt}} {{.HelpName}} --type cpu myminio/
2. Start CPU, Memory and Block profiling concurrently
{{.Prompt}} {{.HelpName}} --type cpu,mem,block myminio/
`,
}
func checkAdminProfileStartSyntax(ctx *cli.Context) {
// Check flags combinations
if len(ctx.Args()) != 1 {
cli.ShowCommandHelpAndExit(ctx, "start", 1) // last argument is exit code
}
s := set.NewStringSet()
supportedProfilerTypes := []madmin.ProfilerType{
madmin.ProfilerCPU,
madmin.ProfilerMEM,
madmin.ProfilerBlock,
madmin.ProfilerMutex,
madmin.ProfilerTrace,
madmin.ProfilerThreads,
madmin.ProfilerGoroutines,
madmin.ProfilerCPUIO,
}
for _, profilerType := range supportedProfilerTypes {
s.Add(string(profilerType))
}
// Check if the provided profiler type is known and supported
supportedProfiler := false
profilers := strings.Split(strings.ToLower(ctx.String("type")), ",")
for _, profiler := range profilers {
if profiler != "" {
if s.Contains(profiler) {
supportedProfiler = true
break
}
}
}
if !supportedProfiler {
fatalIf(errDummy().Trace(ctx.String("type")),
"Profiler type unrecognized. Possible values are: %v.", supportedProfilerTypes)
}
}
// mainSupportProfileStart - the entry function of profile command
func mainSupportProfileStart(ctx *cli.Context) error {
// Check for command syntax
checkAdminProfileStartSyntax(ctx)
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
profilers := ctx.String("type")
// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
if err != nil {
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
return nil
}
// Start profile
_, cmdErr := client.StartProfiling(globalContext, madmin.ProfilerType(profilers))
fatalIf(probe.NewError(cmdErr), "Unable to start profile.")
console.Infoln("Profile data successfully started.")
return nil
}
-135
View File
@@ -1,135 +0,0 @@
// 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/>.
package cmd
import (
"io"
"io/ioutil"
"os"
"time"
"github.com/minio/cli"
"github.com/minio/mc/pkg/probe"
"github.com/minio/pkg/console"
)
var supportProfileStopCmd = cli.Command{
Name: "stop",
Usage: "stop and download profile data",
Action: mainSupportProfileStop,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: globalFlags,
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} [FLAGS] TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
2. Download latest profile data in the current directory
{{.Prompt}} {{.HelpName}} myminio/
`,
}
func checkAdminProfileStopSyntax(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
cli.ShowCommandHelpAndExit(ctx, "stop", 1) // last argument is exit code
}
}
// moveFile - os.Rename cannot handle cross device renames, in our situation
// it is possible that /tmp is mounted from a separate partition and current
// working directory is a different partition. To allow all situations to
// be handled appropriately use this function instead of os.Rename()
func moveFile(sourcePath, destPath string) error {
inputFile, err := os.Open(sourcePath)
if err != nil {
return err
}
outputFile, err := os.Create(destPath)
if err != nil {
inputFile.Close()
return err
}
defer outputFile.Close()
_, err = io.Copy(outputFile, inputFile)
inputFile.Close()
if err != nil {
return err
}
// The copy was successful, so now delete the original file
return os.Remove(sourcePath)
}
// mainSupportProfileStop - the entry function of profile stop command
func mainSupportProfileStop(ctx *cli.Context) error {
// Check for command syntax
checkAdminProfileStopSyntax(ctx)
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
if err != nil {
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
return nil
}
// Create profile zip file
tmpFile, e := ioutil.TempFile("", "mc-profile-")
fatalIf(probe.NewError(e), "Unable to download profile data.")
// Ask for profile data, which will come compressed with zip format
zippedData, adminErr := client.DownloadProfilingData(globalContext)
fatalIf(probe.NewError(adminErr), "Unable to download profile data.")
// Copy zip content to target download file
_, e = io.Copy(tmpFile, zippedData)
fatalIf(probe.NewError(e), "Unable to download profile data.")
// Close everything
zippedData.Close()
tmpFile.Close()
downloadPath := "profile.zip"
fi, e := os.Stat(downloadPath)
if e == nil && !fi.IsDir() {
e = moveFile(downloadPath, downloadPath+"."+time.Now().Format(dateTimeFormatFilename))
fatalIf(probe.NewError(e), "Unable to create a backup of profile.zip")
} else {
if !os.IsNotExist(e) {
fatal(probe.NewError(e), "Unable to download profile data.")
}
}
fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to download profile data.")
console.Infof("Profile data successfully downloaded as %s\n", downloadPath)
return nil
}
+151 -7
View File
@@ -18,13 +18,35 @@
package cmd
import (
"io"
"io/ioutil"
"log"
"os"
"strings"
"time"
"github.com/minio/cli"
"github.com/minio/madmin-go"
"github.com/minio/mc/pkg/probe"
"github.com/minio/minio-go/v7/pkg/set"
"github.com/minio/pkg/console"
)
var supportProfileSubcommands = []cli.Command{
supportProfileStartCmd,
supportProfileStopCmd,
}
// profile command flags.
var (
profileFlags = []cli.Flag{
cli.IntFlag{
Name: "duration",
Usage: "start profiling for the specified duration in seconds",
Value: 10,
},
cli.StringFlag{
Name: "type",
Usage: "profiler type, possible values are 'cpu', 'cpuio', 'mem', 'block', 'mutex', 'trace', 'threads' and 'goroutines'",
Value: "cpu,mem,block,mutex,threads,goroutines",
},
}
)
var supportProfileCmd = cli.Command{
Name: "profile",
@@ -32,13 +54,135 @@ var supportProfileCmd = cli.Command{
Action: mainSupportProfile,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: globalFlags,
Subcommands: supportProfileSubcommands,
Flags: append(profileFlags, globalFlags...),
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} [FLAGS] TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Fetch CPU profiling only
{{.Prompt}} {{.HelpName}} --type cpu myminio/
2. Fetch CPU, Memory and Block profiling concurrently
{{.Prompt}} {{.HelpName}} --type cpu,mem,block myminio/
3. Fetch CPU, Memory and Block profiling concurrently for 10 minutes
{{.Prompt}} {{.HelpName}} --type cpu,mem,block --duration 600 myminio/
`,
}
func checkAdminProfileSyntax(ctx *cli.Context) {
s := set.CreateStringSet(string(madmin.ProfilerCPU),
string(madmin.ProfilerMEM),
string(madmin.ProfilerBlock),
string(madmin.ProfilerMutex),
string(madmin.ProfilerTrace),
string(madmin.ProfilerThreads),
string(madmin.ProfilerGoroutines),
string(madmin.ProfilerCPUIO))
// Check if the provided profiler type is known and supported
profilers := strings.Split(strings.ToLower(ctx.String("type")), ",")
for _, profiler := range profilers {
if profiler != "" {
if !s.Contains(profiler) {
fatalIf(errDummy().Trace(ctx.String("type")),
"Profiler type %s unrecognized. Possible values are: %v.", profiler, s)
}
}
}
if len(ctx.Args()) != 1 {
cli.ShowCommandHelpAndExit(ctx, "profile", 1) // last argument is exit code
}
if ctx.Int("duration") < 10 {
fatal(errDummy().Trace(), "profiling must be run for atleast 10 seconds")
}
}
// moveFile - os.Rename cannot handle cross device renames, in our situation
// it is possible that /tmp is mounted from a separate partition and current
// working directory is a different partition. To allow all situations to
// be handled appropriately use this function instead of os.Rename()
func moveFile(sourcePath, destPath string) error {
inputFile, err := os.Open(sourcePath)
if err != nil {
return err
}
outputFile, err := os.Create(destPath)
if err != nil {
inputFile.Close()
return err
}
defer outputFile.Close()
_, err = io.Copy(outputFile, inputFile)
inputFile.Close()
if err != nil {
return err
}
// The copy was successful, so now delete the original file
return os.Remove(sourcePath)
}
func getProfileData(data io.ReadCloser) string {
// Create profile zip file
tmpFile, e := ioutil.TempFile("", "mc-profile-")
fatalIf(probe.NewError(e), "Unable to download profile data.")
// Copy zip content to target download file
_, e = io.Copy(tmpFile, data)
fatalIf(probe.NewError(e), "Unable to download profile data.")
// Close everything
data.Close()
tmpFile.Close()
downloadPath := "profile.zip"
downloadedFile := downloadPath + "." + time.Now().Format(dateTimeFormatFilename)
fi, e := os.Stat(downloadPath)
if e == nil && !fi.IsDir() {
e = moveFile(downloadPath, downloadedFile)
fatalIf(probe.NewError(e), "Unable to create a backup of profile.zip")
} else {
if !os.IsNotExist(e) {
fatal(probe.NewError(e), "Unable to download profile data.")
}
}
fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to download profile data.")
return downloadedFile
}
// mainSupportProfile is the handle for "mc support profile" command.
func mainSupportProfile(ctx *cli.Context) error {
commandNotFound(ctx, supportProfileSubcommands)
// Check for command syntax
checkAdminProfileSyntax(ctx)
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
profilers := ctx.String("type")
duration := ctx.Int("duration")
// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
if err != nil {
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
return nil
}
log.Printf("Collecting data for %d seconds \n", duration)
data, adminErr := client.Profile(globalContext, madmin.ProfilerType(profilers), time.Second*time.Duration(duration))
fatalIf(probe.NewError(adminErr), "Unable to download profile data.")
console.Infof(" Profile data successfully downloaded as %s\n", getProfileData(data))
return nil
}
-17
View File
@@ -302,7 +302,6 @@ Skip SSL certificate verification.
| [**policy** - manage canned policies](#policy) |
| [**config** - manage server configuration file](#config) |
| [**heal** - heal disks, buckets and objects on MinIO server](#heal) |
| [**profile** - generate profile data for debugging purposes](#profile) |
| [**top** - provide top like statistics for MinIO](#top) |
| [**trace** - show http trace for MinIO server](#trace) |
| [**console** - show console logs for MinIO server](#console) |
@@ -647,22 +646,6 @@ mc admin config import myminio < /tmp/my-serverconfig
### Command `heal` - Heal disks, buckets and objects on MinIO server
Healing is automatic on server side which runs on a continuous basis on a low priority thread, `mc admin heal` is deprecated and will be removed in future.
<a name="profile"></a>
### Command `profile` - generate profile data for debugging purposes
```
NAME:
mc admin profile - generate profile data for debugging purposes
COMMANDS:
start start recording profile data
stop stop and download profile data
```
Start CPU profiling
```
mc admin profile start --type cpu myminio/
```
<a name="top"></a>
### Command `top` - provide top like statistics for MinIO
+47 -1
View File
@@ -34,6 +34,7 @@ tag manage tags for bucket(s) and object(s)
replicate configure server side bucket replication
admin manage MinIO servers
update update mc to latest release
support supportability tools like profile, register, callhome, inspect
```
## 1. Download MinIO Client
@@ -323,7 +324,7 @@ mc version RELEASE.2020-04-25T00-43-23Z
| [**alias** - manage aliases](#alias) | [**policy** - set public policy on bucket or prefix](#policy) | [**event** - manage events on your buckets](#event) | [**encrypt** - manage bucket encryption](#encrypt) |
| [**update** - manage software updates](#update) | [**watch** - watch for events](#watch) | [**retention** - set retention for object(s)](#retention) | [**sql** - run sql queries on objects](#sql) |
| [**head** - display first 'n' lines of an object](#head) | [**stat** - stat contents of objects and folders](#stat) | [**legalhold** - set legal hold for object(s)](#legalhold) | [**mv** - move objects](#mv) |
| [**du** - summarize disk usage recursively](#du) | [**tag** - manage tags for bucket and object(s)](#tag) | [**admin** - manage MinIO servers](#admin) | |
| [**du** - summarize disk usage recursively](#du) | [**tag** - manage tags for bucket and object(s)](#tag) | [**admin** - manage MinIO servers](#admin) | [**support** - generate profile data for debugging purposes](#support) |
@@ -1908,3 +1909,48 @@ mc replicate resync start myminio/mybucket --remote-bucket "arn:minio:replicatio
```
mc replicate resync status myminio/mybucket --remote-bucket "arn:minio:replication::xxx:mybucket"
```
<a name="support"></a>
### Command `support` - support related commands
```
NAME:
mc support register register with MinIO subscription network
mc support callhome configure callhome settings
mc support diag, diagnostics upload health data for diagnostics
mc support perf analyze object, network and drive performance
mc support inspect upload raw object contents for analysis
mc support profile generate profile data for debugging
```
Register MinIO cluster at alias 'play' on SUBNET, using the name "play-cluster".
```
mc support register play --name play-cluster
```
Enable logs callhome for cluster with alias 'play'.
```
mc support callhome set play logs=on
```
Download 'xl.meta' for a specific object from all the drives in a zip file.
```
mc support inspect myminio/bucket/test*/xl.meta
```
Run object speed measurement with autotuning the concurrency to obtain maximum throughput and IOPs.
```
mc support perf object myminio/
```
Upload MinIO diagnostics report for 'play' (https://play.min.io by default) to SUBNET
```
mc support diag play
```
Get CPU profiling for 2 minutes
```
mc support profile --type cpu --duration 120 myminio/
```
+3
View File
@@ -62,6 +62,7 @@ github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqO
github.com/briandowns/spinner v1.18.1 h1:yhQmQtM1zsqFsouh09Bk/jCjd50pC3EOGsh28gLVvwY=
github.com/briandowns/spinner v1.18.1/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/ppAL/hX5SmPJU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
@@ -273,6 +274,7 @@ github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
@@ -343,6 +345,7 @@ github.com/minio/colorjson v1.0.2/go.mod h1:JWxcL2n8T8JVf+NY6awl6kn5nK49aAzHOeQE
github.com/minio/filepath v1.0.0 h1:fvkJu1+6X+ECRA6G3+JJETj4QeAYO9sV43I79H8ubDY=
github.com/minio/filepath v1.0.0/go.mod h1:/nRZA2ldl5z6jT9/KQuvZcQlxZIMQoFFQPvEXx9T/Bw=
github.com/minio/madmin-go v1.3.5/go.mod h1:vGKGboQgGIWx4DuDUaXixjlIEZOCIp6ivJkQoiVaACc=
github.com/minio/madmin-go v1.3.11/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98=
github.com/minio/madmin-go v1.3.13 h1:157u3bFK9qh2EkkqjpJ/bwOw/5KonXUWqhKP3ZczAdY=
github.com/minio/madmin-go v1.3.13/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98=
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=