monitor
monitor
¶
Resource monitoring for the Marianne daemon.
Periodic background checks on memory, child process count, and zombie detection. Emits structured log warnings when limits are approached and triggers backpressure (e.g. job cancellation) when hard limits are exceeded.
Delegates system probing to SystemProbe (system_probe.py) which
consolidates the psutil / /proc fallback pattern in one place.
Classes¶
ResourceSnapshot
dataclass
¶
ResourceSnapshot(timestamp, memory_usage_mb, child_process_count, running_jobs, active_sheets, zombie_pids=list(), probe_failed=False)
Point-in-time resource usage reading.
ResourceMonitor
¶
Periodic resource monitoring for the daemon.
Checks memory usage, child process count, and zombie processes on a configurable interval. Emits structured log warnings when approaching limits and can trigger hard actions (job cancellation) when hard limits are exceeded.
Source code in src/marianne/daemon/monitor.py
Attributes¶
seconds_since_last_check
property
¶
Seconds since the last successful monitoring check.
Returns float('inf') if no check has succeeded yet.
Consumers can use this to detect stale resource data.
is_degraded
property
¶
Whether the monitor has entered degraded mode due to repeated failures.
Functions¶
start
async
¶
Start the periodic monitoring loop.
Source code in src/marianne/daemon/monitor.py
stop
async
¶
Stop the monitoring loop.
Source code in src/marianne/daemon/monitor.py
check_now
async
¶
Run an immediate resource check and return snapshot.
Source code in src/marianne/daemon/monitor.py
is_accepting_work
¶
Check if resource usage is below warning thresholds.
Returns True when both memory and process counts are below
WARN_THRESHOLD percent of their configured limits. Used by
HealthChecker.readiness() to signal backpressure.
Fail-closed: returns False when probes fail or monitor is degraded.
Source code in src/marianne/daemon/monitor.py
current_memory_mb
¶
update_limits
¶
Hot-apply new resource limits from a SIGHUP config reload.
Replaces the internal _config reference. Safe because the
monitor only reads _config during periodic checks, and
asyncio's single-threaded event loop prevents concurrent access.
Source code in src/marianne/daemon/monitor.py
set_manager
¶
Wire up the job manager reference after construction.
Called by DaemonProcess after both the monitor and manager are created, avoiding the circular dependency of needing both at init.