The mntr (monitor) is a SystemD daemon to monitor and watch for a high CPU usage and reboot server. This is sometimes needed as a tool of the last resort when a service used so much CPU that even SSH doesn't work. Rebooting is also clears the TCP connections table so that if you have connection leaks this will help you. The service can send an alert on a high CPU usage and when reboot is triggered.
For Ubuntu use PPA repository:
sudo add-apt-repository ppa:stokito/utils
sudo apt update
sudo apt install mntr
Or install by downloading the package:
wget -O /tmp/mntr https://github.com/yurt-page/mntr/releases/download/v1.1.0/mntr_1.1.0_all.deb
sudo dpkg -i /tmp/mntr
rm -f /tmp/mntr
sudo cp -r dist/* /
sudo chmod +x /usr/bin/notify.sh
# install service
sudo systemctl daemon-reload
sudo systemctl enable mntr
# Configure (see bellow), start the service and check logs
sudo systemctl restart mntr
journalctl -n 200 -f -u mntr
git clone [email protected]:yurt-page/mntr.git
cd mntr
# install files, service and reload systemd services
sudo make install_all
# reload to test after changes
sudo make restart
To check CPU count use lscpu
.
Edit the /etc/default/mntr
to set limits:
# Send notification if only three free CPUs left
ALERT_CPU_LIMIT="-3"
# Hard reboot if load is over the 2 CPUs
REBOOT_CPU_LIMIT="2"
Edit the /etc/default/notify
to set Telegram chat for an alert:
TG_BOT_TOKEN=""
TG_CHAT_ID=""
Then restart with sudo systemctl restart mntr
.