Remove mc admin bucket remote bandwidth command and introduce (#4430)
This commit is contained in:
@@ -1,195 +0,0 @@
|
||||
// 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 (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminBandwidthInfoCmdFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "unit",
|
||||
Value: "b",
|
||||
Usage: "[b|bi|B|Bi] Display bandwidth in bits (IEC [bi] or SI [b]) or bytes (IEC [Bi] or SI [B])",
|
||||
},
|
||||
}
|
||||
|
||||
var adminBwInfoCmd = cli.Command{
|
||||
Name: "bandwidth",
|
||||
Usage: "Show bandwidth info for buckets on the MinIO server in bits or bytes per second. Ki,Bi,Mi,Gi represent IEC units.",
|
||||
Action: mainAdminBwInfo,
|
||||
Before: setGlobalsFromContext,
|
||||
OnUsageError: onUsageError,
|
||||
Flags: append(globalFlags, adminBandwidthInfoCmdFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} FLAGS TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Show the bandwidth usage for all the buckets in a MinIO server setup
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. Show the bandwidth usage for the bucket 'source-bucket' in a MinIO server setup
|
||||
{{.Prompt}} {{.HelpName}} play/source-bucket
|
||||
`,
|
||||
}
|
||||
|
||||
func printTable(report madmin.Report, bits bool, iec bool) {
|
||||
bucketMaxLength := 63
|
||||
bucketColLength := 6
|
||||
var bucketKeys []string
|
||||
for bucket := range report.Report.BucketStats {
|
||||
if len(bucket) <= bucketMaxLength && len(bucket) > bucketColLength {
|
||||
bucketColLength = len(bucket)
|
||||
}
|
||||
bucketKeys = append(bucketKeys, bucket)
|
||||
}
|
||||
sort.Strings(bucketKeys)
|
||||
dspOrder := []col{colGreen} // Header
|
||||
for i := 0; i < len(report.Report.BucketStats); i++ {
|
||||
dspOrder = append(dspOrder, colGrey)
|
||||
}
|
||||
var printColors []*color.Color
|
||||
for _, c := range dspOrder {
|
||||
printColors = append(printColors, getPrintCol(c))
|
||||
}
|
||||
|
||||
cellText := make([][]string, len(report.Report.BucketStats)+1) // 1 for the header
|
||||
tbl := console.NewTable(printColors, []bool{false, false, false}, 0)
|
||||
bucketTitle := fmt.Sprintf("%-16v", "Bucket")
|
||||
cellText[0] = []string{
|
||||
bucketTitle,
|
||||
"Configured Max Bandwidth",
|
||||
"Current Bandwidth",
|
||||
}
|
||||
tbl.HeaderRowSeparator = true
|
||||
index := 1
|
||||
|
||||
for _, bucket := range bucketKeys {
|
||||
values := report.Report.BucketStats[bucket]
|
||||
if len(bucket) > bucketMaxLength {
|
||||
bucket = bucket[:bucketMaxLength] + ".."
|
||||
}
|
||||
var mul uint64
|
||||
mul = 1
|
||||
if bits {
|
||||
mul = 8
|
||||
}
|
||||
limit := humanize.Bytes(uint64(values.LimitInBytesPerSecond) * mul)
|
||||
current := humanize.Bytes(uint64(values.CurrentBandwidthInBytesPerSecond) * mul)
|
||||
if iec {
|
||||
limit = humanize.IBytes(uint64(values.LimitInBytesPerSecond)*mul) + "/sec"
|
||||
current = humanize.IBytes(uint64(values.CurrentBandwidthInBytesPerSecond)*mul) + "/sec"
|
||||
}
|
||||
if bits {
|
||||
limit = strings.ToLower(limit) + "/sec"
|
||||
current = strings.ToLower(current) + "/sec"
|
||||
}
|
||||
if values.LimitInBytesPerSecond == 0 {
|
||||
limit = "N/A" // N/A means cluster bandwidth is not configured
|
||||
}
|
||||
cellText[index] = []string{
|
||||
bucket,
|
||||
limit,
|
||||
current,
|
||||
}
|
||||
index++
|
||||
}
|
||||
if len(report.Report.BucketStats) > 0 {
|
||||
if e := tbl.DisplayTable(cellText); e != nil {
|
||||
console.Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkAdminBwInfoSyntax(ctx *cli.Context) {
|
||||
u := ctx.String("unit")
|
||||
if u != "bi" &&
|
||||
u != "b" &&
|
||||
u != "Bi" &&
|
||||
u != "B" &&
|
||||
u != "" {
|
||||
showCommandHelpAndExit(ctx, globalErrorExitStatus)
|
||||
}
|
||||
if len(ctx.Args()) > 1 || len(ctx.Args()) == 0 {
|
||||
showCommandHelpAndExit(ctx, globalErrorExitStatus)
|
||||
}
|
||||
}
|
||||
|
||||
func mainAdminBwInfo(ctx *cli.Context) {
|
||||
checkAdminBwInfoSyntax(ctx)
|
||||
aliasURL, bucket := getAliasAndBucket(ctx)
|
||||
client := getClient(aliasURL)
|
||||
reportCh := client.GetBucketBandwidth(globalContext, bucket)
|
||||
firstPrint := true
|
||||
bandwidthUnitsString := ctx.String("unit")
|
||||
for {
|
||||
select {
|
||||
case report := <-reportCh:
|
||||
if len(report.Report.BucketStats) == 0 {
|
||||
continue
|
||||
}
|
||||
if report.Err != nil {
|
||||
if strings.Contains(report.Err.Error(), "EOF") {
|
||||
continue
|
||||
}
|
||||
console.Error(report.Err)
|
||||
}
|
||||
printBandwidth(report, firstPrint, bandwidthUnitsString == "bi" || bandwidthUnitsString == "b",
|
||||
bandwidthUnitsString == "bi" || bandwidthUnitsString == "Bi")
|
||||
firstPrint = false
|
||||
case <-globalContext.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printBandwidth(report madmin.Report, firstPrint bool, bits bool, iec bool) {
|
||||
rewindLines := len(report.Report.BucketStats) + 4
|
||||
if firstPrint {
|
||||
rewindLines = 0
|
||||
}
|
||||
if globalJSON {
|
||||
reportJSON, e := json.MarshalIndent(report, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal to JSON")
|
||||
console.Println(string(reportJSON))
|
||||
time.Sleep(1 * time.Second)
|
||||
return
|
||||
}
|
||||
if len(report.Report.BucketStats) > 0 {
|
||||
console.RewindLines(rewindLines)
|
||||
// For the next iteration, rewind lines
|
||||
printTable(report, bits, iec)
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
@@ -23,8 +23,6 @@ var adminBucketRemoteSubcommands = []cli.Command{
|
||||
adminBucketRemoteAddCmd,
|
||||
adminBucketRemoteEditCmd,
|
||||
adminBucketRemoteRmCmd,
|
||||
|
||||
adminBwInfoCmd,
|
||||
}
|
||||
|
||||
var adminBucketRemoteCmd = cli.Command{
|
||||
|
||||
@@ -419,12 +419,11 @@ var completeCmds = map[string]complete.Predictor{
|
||||
"/admin/group/remove": aliasCompleter,
|
||||
"/admin/group/info": aliasCompleter,
|
||||
|
||||
"/admin/bucket/remote/add": aliasCompleter,
|
||||
"/admin/bucket/remote/edit": aliasCompleter,
|
||||
"/admin/bucket/remote/rm": aliasCompleter,
|
||||
"/admin/bucket/remote/bandwidth": aliasCompleter,
|
||||
"/admin/bucket/quota": aliasCompleter,
|
||||
"/admin/bucket/info": s3Complete{deepLevel: 2},
|
||||
"/admin/bucket/remote/add": aliasCompleter,
|
||||
"/admin/bucket/remote/edit": aliasCompleter,
|
||||
"/admin/bucket/remote/rm": aliasCompleter,
|
||||
"/admin/bucket/quota": aliasCompleter,
|
||||
"/admin/bucket/info": s3Complete{deepLevel: 2},
|
||||
|
||||
"/admin/kms/key/create": aliasCompleter,
|
||||
"/admin/kms/key/status": aliasCompleter,
|
||||
|
||||
+30
-8
@@ -78,6 +78,7 @@ func (s replicateStatusMessage) JSON() string {
|
||||
|
||||
func (s replicateStatusMessage) String() string {
|
||||
coloredDot := console.Colorize("Headers", dot)
|
||||
|
||||
maxLen := 15
|
||||
var contents [][]string
|
||||
|
||||
@@ -94,7 +95,7 @@ func (s replicateStatusMessage) String() string {
|
||||
s.ReplicationStatus.ReplicatedSize == 0 {
|
||||
return "Replication status not available."
|
||||
}
|
||||
r := console.Colorize("THeaders", newPrettyTable(" | ",
|
||||
r := console.Colorize("THeaderBold", newPrettyTable(" | ",
|
||||
Field{"Summary", 95},
|
||||
).buildRow("Summary: "))
|
||||
rows += r
|
||||
@@ -136,8 +137,8 @@ func (s replicateStatusMessage) String() string {
|
||||
sort.Strings(arns)
|
||||
if len(arns) > 0 {
|
||||
rows += "\n"
|
||||
r := console.Colorize("THeaders", newPrettyTable(" | ",
|
||||
Field{"Target statuses", 95},
|
||||
r := console.Colorize("THeaderBold", newPrettyTable(" | ",
|
||||
Field{"Target statuses", 120},
|
||||
).buildRow("Remote Target Statuses: "))
|
||||
rows += r
|
||||
rows += "\n"
|
||||
@@ -157,21 +158,40 @@ func (s replicateStatusMessage) String() string {
|
||||
var hdrStr, hdrDet string
|
||||
hdrStr = ep
|
||||
if hdrStr != "" {
|
||||
hdrDet = arn
|
||||
hdrDet = console.Colorize("Values", arn)
|
||||
} else {
|
||||
hdrStr = arn
|
||||
}
|
||||
r := console.Colorize(th, newPrettyTable(" | ",
|
||||
Field{"Ep", 120},
|
||||
Field{"Ep", 100},
|
||||
).buildRow(fmt.Sprintf("%s %s", coloredDot, hdrStr)))
|
||||
rows += r
|
||||
rows += "\n"
|
||||
if hdrDet != "" {
|
||||
r = console.Colorize("THeader", newPrettyTable(" | ",
|
||||
Field{"Arn", 120},
|
||||
).buildRow(" "+hdrDet))
|
||||
Field{"Arn", 100},
|
||||
).buildRow(" "+"ARN: "+hdrDet))
|
||||
rows += r
|
||||
rows += "\n"
|
||||
bwStat, ok := s.ReplicationStatus.Stats[arn]
|
||||
if ok && bwStat.BandWidthLimitInBytesPerSecond > 0 {
|
||||
limit := humanize.Bytes(uint64(bwStat.BandWidthLimitInBytesPerSecond))
|
||||
current := humanize.Bytes(uint64(bwStat.CurrentBandwidthInBytesPerSecond))
|
||||
if bwStat.BandWidthLimitInBytesPerSecond == 0 {
|
||||
limit = "N/A" // N/A means cluster bandwidth is not configured
|
||||
}
|
||||
|
||||
r = console.Colorize("THeaderBold", newPrettyTable("",
|
||||
Field{"B/w limit Hdr", 80},
|
||||
).buildRow(" Configured Max Bandwidth (Bps): "+console.Colorize("Values", limit)))
|
||||
rows += r
|
||||
rows += "\n"
|
||||
r = console.Colorize("THeaderBold", newPrettyTable("",
|
||||
Field{"B/w limit Hdr", 80},
|
||||
).buildRow(" Current Bandwidth (Bps): "+console.Colorize("Values", current)))
|
||||
rows += r
|
||||
}
|
||||
rows += "\n"
|
||||
}
|
||||
rows += console.Colorize("TgtHeaders", newPrettyTable(" | ",
|
||||
Field{"Status", 21},
|
||||
@@ -201,10 +221,12 @@ func mainReplicateStatus(cliCtx *cli.Context) error {
|
||||
ctx, cancelReplicateStatus := context.WithCancel(globalContext)
|
||||
defer cancelReplicateStatus()
|
||||
|
||||
console.SetColor("THeaders", color.New(color.Bold, color.FgHiWhite))
|
||||
console.SetColor("THeader", color.New(color.FgWhite))
|
||||
|
||||
console.SetColor("Headers", color.New(color.Bold, color.FgGreen))
|
||||
console.SetColor("Values", color.New(color.FgGreen))
|
||||
console.SetColor("THeaderBold", color.New(color.FgWhite))
|
||||
|
||||
console.SetColor("TgtHeaders", color.New(color.Bold, color.FgCyan))
|
||||
|
||||
console.SetColor("Replica", color.New(color.FgCyan))
|
||||
|
||||
@@ -34,7 +34,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/mattn/go-ieproxy"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v2"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/encrypt"
|
||||
@@ -420,13 +419,6 @@ func centerText(s string, w int) string {
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func getAliasAndBucket(ctx *cli.Context) (string, string) {
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
aliasedURL = filepath.Clean(aliasedURL)
|
||||
return url2Alias(aliasedURL)
|
||||
}
|
||||
|
||||
func getClient(aliasURL string) *madmin.AdminClient {
|
||||
client, err := newAdminClient(aliasURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
Reference in New Issue
Block a user