Skip to content

Commit cfc1154

Browse files
committed
memory-usage: modernize code
1 parent b4a8765 commit cfc1154

File tree

4 files changed

+180
-88
lines changed

4 files changed

+180
-88
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Monitoring Plugins:
7171
* gitlab-readiness: increase timeout from 3 to 8 secs
7272
* infomaniak-events: increase timeout from 8 to 28 secs
7373
* journald-usage: also print SystemMaxUse and SystemKeepFree
74+
* memory-usage: modernize code
7475
* pip-updates: modernize code
7576
* procs: avoid token + PEB reads and repeated attribute calls per process, as this has an impact on busy Windows servers
7677
* rocketchat-stats: improve output and docs a little bit

check-plugins/memory-usage/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
Displays the amount of free and used memory in the system and checks how much physical memory is left across platforms by using the `available` field.
5+
Displays system memory usage and alerts on sustained high usage. Reports total/used/available/free plus shared/buffers/cached, and evaluates WARN/CRIT against the overall usage percentage. Perfdata is emitted for all fields so you can graph trends over time. With `--top`, the most memory-consuming processes are listed (by RSS and percentage) to aid quick diagnosis. Cross-platform on all psutil-supported systems (Linux, Windows, \*BSD, macOS).
66

77
Hints:
88

@@ -26,17 +26,22 @@ Hints:
2626
```text
2727
usage: memory-usage [-h] [-V] [--always-ok] [-c CRIT] [--top TOP] [-w WARN]
2828
29-
Displays amount of free and used memory in the system, checks against used
30-
memory in percent.
29+
Displays system memory usage and alerts on sustained high usage. Reports
30+
total/used/available/free plus shared/buffers/cached, and evaluates WARN/CRIT
31+
against the overall usage percentage. Perfdata is emitted for all fields so
32+
you can graph trends over time. With `--top`, the most memory-consuming
33+
processes are listed (by RSS and percentage) to aid quick diagnosis. Cross-
34+
platform on all psutil-supported systems (Linux, Windows, *BSD, macOS).
3135
3236
options:
3337
-h, --help show this help message and exit
3438
-V, --version show program's version number and exit
3539
--always-ok Always returns OK.
3640
-c, --critical CRIT Set the critical threshold for memory usage (in
3741
percent). Default: 95
38-
--top TOP List x "Top most memory consuming processes". Default:
39-
5
42+
--top TOP List x "Top most memory consuming processes". Use
43+
`--top=0` to disable this feature. Default: 5 on Linux,
44+
0 on Windows
4045
-w, --warning WARN Set the warning threshold for memory usage (in
4146
percent). Default: 90
4247
```
@@ -46,7 +51,7 @@ options:
4651

4752
```bash
4853
./memory-usage
49-
./memory-usage --warning 90 --critical 95
54+
./memory-usage --warning=90 --critical=95 --top=5
5055
```
5156

5257
Output:
@@ -55,7 +60,7 @@ Output:
5560
36.2% - total: 3.8GiB, used: 1.1GiB, available: 2.4GiB, free: 989.4MiB
5661
shared: 41.6MiB, buffers: 3.6MiB, cached: 1.8GiB
5762
58-
Top5 most memory consuming processes:
63+
Top 5 most memory consuming processes:
5964
1. php-fpm: 810.7MiB (20.7%)
6065
2. forkit: 418.3MiB (10.7%)
6166
3. kit_spare_001: 335.5MiB (8.6%)
@@ -85,8 +90,8 @@ Top5 most memory consuming processes:
8590

8691
## Troubleshooting
8792

88-
This checks sometimes reports \> 100% memory usage
89-
That's fine, the RES column in `top` says the same if you sum up all values for a process (attention: the values in top's RES column are KB by default), and compare process memory to total physical system memory. The machine does not swap, so this is kind of Linux memory management mystery.
93+
This checks sometimes reports \> 100% memory usage on Linux
94+
That's fine, the RES column in `top` says the same if you sum up all values for a process (attention: the values in top's RES column are KB by default), and compare process memory to total physical system memory. If machine does not swap, this is kind of Linux memory management mystery.
9095

9196

9297
## Credits, License

check-plugins/memory-usage/icingaweb2-module-director/memory-usage.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"tpl-service-generic"
147147
],
148148
"max_check_attempts": 5,
149-
"notes": "Displays amount of free and used memory in the system, checks against used memory in percent.",
149+
"notes": "Displays system memory usage and alerts on sustained high usage. Reports total/used/available/free plus shared/buffers/cached, and evaluates WARN/CRIT against the overall usage percentage. Perfdata is emitted for all fields so you can graph trends over time. With `--top`, the most memory-consuming processes are listed (by RSS and percentage) to aid quick diagnosis. Cross-platform on all psutil-supported systems (Linux, Windows, *BSD, macOS).",
150150
"notes_url": "https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/memory-usage",
151151
"object_name": "tpl-service-memory-usage",
152152
"object_type": "template",
@@ -195,7 +195,7 @@
195195
"tpl-service-generic"
196196
],
197197
"max_check_attempts": 5,
198-
"notes": "Displays amount of free and used memory in the system, checks against used memory in percent.",
198+
"notes": "Displays system memory usage and alerts on sustained high usage. Reports total/used/available/free plus shared/buffers/cached, and evaluates WARN/CRIT against the overall usage percentage. Perfdata is emitted for all fields so you can graph trends over time. With `--top`, the most memory-consuming processes are listed (by RSS and percentage) to aid quick diagnosis. Cross-platform on all psutil-supported systems (Linux, Windows, *BSD, macOS).",
199199
"notes_url": "https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/memory-usage",
200200
"object_name": "tpl-service-memory-usage-windows",
201201
"object_type": "template",
@@ -240,7 +240,7 @@
240240
"3": {
241241
"varname": "memory_usage_top",
242242
"caption": "Memory Usage: Top",
243-
"description": "List x \"Top most memory consuming processes\".",
243+
"description": "List x \"Top most memory consuming processes\". Use `--top=0` to disable this feature. Default: 5 on Linux, 0 on Windows",
244244
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString",
245245
"format": null,
246246
"settings": {
@@ -282,7 +282,7 @@
282282
"7": {
283283
"varname": "memory_usage_windows_top",
284284
"caption": "Memory Usage: Top",
285-
"description": "List x \"Top most memory consuming processes\".",
285+
"description": "List x \"Top most memory consuming processes\". Use `--top=0` to disable this feature. Default: 5 on Linux, 0 on Windows",
286286
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeString",
287287
"format": null,
288288
"settings": {

0 commit comments

Comments
 (0)