OOM, repeated starts and PID checks¶
These optional checks are available since 0.0.68. They use Docker metadata and statistics, without running commands inside containers. Existing default checks make no additional event-history request.
Resource |
Meaning |
|---|---|
|
Docker OOM events retained in the recent window, including after a container restart. |
|
Container starts in that window: initial start, explicit start/restart and Docker restart-policy starts. |
|
Current cgroup process/thread count. This is not the host PID of the container’s main process ( |
|
Configured finite Docker PID limit; |
|
|
Read checks¶
monit-docker --name 'web*' --event-window 300 stats \
--rsc oom_events --rsc starts_recent \
--rsc pids_current --rsc pids_limit --rsc pids_percent
--event-window is a global option before stats, monit, cron or serve.
It accepts 1–86400 seconds and defaults to 300. One query reads the Docker event
buffer per cycle for all selected containers, only when an event resource is
requested explicitly or by a rule. PID checks share the existing stats stream.
No extra service, database, event thread or persistent state file is added.
For the UI and Prometheus, explicitly select the desired resources, for example:
monit-docker --event-window 300 serve \
--rsc status --rsc health --rsc cpu_percent --rsc mem_usage --rsc mem_limit \
--rsc mem_percent --rsc oom_events --rsc starts_recent --rsc pids_current
Selecting any PID resource also supplies the count, limit and percentage in the API. The UI displays them when available and shows incomplete event history explicitly. Regular UI authentication and action controls are unchanged.
Rules and actions¶
These numeric resources work with existing YAML condition/command aliases,
check-config, monit, cron, serve, dry runs, delays and cooldowns.
For reusable YAML aliases:
conditions:
recent_oom:
expr: ['oom_events > 0']
frequent_starts:
expr: ['starts_recent >= 3']
pid_pressure:
expr: ['pids_percent > 90']
For example, to preview stopping a service that started three times in five minutes:
monit-docker --name web --event-window 300 cron \
--state-file /var/lib/monit-docker/web.json --dry-run \
--cmd-if 'starts_recent >= 3 ? stop'
For PID pressure, a possible condition is pids_percent > 90. Configure a finite
Docker pids_limit first, or use an absolute pids_current threshold instead.
An unavailable value is an error (115) when used in a rule, never a healthy zero.
Event-only rules also work on stopped containers; PID rules require a running
or paused container with supported PID accounting.
Starts are not the automatic restart budget. The initial start counts,
and a start/stop sequence counts on its next start. This observes Docker and
operator activity; it does not limit Docker’s restart policy. The existing
--max-restarts guard applies only to monit-docker’s own automatic restarts.
A rule action based on these checks uses the same persistent budget and audit
journal as other automatic actions. An OOM is not automatically a reason to
restart: the underlying memory pressure may need intervention.
Alerts, notifications and journal¶
The metrics are window gauges, not cumulative counters; do not apply rate()
to oom_events or starts_recent. The supplied alert examples detect OOMs,
at least three starts in a 300-second window, high PID usage and truncated history.
They activate only when the corresponding checks are enabled. Existing
Alertmanager/email/Slack/Redis/HTTP notification integrations can deliver them.
Actions and their outcomes are recorded in the existing audit journal. To journal the alerts themselves, configure the existing private Alertmanager audit receiver or the audited notification adapters as described in the audit guide. Reading an event window does not append all its events repeatedly to the journal.
Docker references: events and retention and PID statistics.