http://xmodulo.com/2014/09/monitor-server-memory-usage-nagios-remote-plugin-executor.html
In a previous tutorial, we have seen how we can set up Nagios Remote Plugin Executor (NRPE) in an existing Nagios setup. However, the scripts and plugins needed to monitor memory usage do not come with stock Nagios. In this tutorial, we will see how we can configure NRPE to monitor RAM usage of a remote server.
The script that we will use for monitoring RAM is available at Nagios Exchange, as well as the creators' Github repository.
Assuming that NRPE has already been set up, we start the process by downloading the script in the server that we want to monitor.
Now that the script is ready, we define the command to check RAM usage for NRPE. As mentioned before, the command will check free memory, warn when free memory is less than 20%, and generate critical alarm when free memory is less than 10%.
For RHEL/CentOS 32 bit:
For RHEL/CentOS 64 bit:
For Debian/Ubuntu:
For RHEL/CentOS 32 bit:
For RHEL/CentOS 64 bit:
Now we define the service check in Nagios.
On Debian/Ubuntu:
On RHEL/CentOS:
Finally, we restart the Nagios service.
On Debian/Ubuntu:
In a previous tutorial, we have seen how we can set up Nagios Remote Plugin Executor (NRPE) in an existing Nagios setup. However, the scripts and plugins needed to monitor memory usage do not come with stock Nagios. In this tutorial, we will see how we can configure NRPE to monitor RAM usage of a remote server.
The script that we will use for monitoring RAM is available at Nagios Exchange, as well as the creators' Github repository.
Assuming that NRPE has already been set up, we start the process by downloading the script in the server that we want to monitor.
Preparing Remote Servers
On Debain/Ubuntu:
# cd /usr/lib/nagios/plugins/
# wget https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl
# mv check_mem.pl check_mem
# chmod +x check_mem
On RHEL/CentOS:# wget https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl
# mv check_mem.pl check_mem
# chmod +x check_mem
# cd /usr/lib64/nagios/plugins/ (or /usr/lib/nagios/plugins/ for 32-bit)
# wget https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl
# mv check_mem.pl check_mem
# chmod +x check_mem
You can check whether the script generates output properly by
manually running the following command on localhost. When used with
NRPE, this command is supposed to check free memory, warn when free
memory is less than 20%, and generate critical alarm when free memory is
less than 10%.# wget https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl
# mv check_mem.pl check_mem
# chmod +x check_mem
# ./check_mem -f -w 20 -c 10
OK - 34.0% (2735744 kB) free.|TOTAL=8035340KB;;;; USED=5299596KB;6428272;7231806;; FREE=2735744KB;;;; CACHES=2703504KB;;;;If you see something like the above as an output, that means the command is working okay.
Now that the script is ready, we define the command to check RAM usage for NRPE. As mentioned before, the command will check free memory, warn when free memory is less than 20%, and generate critical alarm when free memory is less than 10%.
# vim /etc/nagios/nrpe.cfg
For Debian/Ubuntu:
1
| command [check_mem]= /usr/lib/nagios/plugins/check_mem -f -w 20 -c 10 |
1
| command [check_mem]= /usr/lib/nagios/plugins/check_mem -f -w 20 -c 10 |
1
| command [check_mem]= /usr/lib64/nagios/plugins/check_mem -f -w 20 -c 10 |
Preparing Nagios Server
In the Nagios server, we define a custom command for NRPE. The command can be stored in any directory within Nagios. To keep the tutorial simple, we will put the command definition in /etc/nagios directory.
# vim /etc/nagios3/conf.d/nrpe_command.cfg
1
2
3
4
| define command { command_name check_nrpe command_line /usr/lib/nagios/plugins/check_nrpe -H '$HOSTADDRESS$' -c '$ARG1$' } |
# vim /etc/nagios/objects/nrpe_command.cfg
1
2
3
4
| define command { command_name check_nrpe command_line /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } |
# vim /etc/nagios/objects/nrpe_command.cfg
1
2
3
4
| define command { command_name check_nrpe command_line /usr/lib64/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } |
On Debian/Ubuntu:
# vim /etc/nagios3/conf.d/nrpe_service_check.cfg
1
2
3
4
5
6
| define service{ use local -service host_name remote-server service_description Check RAM check_command check_nrpe!check_mem } |
# vim /etc/nagios/objects/nrpe_service_check.cfg
1
2
3
4
5
6
| define service{ use local -service host_name remote-server service_description Check RAM check_command check_nrpe!check_mem } |
On Debian/Ubuntu:
# service nagios3 restart
On RHEL/CentOS 6:
# service nagios restart
On RHEL/CentOS 7:
# systemctl restart nagios.service
Troubleshooting
Nagios should start checking RAM usage of a remote-server using NRPE. If you are having any problem, you could check the following.- Make sure that NRPE port is allowed all the way to the remote host. Default NRPE port is TCP 5666.
- You could try manually checking NRPE operation by executing the check_nrpe command: /usr/lib/nagios/plugins/check_nrpe -H remote-server
- You could also try to run the check_mem command manually: /usr/lib/nagios/plugins/check_nrpe -H remote-server –c check_mem
- In the remote server, set debug=1 in /etc/nagios/nrpe.cfg. Restart the NRPE service and check the log file /var/log/messages (RHEL/CentOS) or /var/log/syslog (Debain/Ubuntu). The log files should contain relevant information if there is any configuration or permission errors. If there are not hits in the log, it is very likely that the requests are not reaching the remote server due to port filtering at some point.
No comments:
Post a Comment