Monitor services and email alerts (monit)
Automatically restart downed services and receive email alerts.
What this tutorial does
The tutorial "Monitor services and email alerts (monit)" helps you achieve this goal:
Automatically restart downed services and receive email alerts.
Debian/Ubuntu
-
Install monit: apt install -y monit - --- Main configuration: /etc/monit/monitrc ---
- Uncomment and configure the web interface:
- set httpd port 2812 and use address localhost
- allow admin:password
- Configure email alerts:
- set mailserver smtp.gmail.com port 587
- username "[email protected]" password "app_password"
- using tlsv12
- set alert [email protected]
- --- Monitor Apache ---
- Create /etc/monit/conf.d/apache:
- check process apache2 with pidfile /var/run/apache2/apache2.pid
-
start program = "/bin/systemctl start apache2" -
stop program = "/bin/systemctl stop apache2" - if cpu > 80% for 2 cycles then alert
- if memory > 512 MB then alert
- --- Monitor disk space ---
- check filesystem rootfs with path /
- if space usage > 85% then alert
- --- Start monit ---
-
systemctl enable --now monit -
monit reload && monit status