system_probe
system_probe
¶
Consolidated system probes for the Marianne daemon.
Provides a single SystemProbe class that encapsulates the
"try psutil → fallback to /proc" pattern used across the daemon for:
- Memory usage (RSS)
- Child process counting
- Zombie detection and reaping
- Process group member counting
Extracted from monitor.py and pgroup.py (FIX-16) to eliminate
5× duplication of the psutil/proc fallback logic. All methods are
static — callers import the class and call methods directly.
Classes¶
SystemProbe
¶
Consolidated system resource probes.
Each method tries psutil first, then falls back to /proc on Linux.
Returns None when all probes fail — callers should treat that
as a critical condition (fail-closed).
Functions¶
get_memory_mb
staticmethod
¶
Get current process RSS memory in MB.
Uses psutil.Process().memory_info().rss if available,
falls back to reading VmRSS from /proc/self/status.
Returns:
| Type | Description |
|---|---|
float | None
|
RSS in megabytes, or |
Source code in src/marianne/daemon/system_probe.py
get_child_count
staticmethod
¶
Count child processes of the current process (recursive).
Uses psutil.Process().children(recursive=True) if available,
falls back to scanning /proc/*/status for matching PPid.
Returns:
| Type | Description |
|---|---|
int | None
|
Number of child processes, or |
Source code in src/marianne/daemon/system_probe.py
get_zombies
staticmethod
¶
Detect zombie child processes (without reaping).
Returns:
| Type | Description |
|---|---|
list[int]
|
List of zombie PIDs that were detected (not necessarily reaped). |
reap_zombies
staticmethod
¶
Detect and reap zombie child processes.
Returns:
| Type | Description |
|---|---|
list[int]
|
List of PIDs that were reaped. |
count_group_members
staticmethod
¶
Count processes in a process group, excluding one PID.
Uses psutil Process.pgid per-process if available, falls
back to reading /proc/*/stat field 5 (0-indexed 4).
Note: psutil.process_iter(["pgid"]) raises ValueError
because pgid is not a valid as_dict attribute. We use
per-process os.getpgid(proc.pid) instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pgid
|
int
|
Process group ID to count members of. |
required |
exclude_pid
|
int
|
PID to exclude from count (typically self). |
0
|
Returns:
| Type | Description |
|---|---|
int | None
|
Number of matching processes, or None if all probes fail. |