Monit allows you to monitor web server status. If you are running a home server or a large-scale Linux server, you may also be using Apache and MySQL for serving websites. Or you may just be using Apache for reverse proxies and MySQL as Kodi library. Setting up reverse proxies for apps such CouchPotato and Transmission, make it easy to access them. MySQL, apart from storing data from dynamic websites, can also keep you media library synced on all Kodi devices. What if your Apache fails and you are unable to access your apps or MySQL fails and your Kodi media don't play? Monit is an automatic monitoring, maintenance, and repair utility for Unix systems. If your Apache or MySQL server fails, Monit can send you an email alert. It can even try to restart Apache and MySQL. In this Monit tutorial, I will describe how to 1) monitor Apache server with Monit, 2), monitor NGINX server with Monit, and 3) monitor MySQL server with Monit. I am assuming that you have already installed and configured Monit following my previous guide.
Table of Contents
Monitor Web Server Status with Monit
On my Ubuntu home server, I run Apache server and MySQL server for reasons described above. On my Ubuntu VPS that runs this website, I run NGINX. If one of them fails, I would not know until I try something (say play a video or access CouchPotato) and it fails. If my NGINX server is down, I won't know until I run a web site status check. Monit can notify server failures as soon as it happens. When I recently setup my new home server, I decided to use Monit for system monitoring. I use Monit to monitor several services listed below:
Monitor your home server with Monit:
- Home server system load monitoring (CPU, RAM, Swap)
- Server hard drive storage monitoring (HDD space)
- Motherboard temperature monitoring
- Processor or CPU temperature monitoring
- Monitor Hard drive SMART health and temperature
- Monitor file server status (Samba and NFS)
- Monitor web server status (Apache, NGINX, and MySQL)
- Monitor CouchPotato process status
- Monitor SickBeard process status
- Monitor SickRage process status
- Monitor SABnzbd process status
- Monitor Webmin process status
- Monitor qBittorrent process status
- Monitor Transmission process status
- Monitor ShellInABox process status
Since setting it up I have never had one Kodi streaming problem. So let us see how to automatically manage web server using Monit server monitor software.
Before enabling web server monitoring, it is required that you have a working Monit instance with a proper
/etc/monit/monitrc file. Monit configurations for various services are loaded from
Monitor Apache Server with Monit
Setting up Apache server monitoring with Monit is with Monit's pre-made configuration templates. All you have to do is copy the existing template from
sudo cp /etc/monit/monitrc.d/apache2 /etc/monit/conf.d/
Instead of copying, you may also create a symbolic link. Apache web server process creates
apache2.pid. The above code monitor
apache2.pid file and if does not exist, Monit will try to restart Apache. A restart will trigger an email alert as shown in the example below. If restart fails multiple times then Monit stops monitoring Apache server.
Monitor NGINX Server with Monit
Monit also provides templates for for NGINX server monitoring. Once again, all you have to do is copy the existing template from
sudo cp /etc/monit/monitrc.d/nginx /etc/monit/conf.d/
Instead of copying, you may also create a symbolic link. NGINX web server process creates
nginx.pid. The above code monitor
nginx.pid file and if does not exist, Monit will try to restart NGINX Server. A restart will trigger an email alert as shown in the example above. If restart fails multiple times then Monit stops monitoring NGINX server.
Monitor MySQL Server with Monit
Monit also provides templates for MySQL server monitoring. Once again, all you have to do is copy the existing template from
sudo cp /etc/monit/monitrc.d/mysql /etc/monit/conf.d/
Instead of copying, you may also create a symbolic link. MySQL database server process creates
mysqld.pid. The above code monitor
mysqld.pid file and if does not exist, Monit will try to restart MySQL Server. A restart will trigger an email alert as shown in the example above. If restart fails multiple times then Monit stops monitoring MySQL server.
Test and Reload Monit
Once you make any changes you have to test Monit configuration:
sudo monit -t
You should see the following message: Control File Syntax OK. Then, check to see if Monit is already running using the following command:
sudo /etc/init.d/monit status
If Monit is running, reload configurations using the following command to monitor web server status with Monit:
sudo /etc/init.d/monit reload
If Monit is not running, then start it using
sudo monit command instead. The whole sequence of commands for testing and reloading Monit is shown in the picture below.
Now, fire up your web browser and visit one of the following URLs depending on how your Monit is configured (be sure to use the correct port number):
- http://IPADDRESS:2812 (local network IP)
- http://domain.com:2812 (if you have domain name pointing to your server)
You should see Apache and MySQL web server statuses as shown in the picture below (NGINX is not shown in this example picture).
That is it to monitor web server status with Monit. As you can see Monit allows for automatic web server status monitoring, which can be a big help for system administrators. Monit Wiki page has several examples. More home server specific Monit examples to follow, so keep checking back.
IPVanish VPN Exclusive Offer - only $3.99 per month:
Windows, Android, Ubuntu
OSMC on RPi
♦ Hide your browsing (no logs), Anonymize Streaming and Downloads
♦ Circumvent Geo/Country Restrictions and access worldwide content
♦ Works on Windows, Mac, Linux, Android, iOS, Router, and more
♦ 250 GB of SugarSync Secure storage included
♦ Money back guarantee - Sign Up Now