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.
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
+2
-2
@@ -82,8 +82,8 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
// Terminal width
|
||||
globalTermWidth int
|
||||
// Terminal height/width, zero if not found
|
||||
globalTermWidth, globalTermHeight int
|
||||
|
||||
globalHelpPager *termPager
|
||||
|
||||
|
||||
+3
-3
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user