Install monit standard Ubuntu version, then upgrade to latest:
apt install monit -y
service monit stop
apt remove monit -y
cd /tmp
wget --no-check-certificate https://mmonit.com/monit/dist/binary/5.32.0/monit-5.32.0-linux-x64.tar.gz
tar -xf monit-5.32.0-linux-x64.tar.gz
cd monit-5.32.0
sudo cp bin/monit /usr/bin/monit
sudo ln -s /etc/monit/monitrc /etc/monitrc
Add database user, otherwise there will be many failed/aborted database connections (because of Monit’s auto check):
CREATE USER 'monit'@'localhost' IDENTIFIED BY 'yourpassword';
FLUSH PRIVILEGES;
Monit syntax:
check process mysqld with pidfile /run/mysqld/mysqld.pid
start program = "/usr/bin/systemctl start mariadb" with timeout 60 seconds
stop program = "/usr/bin/systemctl stop mariadb"
if failed unixsocket /var/run/mysqld/mysqld.sock
protocol mysqls username "monit" password "yourpassword"
then restart
# Admin will notify by mail if below of the condition satisfied.
if cpu is greater than 20% for 1 cycles then alert
Finished!
service monit restart