From 4be483de6d36a8fbdace1785173c4c28b83eee4f Mon Sep 17 00:00:00 2001 From: Anis Eleuch Date: Tue, 3 Oct 2023 08:31:31 -0700 Subject: [PATCH] scanner: Limit the active disks if no enough term space (#4705) If the terminal height is not enough to show the number of active disks, which is likely the case in a large deployment, print only a few entries until the number of lines reaches the terminal height. --- cmd/admin-scanner-status.go | 26 +++++++++++++++++++------- cmd/globals.go | 4 ++-- cmd/main.go | 6 +++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/cmd/admin-scanner-status.go b/cmd/admin-scanner-status.go index e804b8ac..5bafffe8 100644 --- a/cmd/admin-scanner-status.go +++ b/cmd/admin-scanner-status.go @@ -229,14 +229,19 @@ func (m *scannerMetricsUI) View() string { table.SetAlignment(tablewriter.ALIGN_LEFT) table.SetBorder(true) table.SetRowLine(false) + + writtenRows := 0 addRow := func(s string) { table.Append([]string{s}) + writtenRows++ } _ = addRow addRowF := func(format string, vals ...interface{}) { s := fmt.Sprintf(format, vals...) table.Append([]string{s}) + writtenRows++ } + sc := m.current.Aggregated.Scanner if sc == nil { s.WriteString("(waiting for data)") @@ -338,14 +343,27 @@ func (m *scannerMetricsUI) View() string { } addRowF(title("Yield:")+" %v total; Avg: %s", metricsDuration(time.Duration(x.AccTime)), avg) } + if errs := m.current.Errors; len(errs) > 0 { + addRow("------------------------------------------- Errors --------------------------------------------------") + for _, s := range errs { + addRow(console.Colorize("metrics-error", s)) + } + } if m.maxPaths != 0 && len(sc.ActivePaths) > 0 { addRow("------------------------------------- Currently Scanning Paths --------------------------------------") - const length = 100 + length := 100 + if globalTermWidth > 5 { + length = globalTermWidth + } for i, s := range sc.ActivePaths { if i == m.maxPaths { break } + if globalTermHeight > 5 && writtenRows >= globalTermHeight-5 { + addRow(console.Colorize("metrics-path", fmt.Sprintf("( ... hiding %d more disk(s) .. )", len(sc.ActivePaths)-i))) + break + } if len(s) > length { s = s[:length-3] + "..." } @@ -353,12 +371,6 @@ func (m *scannerMetricsUI) View() string { addRow(console.Colorize("metrics-path", s)) } } - if errs := m.current.Errors; len(errs) > 0 { - addRow("------------------------------------------- Errors --------------------------------------------------") - for _, s := range errs { - addRow(console.Colorize("metrics-error", s)) - } - } table.Render() return s.String() } diff --git a/cmd/globals.go b/cmd/globals.go index 64e4ec26..88124631 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -82,8 +82,8 @@ var ( ) var ( - // Terminal width - globalTermWidth int + // Terminal height/width, zero if not found + globalTermWidth, globalTermHeight int globalHelpPager *termPager diff --git a/cmd/main.go b/cmd/main.go index db5c34b2..db76106d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -33,7 +33,6 @@ import ( "syscall" "time" - "github.com/cheggaaa/pb" "github.com/inconshreveable/mousetrap" "github.com/minio/cli" "github.com/minio/mc/pkg/probe" @@ -42,6 +41,7 @@ import ( "github.com/minio/pkg/v2/env" "github.com/minio/pkg/v2/trie" "github.com/minio/pkg/v2/words" + "golang.org/x/term" completeinstall "github.com/posener/complete/cmd/install" ) @@ -117,10 +117,10 @@ func Main(args []string) error { // Fetch terminal size, if not available, automatically // set globalQuiet to true. - if w, e := pb.GetTerminalWidth(); e != nil { + if w, h, e := term.GetSize(int(os.Stdin.Fd())); e != nil { globalQuiet = true } else { - globalTermWidth = w + globalTermWidth, globalTermHeight = w, h } // Set the mc app name.