Press "Enter" to skip to content

Monitoring your server with Nagios

One of the fundamental aspects in the maintenance of a server is monitoring.

This post explains how to install and configure the core of nagios in a CentOS 7 server as well as the configuration of various service checks.

It should be noted that there are numerous monitoring tools in the market, most of them you must pay and consume a lot of resources. That is why here we explain to use the core of nagios since it is quite light and it is also free.

First of all you need to download the latest version of nagios core and nagios core plugins from Nagios’s official website:

A LAMP stack must be installed on the monitoring server before install Nagios, you can follow this tutorial

In addition the LAMP stack, the following packages must be installed before install nagios core:

Next step is to create a user named ‘nagios‘ & a group named ‘nagcmd‘ for running nagios:

Add ‘nagios’ and ‘apache’ users to the group ‘nagcmd’:

Compile and install the source code for the latest stable release of Nagios Core:

Web interface will be installed with a default user by the name ‘nagiosadmin‘ but there will be no default password for the user. We will set up the password for this user by issuing the following command:

We have now completed installation for nagios core but we need to install plugins/scripts as without them we can’t monitor the resources. So open the directory with nagios plugin files,compile them and install the plugins:

Last step before wake up nagios service is to verify Nagios configuration against the default configuration file:

You should see the check list and make sure there are no errors:

This will ensure that all the settings made to nagios configuration file are correct and if there is any issue with file, it will report that as well.

It is also important to configure nagios service to start at boot time:

Nagios is ready to be started. Let’s do that, and restart Apache:

Now we can navigate to nagios web interface (http://<server IP>/nagios) and we can go to “services” or “hosts” tab in order to view the status of the currently configured service checks. You should see something like this:

Now it’s time to get under the hood and set up our own checks.

Example 1

Imagine that we want to change the port of the SSH status check. We must follow the following steps:

1- See the documentation of SSH check (all plugins/scripts checks are located under “/usr/local/nagios/libexec“):

2- We can see that using ‘-p’ option we can specify the port of the service check. We can test it, and check the SSH status if it’s listening on port 2244 for example:

3- Finally we must modify the SSH service check of our localhost by modifying the ‘/usr/local/nagios/etc/objects/localhost.cfg’ file. Specifically we modify the command check and we can specify options to the command using the character ‘!’:

We must reload the config of nagios service:

On the web interface we must force a re-check action on the service to get the new status.

Example 2

To monitor CPU usage we must keep in mind the number of cores that our server has since the thresholds must be calculated based on the following formula:

translated_value = (nº cores * threshold(%) ) / 100

Here is an example of translated values:

WARNING -> 85% (1m) , 80% (5m), 75% (15m) -> 1.7 (1m), 1.6 (5m), 1.5 (15m)

CRITICAL -> 95% (1m) , 90% (5m), 85% (15m) -> 1.9 (1m), 1.8 (5m), 1.7 (15m)

Example 3

You can also add your own plugin/script checks.

1- You have to move the new script to ‘/usr/local/nagios/libexec‘ path and give him the proper permissions:

2- We can test it and if it works we can add this plugin/script to the list of allowed commands. We must modify ‘/usr/local/nagios/etc/objects/commands.cfg’ file:

3- And finally add this new check to the list of service checks of our server modifying the file ‘/usr/local/nagios/etc/objects/localhost.cfg’

On the next post we will explain how to configure nagios to send alerts to our e-mail using Gmail SMTP servers.

Enjoy! 🙂


  1. Psyco
    Psyco 29 January, 2018

    Great! So useful

  2. Jack Main
    Jack Main 30 January, 2018

    Really interesting! Waiting for the next post!

  3. Tinker
    Tinker 30 January, 2018

    Ver y interesting,. It’s very use fue, thank you

    • Carlos Martin-Cleto
      Carlos Martin-Cleto 30 January, 2018

      Really appreciate it! 🙂

  4. Pablo Cloreno
    Pablo Cloreno 31 January, 2018

    Really nice bro.

    I like so much for posts, you are the number one

    • Carlos Martin
      Carlos Martin 1 February, 2018

      Thanks Pablo! I’m glad to hear it !

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.