I used to run this site on a very cheap web host. It seemed perfect, until a month or so after setting it up my site would periodically crash from a lack of memory. I figured I was getting was I was paying for ($1/month hosting isn’t really designed for long-term use), and decided to move back to AWS, and then finally settled on DigitalOcean as the cheapest option I could find ($5/month).
Nevertheless, I became distrusting of VPS’s (once bitten, twice shy), and this distrust was a big motivator into building a monitoring solution at home with Nagios.
Trying to find a guide on monitoring a website with Nagios wasn’t straightforward though, so I’m just going to post here what I got working. I also monitor Google and my employer’s website, just so I can discern between an individual host failure or problem with my ISP.
So first off, I created a new file called
/usr/local/nagios/etc/objects/websites.cfg. Then, with a text editor, I defined the following hosts:
You can see I’ve put the IP addresses in for the sites, so there’s no dependency on DNS (I’ve got separate checks for my DNS server). The easiest way to get the IP address is either by pinging the site (
ping google.com.au) or by performing a name server lookup (
I’ve also set them to use the
linux-server template. This could be incorrect, but it works for me as the
check_http commands are defined for that template.
Then, further down in the same
websites.cfg file, we have the service definitions:
The first just checks that the site responds in a timely manner. The second checks that the SSL certificate is valid, and also will give me a warning at 30 days (and critical at 14 days) that it will expire. I’ve excluded Google from the SSL check, as I don’t care about their certificates.
Now it’s just a case of editing
/usr/local/nagios/etc/nagios.cfg and adding in the new configuration file we created:
# Definitions for monitoring Websites
It’s totally up to you where you put the host and service definitions. You can integrate them with one of the other files too if you like.
Oh and don’t forget to restart nagios when you’re done, to see the changes reflected:
service nagios restart
Here’s what mine looks like once the checks have been performed: