Skip to content

Commit f6bf0d8

Browse files
committed
feat(procs): add --lengthy parameter and per-process memory details to --top table
Show platform-specific memory fields (RSS, VMS, Shared, etc.) in the --top process table. Without --lengthy, a compact view is shown (CPU Total, RSS). Fix the --top table to filter by zero CPU time instead of sleeping status. Dynamically detect available memory_info fields from the installed psutil version for forward compatibility.
1 parent fa64795 commit f6bf0d8

File tree

5 files changed

+253
-64
lines changed

5 files changed

+253
-64
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Monitoring Plugins:
3939
* infomaniak-swiss-backup-devices: add `--ignore-customer`, `--ignore-name`, `--ignore-tag`, `--ignore-user` parameters to skip devices by regex
4040
* infomaniak-swiss-backup-products: add `--ignore-customer`, `--ignore-tag` parameters to skip products by regex
4141
* nextcloud-enterprise: provides information about an installed Nextcloud Enterprise subscription
42-
* procs: add `--top` parameter to list the top N processes by CPU time (user/system/total) with status, excluding sleeping processes by default
42+
* procs: add `--lengthy` parameter for extended `--top` table output with all platform-specific memory fields
43+
* procs: add `--top` parameter to list the top N processes by CPU time and memory usage
4344
* procs: add `--warning-cpu-percent` / `--critical-cpu-percent` thresholds for aggregated CPU usage of filtered processes (requires SQLite for delta calculation between runs)
4445
* statuspal: also detect 'emergency-maintenance' state
4546
* valkey-status: support user and password credentials [PR #954](https://github.com/Linuxfabrik/monitoring-plugins/pull/954), thanks to [Claudio Kuenzler](https://github.com/Napsty)

check-plugins/memory-usage/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Monitors physical memory utilization with threshold-based alerting on overall me
2727
* Memory usage calculations differ between tools (top, htop, free) due to different counting methods and kernel versions
2828
* This check uses psutil's cross-platform `available` metric for consistency
2929
* Process memory percentages may sum to >100% on Linux due to shared memory accounting
30+
* The `--top` list reports RSS per process from psutil's `memory_info()`:
31+
32+
| Field | Description |
33+
|----|----|
34+
| rss | Resident Set Size. The non-swapped physical memory a process has used. On UNIX matches the `top` RES column. On Windows maps to `WorkingSetSize`. |
3035

3136

3237
## Fact Sheet

check-plugins/procs/README.md

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,38 @@ Prints the number of currently running processes and warns on metrics like proce
66

77
Hints:
88

9-
* Memory: We count RSS, also known as 'Resident Set Size' or 'Res'. This is the amount of physical memory that a process has used that has not been swapped out. In UNIX, it matches the 'RES' column in 'top'. Note the differences in memory counting between tools such as 'top', 'htop', 'glances', 'GNOME System Monitor' and others. The way memory is counted also changes between different Linux kernel versions. On Windows, this is an alias for the wset field, matching the 'Mem Usage' column in taskmgr.exe.
109
* CPU usage: The `--warning-cpu-percent` and `--critical-cpu-percent` thresholds compare the aggregated CPU usage of all matching processes against the given threshold. This requires at least two consecutive check runs for the delta calculation. A value of 100% equals one fully utilized CPU core. On multi-core systems, values above 100% are possible.
10+
* Memory: The `--top` table reports per-process memory fields from psutil's `memory_info()`. Note the differences in memory counting between tools such as `top`, `htop`, `glances`, `GNOME System Monitor` and others. The way memory is counted also changes between different Linux kernel versions. The following fields are available (all values in bytes):
11+
12+
Portable (all platforms):
13+
14+
| Field | Description |
15+
|----|----|
16+
| rss | Resident Set Size. The non-swapped physical memory a process has used. On UNIX matches the `top` RES column. On Windows maps to `WorkingSetSize`. |
17+
| vms | Virtual Memory Size. The total amount of virtual memory used by the process. On UNIX matches the `top` VIRT column. On Windows maps to `PrivateUsage` (private committed pages only), which differs from the UNIX definition. |
18+
19+
Linux:
20+
21+
| Field | Description |
22+
|----|----|
23+
| data | Aka DRS (Data Resident Set). Covers the data and stack segments combined (from `/proc/<pid>/statm`). Matches `top`'s DATA column. |
24+
| shared | Shared memory that could be shared with other processes (shared libraries, memory-mapped files). Counted even if no other process is currently mapping it. Matches `top`'s SHR column. |
25+
| text | Aka TRS (Text Resident Set). Resident memory devoted to executable code. This memory is read-only and typically shared across all processes running the same binary. Matches `top`'s CODE column. |
26+
27+
Windows:
28+
29+
| Field | Description |
30+
|----|----|
31+
| nonpaged_pool | Current nonpaged pool usage. Kernel memory used for objects that must remain in physical memory. |
32+
| num_page_faults | The number of page faults. |
33+
| pagefile | The Commit Charge value for this process (same as `vms`). |
34+
| paged_pool | Current paged pool usage. Kernel memory used for objects created by the process that can be paged to disk. |
35+
| peak_nonpaged_pool | Peak nonpaged pool usage. |
36+
| peak_paged_pool | Peak paged pool usage. |
37+
| peak_pagefile | Peak Commit Charge during the lifetime of this process. |
38+
| peak_wset | Peak working set size (same as peak RSS). |
39+
| private | Same as `vms`. |
40+
| wset | Current working set size (same as `rss`). |
1141

1242

1343
## Fact Sheet
@@ -29,7 +59,8 @@ usage: procs [-h] [-V] [--always-ok] [--argument ARGUMENT] [--command COMMAND]
2959
[-c CRIT] [--critical-age CRIT_AGE]
3060
[--critical-cpu-percent CRIT_CPU_PERCENT]
3161
[--critical-mem CRIT_MEM]
32-
[--critical-mem-percent CRIT_MEM_PERCENT] [--no-kthreads]
62+
[--critical-mem-percent CRIT_MEM_PERCENT] [--lengthy]
63+
[--no-kthreads]
3364
[--status {dead,disk-sleep,idle,locked,parked,running,sleeping,stopped,suspended,tracing-stop,waiting,wake-kill,waking,zombie}]
3465
[--top TOP] [--username USERNAME] [-w WARN]
3566
[--warning-age WARN_AGE] [--warning-cpu-percent WARN_CPU_PERCENT]
@@ -66,15 +97,16 @@ options:
6697
--critical-mem-percent CRIT_MEM_PERCENT
6798
Threshold for memory usage, in percent. Type: None or
6899
Range. Default: None
100+
--lengthy Extended reporting.
69101
--no-kthreads Filter: Only scan for non kernel threads (works on
70102
Linux only). Default: False
71103
--status {dead,disk-sleep,idle,locked,parked,running,sleeping,stopped,suspended,tracing-stop,waiting,wake-kill,waking,zombie}
72104
Filter: Search only for processes that have a specific
73105
status. Default: None
74106
--top TOP List the top N processes using the most CPU time.
75-
Processes where all instances are sleeping are
76-
excluded from the table. Use `--top=0` to disable this
77-
feature. Default: 5
107+
Processes with zero CPU time are excluded from the
108+
table. Use `--top=0` to disable this feature. Default:
109+
5
78110
--username USERNAME Filter: Search only for processes whose user name
79111
matches USERNAME as a regular expression (case-
80112
insensitive). Example: `--username="^(apache|www-
@@ -107,13 +139,33 @@ options:
107139
Output:
108140

109141
```text
110-
564 procs using 16.9GiB RAM (54.7%), 1 uninterruptible (1x kworker/u36:0+i915_flip), 1 running (1x isolated web co), 561 sleeping, 1 zombie (1x xdg-open), up 1W 1D
142+
582 procs using 17.2GiB RAM (55.6%), 581 sleeping, 1 zombie (1x xdg-open), up 1W 1D
143+
144+
Name ! CPU Total ! RSS ! Status
145+
-------------------+-----------+----------+------------
146+
firefox ! 6h 34m ! 980.4MiB ! 1x sleeping
147+
gnome-shell ! 5h 49m ! 692.2MiB ! 1x sleeping
148+
WebExtensions ! 3h 14m ! 1.8GiB ! 1x sleeping
149+
rocketchat-desktop ! 2h 9m ! 739.5MiB ! 9x sleeping
150+
claude ! 1h 7m ! 2.3GiB ! 5x sleeping
151+
```
152+
153+
With `--lengthy`, the table includes all platform-specific `memory_info()` fields from the installed psutil version (fields that are not available are automatically omitted):
154+
155+
```bash
156+
./procs --lengthy
157+
```
158+
159+
Output (Linux, psutil 7.x):
160+
161+
```text
162+
575 procs using 18.1GiB RAM (58.7%), 574 sleeping, 1 zombie (1x xdg-open), up 1W 1D
111163
112-
Name ! CPU User ! CPU System ! CPU Total ! Status
113-
-----------------+----------+------------+-----------+-----------------------------
114-
isolated web co ! 1h 24m ! 12m 30s ! 1h 37m ! 1x running
115-
kworker/u36:0+i9 ! ! 5s ! 5s ! 1x disk-sleep
116-
xdg-open ! ! ! ! 1x zombie
164+
Name ! CPU User ! CPU System ! CPU Total ! RSS ! VMS ! Shared ! Text ! Lib ! Data ! Dirty ! Status
165+
--------------+----------+------------+-----------+----------+---------+----------+----------+------+----------+-------+------------
166+
firefox ! 5h 15m ! 1h 19m ! 6h 35m ! 978.1MiB ! 21.1GiB ! 229.1MiB ! 300.0KiB ! 0.0B ! 1.6GiB ! 0.0B ! 1x sleeping
167+
gnome-shell ! 4h 13m ! 1h 36m ! 5h 50m ! 693.2MiB ! 7.3GiB ! 122.4MiB ! 12.0KiB ! 0.0B ! 931.9MiB ! 0.0B ! 1x sleeping
168+
WebExtensions ! 2h 59m ! 15m 40s ! 3h 14m ! 1.8GiB ! 9.9GiB ! 105.2MiB ! 300.0KiB ! 0.0B ! 3.1GiB ! 0.0B ! 1x sleeping
117169
```
118170

119171
Other examples:

0 commit comments

Comments
 (0)