From c554b2a6cbfbecb6eac1d819e6e9c6b055d0b166 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Wed, 8 Jul 2026 13:44:45 +0200 Subject: [PATCH] add printer.ByteString() as shortcut --- pkg/es/node.go | 14 ++++++++------ pkg/printer/bytes.go | 9 +++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/es/node.go b/pkg/es/node.go index f9a377a..84c10b5 100644 --- a/pkg/es/node.go +++ b/pkg/es/node.go @@ -26,7 +26,6 @@ import ( "codeberg.org/scip/esctl/pkg/cfg" "codeberg.org/scip/esctl/pkg/printer" - "github.com/dustin/go-humanize" ) 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}, {"Node roles", roles}, {"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}, {"CPUs", *info.Os.AllocatedProcessors}, {"Load 15m/5m/1m", fmt.Sprintf("%.2f/%.2f/%.2f", @@ -139,10 +141,10 @@ func NodeShow(conf *cfg.Config, nodename string) error { *stat.Http.TotalOpened, )}, {"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)}, {"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", stat.Indices.Search.QueryCurrent, stat.Indices.Search.QueryTotal, @@ -158,8 +160,8 @@ func NodeShow(conf *cfg.Config, nodename string) error { stat.Indices.Merges.TotalDocs, )}, {"Merge size current/total", fmt.Sprintf("%s/%s", - printer.Bytes(stat.Indices.Merges.CurrentSizeInBytes).String(), - printer.Bytes(stat.Indices.Merges.TotalSizeInBytes).String(), + printer.ByteString(stat.Indices.Merges.CurrentSizeInBytes), + printer.ByteString(stat.Indices.Merges.TotalSizeInBytes), )}, {"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 { fs := stat.Fs.Data[0] 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) } diff --git a/pkg/printer/bytes.go b/pkg/printer/bytes.go index 6408f2c..87cac11 100644 --- a/pkg/printer/bytes.go +++ b/pkg/printer/bytes.go @@ -22,10 +22,15 @@ type ByteSize struct { size uint64 } +func (b *ByteSize) String() string { + return humanize.Bytes(b.size) +} + func Bytes(size int64) *ByteSize { return &ByteSize{size: uint64(size)} } -func (b *ByteSize) String() string { - return humanize.Bytes(b.size) +func ByteString(size int64) string { + b := ByteSize{size: uint64(size)} + return b.String() }