Website Monitoring with Nagios

website monitoring nagios

By Jonathan Sundqvist, Engineer at Server Density.
Published on the 16th June, 2016.

Have you ever wondered how your website performs when accessed from the other side of the globe? Is it as responsive in Tokyo as it is in Paris?

The good news is, you can use Nagios to monitor HTTP (using any of the 30 available plugins) and TCP (15 plugins).

The not so good news is that for every location you want to monitor you would need to setup a corresponding server. Say you want to monitor 5 locations, you’d need to setup 5 servers to perform those checks and forward them to Nagios. That is 5 times the setup time. Time you could spend fine-tuning your marvellous website instead.

Well, laziness is a virtue when you are a developer. So let’s find a “lazy” way of doing this, shall we?

Use existing infrastructure to perform website monitoring with Nagios

Good programmers are great at reusing code. So why not extend this notion to servers and infrastructure? Why not use someone else’s global infrastructure to automatically perform your web checks, without any setup or hassle?

Server Density operates 42 monitoring locations around the world, continuously checking websites and TCP hosts (which makes us a great Pingdom alternative!) Our locations are scattered around the world, from the US to China and everywhere in between. We’ve even got the middle of Oceania covered. Our web checks speak both IPv4 and IPv6 and you can even search for keywords when you do the check, to ensure the page has loaded as expected.

Here’s what’s cool about this:

Using a simple Nagios plugin (keep reading) you can leverage the entire Server Density infrastructure and feed the results into Nagios.

Not bad, right? Here is how you do it.

Configure the plugin

The first thing you need to do is copy the plugin to the Nagios plugins directory. You need to include the plugin path in resource.cfg which is located in /usr/local/nagios/etc. Out of the box, the plugin path is likely to be /usr/local/nagios/libexec.

Cd into the plugin directory and execute the lines below.

Now that the plugin is in place you need to configure it. Here is a nice guide for setting up the first few Nagios checks. For the purposes of this exercise I will assume you have a similar setup to the one described there.

Let’s now configure the actual command that executes the plugin. Head over to commands.cfg (or where you store your custom commands) and paste the following:

Okay, let’s unpack this a bit.

To use the infrastructure at Server Density all you need to do is create a free trial account and fill in a few details:


Once you’ve created a service, you’ll see the ID of that service in the URL bar (the ID argument).

In the preferences and in the security section you are able to create a token which you’ll need as one of the arguments.

The argument slow allows you to set a threshold (in seconds) of how “slow” a response time can be. If response time exceeds this threshold then the plugin will send a warning to Nagios.

The argument allowed-status lets you define the acceptable HTTP status types. If the response is a status code other than the ones defined here, then the plugin sends Nagios a critical warning.

The locations argument defines the threshold for the amount of locations the above arguments can trigger collectively, before you get alerted (the lower the location threshold, the more alerts you should expect to get).

Note that instead of hard coding the arguments you could use the Nagios $arg$ macro instead.

Setup a host for the website monitoring plugin

Paste the following snippet to where your hosts are configured.

In the above snippet you need to edit host_name for what you want it to be in the Nagios UI. You’ll also need a valid network address. Since the check itself is defined within Server Density, I’ve used If you’re using the host for other things in Nagios then you might want to change it to something else.

The final step is to define a Nagios service for the hosts to send their data to. All you need to do is paste the following snippet to where you keep your service configurations.

Don’t forget to replace check_command with your actual command.

You then need to run the following command to make sure that everything is as it should be:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

The only thing left to do is to restart the Nagios service.

Next Steps

Smile! You now have web check monitoring from no less than 42 locations, all done with minimal effort and without leaving Nagios.

To get started with the plugin just fill in the form below and you’ll get started in no time.

Free eBook: The 9 Ingredients of Scale

From two students with pocket money, to 20 engineers and 80,000 servers on the books, our eBook is a detailed account of how we scaled a world-class DevOps team from the ground up. Download our definitive guide to scaling DevOps and how to get started on your journey.

Help us speak your language. What is your primary tech stack?

What infrastructure do you currently work with?

Articles you care about. Delivered.

Help us speak your language. What is your primary tech stack?

Maybe another time