Server storage monitoring with Monit allows you to keep a check on your home server or web server storage space. Monit is an automatic monitoring, maintenance, and repair utility for Unix systems. If the resource usage is high Monit will send you an email alert. You can then examine and resolve any issues. In this Monit tutorial, I will describe automatic drive space monitoring with Monit for your home server. By server storage monitoring I mean how full any of your drive partitions are. I am assuming that you have already installed and configured Monit following my previous guide.
Determine the Drive Partitions to Monitor
Before you setup storage monitoring with Monit, you need to know what drives and partitions you want to monitor. If you remember my recently built HTPC-NAS combo, I have two hard drives on my server (sda, which is a SSD and sdb, which is a 4 TB HDD). sda has 3 partitions (sda1, sda2, and sda3). I wanted to monitor only sda1 (root) partition and sda3 (home partition). sdb has only one partition. If you do not know which ones to monitor use the
lsblk command. The output will look like what is shown below.
So, I wanted to monitor in total 3 partitions (sda1, sda3, and sdb1).
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
Server Storage Monitoring with Monit
Next, 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
/etc/monit/conf.d folder. For drive space monitoring with Monit, create a Monit configuration file using the following command:
Copy the following contents to it, save, and exit (press Ctrl X, press Y, and press ENTER).
# add each drive you want to monitor below check filesystem Ubuntu with path /dev/sda1 if space usage > 90% then alert check filesystem Home with path /dev/sda3 if space usage > 90% then alert check filesystem Media with path /dev/sdb1 if space usage > 90% then alert
The code above code will monitor hard drive space in 3 partitions in 2 drives. If any of them is more than 90% full, I will receive and email alert. An example of Monit alert is shown below.
So, use the
lsblk command and customize the code above. You may also customize the partition names (Ubuntu, Home, and Media) and/or set a different fill percentage than 90.
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 Monit configurations using the following command:
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 the monitored partitions listed with percent fill level as shown in the picture below.
That is it for Storage monitoring with Monit. As you can see Monit allows for automatic drive space 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.