Monit and it’s big (paid for) brother M/Monit are great tools for monitoring processes on your Raspberry Pi (or any Linux based system). The first thing to note though is that Monit cannot be used to monitor processes started using a systemd service file (as that can be set to recover it’s own daemons), rather it can just monitor daemons started using init.
However, that is not the whole story as Monit can monitor many other things, too numerous to mention, but including http services, and even if a file, that should be written regularly has been written to (I use this to monitor pywws).
It is easy to install, sudo apt-get install monit and there are plenty of resources out there on setting Monit up. There is one key thing to remember, all of the output basically comes from the httpd interface so this has to be enabled. Even a sudo monit status will fail without that being setup and it isn’t by default. So before you do anything you need to edit the file sudo nano /etc/monit/monitrc .
In this file look for the following set httpd ; I then change the text to read as follows (X.X.X.0 being your IP range):
set httpd port 2812
I run all of my Pis headless so I want to be able to connect from other machines on the local network. I don’t bother changing the usual port as I block that at a higher level and as yet have not used any username/password, but it is easily set up.
Exit the editor and restart the Monit service sudo service monit restart
The final thing you need to do is open the port on ufw sudo ufw allow 2812/tcp and reload it sudo ufw reload; you have installed and enabled ufw, haven’t you?
So I tried to follow my own advice on an OrangePi running DietPi and the lines above to enable monit access would not work. Instead I got this error:
root@MyPi:~# sudo monit status
Cannot read status from the monit daemon
Interestingly I could access it from a remote host on the network via http://x.x.x.x:2812 but not in an ssh session.
The solution was to add:
to the above lines to the
monitrc file and then it was happy. Not sure why the 2 installations differed, but they did!