From c6f0d7f436b23dac1ba961d5582250fdc202e1a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20K=C3=A4stle?= Date: Tue, 9 Jun 2026 15:17:25 +0200 Subject: [PATCH] Replace go-humanize with go-check/convert --- cmd/filesystem.go | 14 +++++++------- cmd/memory.go | 16 ++++++++-------- go.mod | 1 - go.sum | 2 -- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/cmd/filesystem.go b/cmd/filesystem.go index 59b977f..2d37289 100644 --- a/cmd/filesystem.go +++ b/cmd/filesystem.go @@ -11,9 +11,9 @@ import ( "github.com/NETWAYS/check_system_basics/internal/common/thresholds" "github.com/NETWAYS/check_system_basics/internal/filesystem" "github.com/NETWAYS/go-check" + "github.com/NETWAYS/go-check/convert" "github.com/NETWAYS/go-check/perfdata" "github.com/NETWAYS/go-check/result" - "github.com/dustin/go-humanize" "github.com/shirou/gopsutil/v3/disk" "github.com/spf13/cobra" ) @@ -356,7 +356,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem if config.WarningAbsolutThreshold.Space.Free.Th.DoesViolate(float64(fs.UsageStats.Free)) { _ = tmpPartialResult.SetState(check.Warning) - tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", humanize.IBytes(fs.UsageStats.Free), humanize.IBytes(fs.UsageStats.Total)) + tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Free).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) } } @@ -365,12 +365,12 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem if config.CriticalAbsolutThreshold.Space.Free.Th.DoesViolate(float64(fs.UsageStats.Free)) { _ = tmpPartialResult.SetState(check.Critical) - tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", humanize.IBytes(fs.UsageStats.Free), humanize.IBytes(fs.UsageStats.Total)) + tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Free).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) } } if tmpPartialResult.GetStatus() == check.OK { - tmpPartialResult.Output = fmt.Sprintf("Absolute free space: %s / %s", humanize.IBytes(fs.UsageStats.Free), humanize.IBytes(fs.UsageStats.Total)) + tmpPartialResult.Output = fmt.Sprintf("Absolute free space: %s / %s", convert.BytesIEC(fs.UsageStats.Free).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) } tmpPartialResult.Perfdata.Add(&pdAbsoluteFreeSpace) @@ -397,7 +397,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem if config.WarningAbsolutThreshold.Space.Used.Th.DoesViolate(float64(fs.UsageStats.Used)) { _ = tmpPartialResult.SetState(check.Warning) - tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", humanize.IBytes(fs.UsageStats.Used), humanize.IBytes(fs.UsageStats.Total)) + tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Used).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) } } @@ -406,12 +406,12 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem if config.CriticalAbsolutThreshold.Space.Used.Th.DoesViolate(float64(fs.UsageStats.Used)) { _ = tmpPartialResult.SetState(check.Critical) - tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", humanize.IBytes(fs.UsageStats.Used), humanize.IBytes(fs.UsageStats.Total)) + tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Used).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) } } if tmpPartialResult.GetStatus() == check.OK { - tmpPartialResult.Output = fmt.Sprintf("Absolute used space: %s / %s", humanize.IBytes(fs.UsageStats.Used), humanize.IBytes(fs.UsageStats.Total)) + tmpPartialResult.Output = fmt.Sprintf("Absolute used space: %s / %s", convert.BytesIEC(fs.UsageStats.Used).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable()) } tmpPartialResult.Perfdata.Add(&pdAbsoluteUsedSpace) diff --git a/cmd/memory.go b/cmd/memory.go index df7b9a5..6c3bd41 100644 --- a/cmd/memory.go +++ b/cmd/memory.go @@ -6,9 +6,9 @@ import ( "github.com/NETWAYS/check_system_basics/internal/common/thresholds" "github.com/NETWAYS/check_system_basics/internal/memory" "github.com/NETWAYS/go-check" + "github.com/NETWAYS/go-check/convert" "github.com/NETWAYS/go-check/perfdata" "github.com/NETWAYS/go-check/result" - "github.com/dustin/go-humanize" "github.com/spf13/cobra" ) @@ -62,8 +62,8 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa _ = partialMemAvailable.SetDefaultState(check.OK) partialMemAvailable.Output = fmt.Sprintf("Available Memory (%s/%s, %.2f%%)", - humanize.IBytes(memStats.VirtMem.Available), - humanize.IBytes(memStats.VirtMem.Total), + convert.BytesIEC(memStats.VirtMem.Available).HumanReadable(), + convert.BytesIEC(memStats.VirtMem.Total).HumanReadable(), memStats.MemAvailablePercentage) // perfdata @@ -147,8 +147,8 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa } partialMemFree.Output = fmt.Sprintf("Free Memory (%s/%s, %.2f%%)", - humanize.IBytes(memStats.VirtMem.Free), - humanize.IBytes(memStats.VirtMem.Total), + convert.BytesIEC(memStats.VirtMem.Free).HumanReadable(), + convert.BytesIEC(memStats.VirtMem.Total).HumanReadable(), MemFreePercentage) if config.MemFree.Warn.IsSet { @@ -202,8 +202,8 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa _ = partialMemUsed.SetDefaultState(check.OK) partialMemUsed.Output = fmt.Sprintf("Used Memory (%s/%s, %.2f%%)", - humanize.IBytes(memStats.VirtMem.Used), - humanize.IBytes(memStats.VirtMem.Total), + convert.BytesIEC(memStats.VirtMem.Used).HumanReadable(), + convert.BytesIEC(memStats.VirtMem.Total).HumanReadable(), memStats.VirtMem.UsedPercent) pdMemUsed := perfdata.Perfdata{ @@ -425,7 +425,7 @@ func computeSwapResults(stats *memory.Mem) *result.PartialResult { return &partialSwap } - partialSwap.Output = fmt.Sprintf("Swap Usage %.2f%% (%s / %s)", stats.SwapInfo.UsedPercent, humanize.IBytes(stats.SwapInfo.Used), humanize.IBytes(stats.SwapInfo.Total)) + partialSwap.Output = fmt.Sprintf("Swap Usage %.2f%% (%s / %s)", stats.SwapInfo.UsedPercent, convert.BytesIEC(stats.SwapInfo.Used).HumanReadable(), convert.BytesIEC(stats.SwapInfo.Total).HumanReadable()) pdSwapUsed := perfdata.Perfdata{ Label: "swap_used", diff --git a/go.mod b/go.mod index 8f0ff44..6acd313 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.25.0 require ( github.com/NETWAYS/go-check v0.6.4 github.com/NETWAYS/go-icingadsl v0.1.2 - github.com/dustin/go-humanize v1.0.1 github.com/shirou/gopsutil/v3 v3.24.5 github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.0.10 diff --git a/go.sum b/go.sum index b1e4df5..17d8a2d 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,6 @@ github.com/NETWAYS/go-icingadsl v0.1.2/go.mod h1:CE74xcjOUHxYpltsooRTimANss5H2VZ github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=