After setting up 329423 services and 823423 containers, you might want to manage your environment in case some service fails. This can be automated restarting, getting notified about failures or a similar thing. Say no more, I've created a Dockerfile and image for Monit for this.
Monit is extremely configurable and allows a maximum of flexibility when it comes to monitoring.
Initially, a configuration file is required to get started. To get one, call
docker run \ -d \ --name=monit \ --restart=always \ --expose 2812 \ -p 127.0.0.1:2812:2812 \ --entrypoint monit ps1337/monit-docker -I && \ docker exec -it monit bash -c "cat /etc/monitrc" && \ docker rm -f monit
and save the output to
To finally monitor services on a machine, you can use this command:
docker run \ -d \ --name=monit \ --restart=always \ -v $PWD/monitrc:/etc/monit/monitrc \ --expose 2812 \ -p 127.0.0.1:2812:2812 \ ps1337/monit:latest
This runs Monit on
localhost for security reasons - change this if required.
After doing the initial setup, one can start monitoring for example
- Remote services
- Local containers using
- System load
You can then refer to the Monit manual for information on adding hosts to monitor.
One helpful option to use is
exec, which executes shell scripts in case a service fails:
check host yolo with address yolo.party if (failed port 80 protocol http with timeout 15 s) retry 5 then exec "/opt/scripts/telegramNotification.sh 'FAIL'"