add printer.ByteString() as shortcut

This commit is contained in:
2026-07-08 13:44:45 +02:00
parent b20f3b39a3
commit 56c636fa2a
2 changed files with 15 additions and 8 deletions

View File

@@ -26,7 +26,6 @@ import (
"codeberg.org/scip/esctl/pkg/cfg" "codeberg.org/scip/esctl/pkg/cfg"
"codeberg.org/scip/esctl/pkg/printer" "codeberg.org/scip/esctl/pkg/printer"
"github.com/dustin/go-humanize"
) )
func NodeList(conf *cfg.Config) error { func NodeList(conf *cfg.Config) error {
@@ -126,6 +125,9 @@ func NodeShow(conf *cfg.Config, nodename string) error {
{"OS", info.Os.PrettyName + " " + info.Os.Version}, {"OS", info.Os.PrettyName + " " + info.Os.Version},
{"Node roles", roles}, {"Node roles", roles},
{"Node version", info.Version}, {"Node version", info.Version},
// FIXME: not implementet upstream
// see: https://github.com/elastic/go-elasticsearch/issues/1526
//{"Allocated shards", stat.Allocations.XXX},
{"HTTP clients", *stat.Http.CurrentOpen}, {"HTTP clients", *stat.Http.CurrentOpen},
{"CPUs", *info.Os.AllocatedProcessors}, {"CPUs", *info.Os.AllocatedProcessors},
{"Load 15m/5m/1m", fmt.Sprintf("%.2f/%.2f/%.2f", {"Load 15m/5m/1m", fmt.Sprintf("%.2f/%.2f/%.2f",
@@ -139,10 +141,10 @@ func NodeShow(conf *cfg.Config, nodename string) error {
*stat.Http.TotalOpened, *stat.Http.TotalOpened,
)}, )},
{"Traffic rx/tx", {"Traffic rx/tx",
printer.Bytes(*stat.Transport.RxSizeInBytes).String() + " / " + printer.Bytes(*stat.Transport.TxSizeInBytes).String()}, printer.ByteString(*stat.Transport.RxSizeInBytes) + " / " + printer.ByteString(*stat.Transport.TxSizeInBytes)},
{"Response time avg", time.Duration(*stat.AdaptiveSelection[id].AvgResponseTimeNs)}, {"Response time avg", time.Duration(*stat.AdaptiveSelection[id].AvgResponseTimeNs)},
{"Memory usage (used/avail)", {"Memory usage (used/avail)",
humanize.Bytes(uint64(*stat.Os.Mem.UsedInBytes)) + " / " + humanize.Bytes(uint64(*stat.Os.Mem.TotalInBytes))}, printer.ByteString(*stat.Os.Mem.UsedInBytes) + " / " + printer.ByteString(*stat.Os.Mem.TotalInBytes)},
{"Search queries current/total", fmt.Sprintf("%d/%d", {"Search queries current/total", fmt.Sprintf("%d/%d",
stat.Indices.Search.QueryCurrent, stat.Indices.Search.QueryCurrent,
stat.Indices.Search.QueryTotal, stat.Indices.Search.QueryTotal,
@@ -158,8 +160,8 @@ func NodeShow(conf *cfg.Config, nodename string) error {
stat.Indices.Merges.TotalDocs, stat.Indices.Merges.TotalDocs,
)}, )},
{"Merge size current/total", fmt.Sprintf("%s/%s", {"Merge size current/total", fmt.Sprintf("%s/%s",
printer.Bytes(stat.Indices.Merges.CurrentSizeInBytes).String(), printer.ByteString(stat.Indices.Merges.CurrentSizeInBytes),
printer.Bytes(stat.Indices.Merges.TotalSizeInBytes).String(), printer.ByteString(stat.Indices.Merges.TotalSizeInBytes),
)}, )},
{"CircuitBreaker trip count", *stat.Breakers["fielddata"].Tripped}, {"CircuitBreaker trip count", *stat.Breakers["fielddata"].Tripped},
} }
@@ -167,7 +169,7 @@ func NodeShow(conf *cfg.Config, nodename string) error {
if len(stat.Fs.Data) > 0 { if len(stat.Fs.Data) > 0 {
fs := stat.Fs.Data[0] fs := stat.Fs.Data[0]
table.AddRow("Storage usage (used/avail)", table.AddRow("Storage usage (used/avail)",
printer.Bytes(*fs.AvailableInBytes).String()+" / "+printer.Bytes(*fs.TotalInBytes).String()) printer.ByteString(*fs.AvailableInBytes)+" / "+printer.ByteString(*fs.TotalInBytes))
table.AddRow("Storage mount", *fs.Mount) table.AddRow("Storage mount", *fs.Mount)
} }

View File

@@ -22,10 +22,15 @@ type ByteSize struct {
size uint64 size uint64
} }
func (b *ByteSize) String() string {
return humanize.Bytes(b.size)
}
func Bytes(size int64) *ByteSize { func Bytes(size int64) *ByteSize {
return &ByteSize{size: uint64(size)} return &ByteSize{size: uint64(size)}
} }
func (b *ByteSize) String() string { func ByteString(size int64) string {
return humanize.Bytes(b.size) b := ByteSize{size: uint64(size)}
return b.String()
} }