monit-docker

MONIT-DOCKER / v0.0.64

Serve mode

Collect continuously, expose JSON status and provide Prometheus metrics.

1. Start the agent

After installation, run in a terminal:

monit-docker serve --interval 30

The first cycle starts immediately. Each cycle is followed by a 30-second wait; this is not a fixed start-to-start period. The default listener is 127.0.0.1:9808. Without rules, it only observes and needs no state file.

2. Check the endpoints

From a second terminal:

curl -fsS http://127.0.0.1:9808/healthz
curl -i http://127.0.0.1:9808/readyz
curl -fsS http://127.0.0.1:9808/v1/status
curl -fsS http://127.0.0.1:9808/metrics
EndpointMeaning
/healthzHTTP 200: process is alive, even if Docker fails.
/readyzHTTP 200 when ready, otherwise 503.
/v1/statusLatest snapshot and ready field; HTTP 200 may contain ready=false.
/metricsPrometheus format. HTTP 200 does not guarantee valid collection.

3. Persistent Docker variant

docker run -d --name monit-docker-agent --restart unless-stopped \
  -p 127.0.0.1:9808:9808 \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  decryptus/monit-docker:0.0.64 \
  monit-docker serve --bind 0.0.0.0 --interval 30

docker logs monit-docker-agent

Stop the terminal agent before reusing port 9808. The 0.0.0.0 bind is inside the container; the published port stays on host loopback. Stop this variant with docker stop monit-docker-agent.

4. Add a rule

monit-docker --name 'web*' serve --interval 30 \
  --state-file "$HOME/.local/state/monit-docker/web.json" \
  --cooldown 600 --trigger-after 300 --max-gap 120 \
  --dry-run --cmd-if 'mem_percent > 90 ? restart'

This first test performs no actions. After review, remove --dry-run to enable actions and persistent observation tracking. Rules require a state file, including in dry-run. With Docker, mount its entire directory, including the lock.

max-gap must exceed the collection interval. An unconditional --cmd does not wait for trigger-after.

5. Operate the agent

The read API has no built-in authentication or TLS. Keep it on localhost or a private network. For browser access, install the HTTPS proxy and interface.

By default, snapshots expire after max(90, 3 × interval) seconds. Failed or stale collection hides container metrics. Prometheus stores history; agent snapshots stay in memory.

Ctrl+C or SIGTERM requests shutdown and waits for the current cycle. There is no guaranteed maximum total shutdown time.