Files
mc/cmd/support-top-api.go
T
Klaus Post 0793ce767b Add --stats to traces (#4669)
Allows collecting live stats of all traced subsystems.

Examples:

```
λ mc admin trace --stats play
+----------------------------+-------------+------+-----------+--------+---------+---------+
| Call                       | Count       | RPM  | Avg Time  | Errors | RX Avg  | TX Avg  |
| s3.GetObject               | 247 (63.3%) | 82.5 | 2.391ms   | 0      | 133 B   | 179 KiB |
| s3.HeadBucket              | 102 (26.2%) | 34.1 | 1.114ms   | 0      | 147 B   | 0 B     |
| s3.GetBucketLocation       | 18 (4.6%)   | 6.0  | 1.942ms   | 0      | 147 B   | 149 B   |
| s3.PutBucket               | 6 (1.5%)    | 2.0  | 4.146ms   | 0      | 151 B   | 0 B     |
| s3.ListObjectsV1           | 4 (1.0%)    | 1.3  | 4.276ms   | 0      | 124 B   | 577 B   |
| s3.ListBuckets             | 3 (0.8%)    | 1.0  | 15.312ms  | 0      | 135 B   | 82 KiB  |
| s3.PutObject               | 3 (0.8%)    | 1.0  | 4.304ms   | 0      | 14 KiB  | 0 B     |
| s3.DeleteObject            | 2 (0.5%)    | 0.7  | 407µs     | 0      | 88 B    | 0 B     |
| s3.HeadObject              | 2 (0.5%)    | 0.7  | 1.36ms    | 0      | 108 B   | 0 B     |
| s3.CompleteMultipartUpload | 1 (0.3%)    | 0.3  | 7.943ms   | 0      | 301 B   | 449 B   |
| s3.NewMultipartUpload      | 1 (0.3%)    | 0.3  | 4.895ms   | 0      | 160 B   | 383 B   |
| s3.PutObjectPart           | 1 (0.3%)    | 0.3  | 103.782ms | 0      | 8.8 MiB | 0 B     |
+----------------------------+-------------+------+-----------+--------+---------+---------+

λ mc admin trace --stats -call=storage play
+------------------------------+---------------+----------+----------+--------+--------+--------+
| Call                         | Count         | RPM      | Avg Time | Errors | RX Avg | TX Avg |
| storage.ReadXL               | 70780 (33.3%) | 174700.3 | 43µs     | 200    | -      | -      |
| storage.RenameData           | 70633 (33.2%) | 174337.5 | 1.165ms  | 0      | -      | -      |
| storage.DiskInfo             | 70540 (33.1%) | 174107.9 | 1µs      | 0      | -      | -      |
| storage.ReadVersion          | 280 (0.1%)    | 691.1    | 70µs     | 0      | -      | -      |
| storage.StatVol              | 236 (0.1%)    | 582.5    | 13µs     | 0      | -      | -      |
| storage.DeleteAbandonedParts | 140 (0.1%)    | 345.6    | 149µs    | 0      | -      | -      |
| storage.CreateFile           | 88 (0.0%)     | 217.2    | 4.169ms  | 0      | -      | -      |
| storage.ListVols             | 88 (0.0%)     | 217.2    | 426µs    | 0      | -      | -      |
| storage.ReadFileStream       | 18 (0.0%)     | 44.4     | 28µs     | 0      | -      | -      |
| storage.VerifyFile           | 16 (0.0%)     | 39.5     | 2.166ms  | 0      | -      | -      |
+------------------------------+---------------+----------+----------+--------+--------+--------+
```
2023-10-10 10:12:06 -07:00

130 lines
3.5 KiB
Go

// Copyright (c) 2015-2023 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"
tea "github.com/charmbracelet/bubbletea"
"github.com/minio/cli"
"github.com/minio/madmin-go/v3"
"github.com/minio/mc/pkg/probe"
)
var supportTopAPIFlags = []cli.Flag{
cli.StringSliceFlag{
Name: "name",
Usage: "summarize current calls for matching API name",
},
cli.StringSliceFlag{
Name: "path",
Usage: "summarize current API calls only on matching path",
},
cli.StringSliceFlag{
Name: "node",
Usage: "summarize current API calls only on matching servers",
},
cli.BoolFlag{
Name: "errors, e",
Usage: "summarize current API calls throwing only errors",
},
}
var supportTopAPICmd = cli.Command{
Name: "api",
Usage: "summarize API events on MinIO server in real-time",
Action: mainSupportTopAPI,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: append(supportTopAPIFlags, supportGlobalFlags...),
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} [FLAGS] TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Display current in-progress all S3 API calls.
{{.Prompt}} {{.HelpName}} myminio/
2. Display current in-progress all 's3.PutObject' API calls.
{{.Prompt}} {{.HelpName}} --name s3.PutObject myminio/
`,
}
// checkSupportTopAPISyntax - validate all the passed arguments
func checkSupportTopAPISyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
showCommandHelpAndExit(ctx, 1) // last argument is exit code
}
}
func mainSupportTopAPI(ctx *cli.Context) error {
checkSupportTopAPISyntax(ctx)
aliasedURL := ctx.Args().Get(0)
alias, _ := url2Alias(aliasedURL)
validateClusterRegistered(alias, false)
// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
if err != nil {
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
return nil
}
ctxt, cancel := context.WithCancel(globalContext)
defer cancel()
opts, e := tracingOpts(ctx, ctx.StringSlice("call"))
fatalIf(probe.NewError(e), "Unable to start tracing")
mopts := matchingOpts(ctx)
// Start listening on all trace activity.
traceCh := client.ServiceTrace(ctxt, opts)
p := tea.NewProgram(initTraceUI())
go func() {
for apiCallInfo := range traceCh {
if apiCallInfo.Err != nil {
fatalIf(probe.NewError(apiCallInfo.Err), "Unable to fetch top API events")
}
if mopts.matches(apiCallInfo) {
p.Send(topAPIResult{
apiCallInfo: apiCallInfo,
})
}
p.Send(topAPIResult{
apiCallInfo: madmin.ServiceTraceInfo{},
})
}
}()
if _, e := p.Run(); e != nil {
cancel()
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to fetch top API events")
}
return nil
}