v1.3.3Stable release

Stable release v1.3.3

Configuration and rules

Name Docker connections, select containers and reuse readable rules.

1. Create a YAML file

Save this as monit-docker.yml. Replace web* with your container pattern.

clients:
  local:
    config:
      base_url: unix:///var/run/docker.sock
ctn-groups:
  web:
    match:
      - 'name:web*'
conditions:
  memory_high:
    expr:
      - mem_percent > 90
commands:
  graceful_restart:
    exec:
      - restart:
          kwargs:
            timeout: 10

2. Validate without Docker

monit-docker -c ./monit-docker.yml --client local --ctn-group web \
  check-config --cmd-if '@memory_high ? @graceful_restart' --output json

check-config checks structure and references without connecting to Docker or performing actions. It requires a file or nonempty inline configuration; a file containing {} is a valid minimal configuration. A completely empty YAML file is not.

3. Use aliases

monit-docker -c ./monit-docker.yml --client local --ctn-group web cron \
  --state-file "$HOME/.local/state/monit-docker/web.json" \
  --cooldown 300 --dry-run \
  --cmd-if '@memory_high ? @graceful_restart'

Understand a condition

mem_percent > 90 ? restart connects a condition to an action. Expressions within an alias are ANDed. Multiple --cmd-if options may each trigger their own sequence; avoid conflicting rules.

mem_usage is measured in bytes and accepts thresholds such as 100MiB. cpu_percent may exceed 100 across multiple cores. monit performs a simple check without persistent cooldown; use cron or serve for persistent state.

Paths and variables

The default path is /etc/monit-docker/monit-docker.yml. Set it with -c or MONIT_DOCKER_CONFFILE. MONIT_DOCKER_CONFIG supplies inline YAML when the file does not exist; an existing file takes precedence.

MONIT_DOCKER_LOGFILE and MONIT_DOCKER_RUNTIMEDIR control log and runtime paths. The log parent directory must exist. Select persistent state separately with --state-file.

Mako configuration templates are trusted code: do not load configuration from unknown sources.

See the configuration and CLI contract for precedence, defaults, selectors and exit codes.

Direct command settings

Each command reads its own section. Explicit CLI flags take precedence. Repeated rule or resource flags replace the corresponding YAML list. An explicit monit --rsc selects observation even if YAML configures an action. Use --dry-run to preview rules for one invocation.

stats:
  rsc: [cpu_percent, mem_usage]
  output: json
serve:
  interval: 60
  status_token_file: /run/secrets/status