Skip to content

Commit d512268

Browse files
Merge pull request #4 from NETWAYS/chore/nice_memory
beautify memory checks a bit
2 parents 55f93fe + ed41632 commit d512268

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

cmd/memory.go

+21-10
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ var memoryCmd = &cobra.Command{
1818
Use: "memory",
1919
Short: "Submodule to check the current system memory and swap usage",
2020
Example: `check_system_basics memory --memory-available-warning 10:20 --memory-free-critical-percentage 50:80 --memory-used-warning @10 --percentage-in-perfdata --swap-free-warning-percentage @30:31
21-
[WARNING] - states: warning=1 ok=1
22-
\_ [WARNING]
23-
\_ [WARNING] Available Memory (25 GiB, 78.97%)
24-
\_ [OK] Free Memory (20 GiB, 64.22%)
25-
\_ [OK] Used Memory (4.3 GiB, 13.73%)
21+
[CRITICAL] - states: critical=1 ok=1
22+
\_ [CRITICAL] RAM
23+
\_ [WARNING] Available Memory (23 GiB/31 GiB, 74.36%)
24+
\_ [CRITICAL] Free Memory (16 GiB/31 GiB, 49.95%)
25+
\_ [OK] Used Memory (6.1 GiB/31 GiB, 19.57%)
2626
\_ [OK] Swap Usage 0.00% (0 B / 36 GiB)
27-
|available_memory_percentage=78.975%;15:100;5:100 available_memory=26401148928B;10:20;;0;33429860352 free_memory=21468332032B;;;0;33429860352 free_memory_percentage=64.219%;;50:80 used_memory=4588732416B;@10;;0;33429860352 free_memory_percentage=13.726% swap_usage_percent=0%;20;85 swap_used=0B;;;0;38654701568
27+
|available_memory_percentage=74.36%;15:100;5:100 available_memory=24856633344B;10:20;;0;33427595264 free_memory=16696102912B;;;0;33427595264 free_memory_percentage=49.947%;;50:80 used_memory=6542696448B;@10;;0;33427595264 free_memory_percentage=19.573% swap_usage_percent=0%;20;85 swap_used=0B;;;0;38654701568
2828
`,
2929
Run: func(cmd *cobra.Command, args []string) {
3030

@@ -52,14 +52,19 @@ var memoryCmd = &cobra.Command{
5252
}
5353

5454
func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.PartialResult {
55-
var partialMem result.PartialResult
55+
partialMem := result.PartialResult{
56+
Output: "RAM",
57+
}
5658
_ = partialMem.SetDefaultState(check.OK)
5759

5860
// # Available
5961
var partialMemAvailable result.PartialResult
6062
_ = partialMemAvailable.SetDefaultState(check.OK)
6163

62-
partialMemAvailable.Output = fmt.Sprintf("Available Memory (%s, %.2f%%)", humanize.IBytes(memStats.VirtMem.Available), memStats.MemAvailablePercentage)
64+
partialMemAvailable.Output = fmt.Sprintf("Available Memory (%s/%s, %.2f%%)",
65+
humanize.IBytes(memStats.VirtMem.Available),
66+
humanize.IBytes(memStats.VirtMem.Total),
67+
memStats.MemAvailablePercentage)
6368

6469
// perfdata
6570
pdMemAvailable := perfdata.Perfdata{
@@ -140,7 +145,10 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa
140145
Uom: "%",
141146
}
142147

143-
partialMemFree.Output = fmt.Sprintf("Free Memory (%s, %.2f%%)", humanize.IBytes(memStats.VirtMem.Free), MemFreePercentage)
148+
partialMemFree.Output = fmt.Sprintf("Free Memory (%s/%s, %.2f%%)",
149+
humanize.IBytes(memStats.VirtMem.Free),
150+
humanize.IBytes(memStats.VirtMem.Total),
151+
MemFreePercentage)
144152

145153
if config.MemFree.Warn.IsSet {
146154
pdMemFree.Warn = &config.MemFree.Warn.Th
@@ -191,7 +199,10 @@ func computeMemResults(config *memory.MemConfig, memStats *memory.Mem) result.Pa
191199
var partialMemUsed result.PartialResult
192200
_ = partialMemUsed.SetDefaultState(check.OK)
193201

194-
partialMemUsed.Output = fmt.Sprintf("Used Memory (%s, %.2f%%)", humanize.IBytes(memStats.VirtMem.Used), memStats.VirtMem.UsedPercent)
202+
partialMemUsed.Output = fmt.Sprintf("Used Memory (%s/%s, %.2f%%)",
203+
humanize.IBytes(memStats.VirtMem.Used),
204+
humanize.IBytes(memStats.VirtMem.Total),
205+
memStats.VirtMem.UsedPercent)
195206

196207
pdMemUsed := perfdata.Perfdata{
197208
Label: "used_memory",

0 commit comments

Comments
 (0)