Skip to content

Commit c6f0d7f

Browse files
author
Lorenz Kästle
committed
Replace go-humanize with go-check/convert
1 parent 6e4bd59 commit c6f0d7f

4 files changed

Lines changed: 15 additions & 18 deletions

File tree

cmd/filesystem.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"github.com/NETWAYS/check_system_basics/internal/common/thresholds"
1212
"github.com/NETWAYS/check_system_basics/internal/filesystem"
1313
"github.com/NETWAYS/go-check"
14+
"github.com/NETWAYS/go-check/convert"
1415
"github.com/NETWAYS/go-check/perfdata"
1516
"github.com/NETWAYS/go-check/result"
16-
"github.com/dustin/go-humanize"
1717
"github.com/shirou/gopsutil/v3/disk"
1818
"github.com/spf13/cobra"
1919
)
@@ -356,7 +356,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem
356356

357357
if config.WarningAbsolutThreshold.Space.Free.Th.DoesViolate(float64(fs.UsageStats.Free)) {
358358
_ = tmpPartialResult.SetState(check.Warning)
359-
tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", humanize.IBytes(fs.UsageStats.Free), humanize.IBytes(fs.UsageStats.Total))
359+
tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Free).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable())
360360
}
361361
}
362362

@@ -365,12 +365,12 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem
365365

366366
if config.CriticalAbsolutThreshold.Space.Free.Th.DoesViolate(float64(fs.UsageStats.Free)) {
367367
_ = tmpPartialResult.SetState(check.Critical)
368-
tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", humanize.IBytes(fs.UsageStats.Free), humanize.IBytes(fs.UsageStats.Total))
368+
tmpPartialResult.Output = fmt.Sprintf("Absolute free space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Free).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable())
369369
}
370370
}
371371

372372
if tmpPartialResult.GetStatus() == check.OK {
373-
tmpPartialResult.Output = fmt.Sprintf("Absolute free space: %s / %s", humanize.IBytes(fs.UsageStats.Free), humanize.IBytes(fs.UsageStats.Total))
373+
tmpPartialResult.Output = fmt.Sprintf("Absolute free space: %s / %s", convert.BytesIEC(fs.UsageStats.Free).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable())
374374
}
375375

376376
tmpPartialResult.Perfdata.Add(&pdAbsoluteFreeSpace)
@@ -397,7 +397,7 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem
397397

398398
if config.WarningAbsolutThreshold.Space.Used.Th.DoesViolate(float64(fs.UsageStats.Used)) {
399399
_ = tmpPartialResult.SetState(check.Warning)
400-
tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", humanize.IBytes(fs.UsageStats.Used), humanize.IBytes(fs.UsageStats.Total))
400+
tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Used).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable())
401401
}
402402
}
403403

@@ -406,12 +406,12 @@ func computeFsCheckResultSpace(fs *filesystem.FilesystemType, config *filesystem
406406

407407
if config.CriticalAbsolutThreshold.Space.Used.Th.DoesViolate(float64(fs.UsageStats.Used)) {
408408
_ = tmpPartialResult.SetState(check.Critical)
409-
tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", humanize.IBytes(fs.UsageStats.Used), humanize.IBytes(fs.UsageStats.Total))
409+
tmpPartialResult.Output = fmt.Sprintf("Absolute used space violates threshold: %s / %s", convert.BytesIEC(fs.UsageStats.Used).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable())
410410
}
411411
}
412412

413413
if tmpPartialResult.GetStatus() == check.OK {
414-
tmpPartialResult.Output = fmt.Sprintf("Absolute used space: %s / %s", humanize.IBytes(fs.UsageStats.Used), humanize.IBytes(fs.UsageStats.Total))
414+
tmpPartialResult.Output = fmt.Sprintf("Absolute used space: %s / %s", convert.BytesIEC(fs.UsageStats.Used).HumanReadable(), convert.BytesIEC(fs.UsageStats.Total).HumanReadable())
415415
}
416416

417417
tmpPartialResult.Perfdata.Add(&pdAbsoluteUsedSpace)

cmd/memory.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"github.com/NETWAYS/check_system_basics/internal/common/thresholds"
77
"github.com/NETWAYS/check_system_basics/internal/memory"
88
"github.com/NETWAYS/go-check"
9+
"github.com/NETWAYS/go-check/convert"
910
"github.com/NETWAYS/go-check/perfdata"
1011
"github.com/NETWAYS/go-check/result"
11-
"github.com/dustin/go-humanize"
1212
"github.com/spf13/cobra"
1313
)
1414

@@ -62,8 +62,8 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa
6262
_ = partialMemAvailable.SetDefaultState(check.OK)
6363

6464
partialMemAvailable.Output = fmt.Sprintf("Available Memory (%s/%s, %.2f%%)",
65-
humanize.IBytes(memStats.VirtMem.Available),
66-
humanize.IBytes(memStats.VirtMem.Total),
65+
convert.BytesIEC(memStats.VirtMem.Available).HumanReadable(),
66+
convert.BytesIEC(memStats.VirtMem.Total).HumanReadable(),
6767
memStats.MemAvailablePercentage)
6868

6969
// perfdata
@@ -147,8 +147,8 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa
147147
}
148148

149149
partialMemFree.Output = fmt.Sprintf("Free Memory (%s/%s, %.2f%%)",
150-
humanize.IBytes(memStats.VirtMem.Free),
151-
humanize.IBytes(memStats.VirtMem.Total),
150+
convert.BytesIEC(memStats.VirtMem.Free).HumanReadable(),
151+
convert.BytesIEC(memStats.VirtMem.Total).HumanReadable(),
152152
MemFreePercentage)
153153

154154
if config.MemFree.Warn.IsSet {
@@ -202,8 +202,8 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa
202202
_ = partialMemUsed.SetDefaultState(check.OK)
203203

204204
partialMemUsed.Output = fmt.Sprintf("Used Memory (%s/%s, %.2f%%)",
205-
humanize.IBytes(memStats.VirtMem.Used),
206-
humanize.IBytes(memStats.VirtMem.Total),
205+
convert.BytesIEC(memStats.VirtMem.Used).HumanReadable(),
206+
convert.BytesIEC(memStats.VirtMem.Total).HumanReadable(),
207207
memStats.VirtMem.UsedPercent)
208208

209209
pdMemUsed := perfdata.Perfdata{
@@ -425,7 +425,7 @@ func computeSwapResults(stats *memory.Mem) *result.PartialResult {
425425
return &partialSwap
426426
}
427427

428-
partialSwap.Output = fmt.Sprintf("Swap Usage %.2f%% (%s / %s)", stats.SwapInfo.UsedPercent, humanize.IBytes(stats.SwapInfo.Used), humanize.IBytes(stats.SwapInfo.Total))
428+
partialSwap.Output = fmt.Sprintf("Swap Usage %.2f%% (%s / %s)", stats.SwapInfo.UsedPercent, convert.BytesIEC(stats.SwapInfo.Used).HumanReadable(), convert.BytesIEC(stats.SwapInfo.Total).HumanReadable())
429429

430430
pdSwapUsed := perfdata.Perfdata{
431431
Label: "swap_used",

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.25.0
55
require (
66
github.com/NETWAYS/go-check v0.6.4
77
github.com/NETWAYS/go-icingadsl v0.1.2
8-
github.com/dustin/go-humanize v1.0.1
98
github.com/shirou/gopsutil/v3 v3.24.5
109
github.com/spf13/cobra v1.10.2
1110
github.com/spf13/pflag v1.0.10

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ github.com/NETWAYS/go-icingadsl v0.1.2/go.mod h1:CE74xcjOUHxYpltsooRTimANss5H2VZ
55
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
66
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
77
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8-
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
9-
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
108
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
119
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
1210
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=

0 commit comments

Comments
 (0)