How To Monitor Remote Linux Machines With Nagios

How To Monitor Remote Linux Machines With Nagios

In the last article, we have briefly gone through the installation of Nagios server on CentOS 7 to monitor application services. As I said in the last post, the Nagios server is monitoring services running locally, ie on own machine, not the remote host.

READ: How To Install Nagios On CentOS 7

To monitor services running on remote machines, we would need to install NRPE plugin. This plugin allows us to execute Nagios plugins on remote Linux machine to monitor applications, services, and resources.

Here, in this post, we will add a remote Linux host to Nagios server for monitoring.

Environment

Nagios Server

Host Name: server.linuxbees.local
IP Address: 192.168.1.10
OS: CentOS 7

Nagios Client

Host Name: client.linuxbees.local
IP Address: 192.168.1.50
OS: CentOS 7

On Remote Linux Machine

You need to configure the EPEL repository to get the NRPE and Nagios plugins.

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Install NRPE & Nagios Plugins

Use the yum command to install NRPE Add-on and Nagios plugins.

yum install nrpe nagios-plugins-all

Configure NRPE

Modify the NRPE configuration file to accept connections from the Nagios server. Edit the /etc/nagios/nrpe.cfg file.

vi /etc/nagios/nrpe.cfg

Add the Nagios servers IP address.

allowed_hosts=192.168.1.10

Nagios Checks

The nrpe.cfg file contains the basic command definitions to check CPU, Memory, Disk, HTTP, FTP, etc on remote hosts.

vi /etc/nagios/nrpe.cfg

For a demo, I will only monitor three resources. Command definition will look like below.

You may find a few hard coded command arguments at the end of the file. You can modify those arguments or use below.

command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200
-w stands for warning and -c stands for critical.

Restart the NRPE service.

systemctl start nrpe
systemctl enable nrpe

Firewall

Configure the firewall to allow Nagios server to reach NRPE server running on remote Linux host. Run these commands on remote Linux machine.

firewall-cmd --permanent --add-port=5666/tcp
firewall-cmd --reload

On Nagios Server

NRPE plugins available in EPEL repository, so configure it on your machine.

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Install NRPE plugin

Use yum command to install the NRPE plugin on your machine.

yum -y install nagios-plugins-nrpe

Edit the nagios.cfg file to include all .cfg files inside the /usr/local/nagios/etc/servers directory. In this directory, we will place the remote host information.

vi /usr/local/nagios/etc/nagios.cfg

Add or uncomment the following line.

cfg_dir=/usr/local/nagios/etc/servers

Create a configuration directory.

mkdir /usr/local/nagios/etc/servers

Configure NRPE Plugin

Edit command.cfg file.

vi /usr/local/nagios/etc/objects/commands.cfg

Add the NRPE plugin information.

# .check_nrpe. command definition
define command{
command_name check_nrpe
command_line /usr/lib64/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$
}

Add a Remote Linux host to Nagios server

Create a client configuration file to define the host and service definitions of remote Linux host. The following template is for monitoring logged in users, system load, and total process.

vi /usr/local/nagios/etc/servers/client.tbc.local.cfg

Copy the below content to the client file.

define host{

            use linux-server
            host_name client.linuxbees.local
            alias client.linuxbees.local
            address 192.168.1.50

            }

define hostgroup{

            hostgroup_name linux-server
            alias Linux Servers
            members client.linuxbees.local
}

define service{

            use local-service
            host_name client.linuxbees.local
            service_description Current Users
            check_command check_nrpe!check_users

}

define service{

            use local-service
            host_name client.linuxbees.local
            service_description Total Processes
            check_command check_nrpe!check_total_procs

}

define service{

            use local-service
            host_name client.linuxbees.local
            service_description Current Load
            check_command check_nrpe!check_load

}

Verify Nagios for any errors.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Restart the Nagios server.

service nagios restart

Monitor the Remote machine

Check the Nagios web interface, you would see the client Linux machine we added just now.

Remote Linux Machine in Nagios

Within a minute, Nagios would start checking the status of resources. You should start seeing status information in Services page.

Monitor Remote Linux Machine With Nagios

Conclusion

You have learned how to monitor the remote Linux system usage metrics like disk usage, CPU load, etc with the help on NRPE plugin. Share your feedback in the comments section.

comments powered by Disqus