Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cmd/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())
}
}

Expand All @@ -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)
Expand All @@ -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())
}
}

Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions cmd/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down