Since 0.0.70, combine container selection, resources and rules in a named scenario, then launch it with a short command.
1. Define scenarios
Add these definitions to /etc/monit-docker/monit-docker.yml. Adapt the container names and use a writable persistent state directory.
scenarios:
web-stats:
description: Read web container CPU and memory usage
mode: stats
select:
name: ['web-*']
resources: [cpu_percent, mem_usage]
web-guard:
description: Restart web containers after sustained high memory usage
mode: cron
select:
name: ['web-*']
rules:
- 'mem_percent > 90 ? restart'
state-file: /var/lib/monit-docker/web-guard.json
cooldown: 300
max-restarts: 3
trigger-after: 120
max-gap: 90
2. Validate and run
monit-docker scenario list
monit-docker scenario show web-guard
monit-docker check-config
monit-docker run web-stats
monit-docker run web-guard --dry-run
monit-docker run web-guard
Listing, showing and validating scenarios work without Docker. The stats mode reads measurements once; cron evaluates rules once; serve monitors continuously. The default mode is cron. A dry run performs no actions and does not build durable observation streaks.
3. Schedule a scenario
For one run every minute, add this crontab entry and adapt the executable path:
* * * * * /usr/local/bin/monit-docker run web-guard
This example requires two minutes of sustained observations, with no gap exceeding 90 seconds. The first match therefore does not immediately restart a container. Keep the same account and state file to preserve cooldowns, budgets and maintenance.
4. Selection and limits
Each scenario requires select or all: true. Global selectors cannot override scenario targets. Each invocation starts one scenario; this version does not define ordered workflow steps or provide a built-in scheduler. Manual HTTP actions continue to use the full serve command. Generated messages and reason values remain English.
5. Try the demo scenario
On the demo server, demo-stats reads measurements only for the two test containers:
sudo docker exec monit-demo-agent monit-docker run demo-stats
It performs no actions. See the reference source for all settings, imports and configuration templates.
See the configuration and CLI contract for precedence, defaults, selectors and exit codes.
Docker exec waits up to 60 seconds by default. Set kwargs.exec_timeout on the command alias (1–86400 seconds). A timeout leaves the outcome unknown; check the container before retrying because the command may still be running.

