Nagios and its fork icinga are great monitoring tools. They come with a bundle of plugins to monitor standard services such as HTTP, SMTP, POP3, load and stuff like that. And there are lots of 3rd party plugins available for almost everything else you can think of.
But one standard thing that is missing in the official nagios-plugins package is a plugin to check memory usage (of the local machine).
So here is how to install one. I assume a Debian system with Icinga running – you might want to adjust paths for other distros or nagios.
- Download the plugin here
e.g. from the shell:wget https://exchange.icinga.com/exchange/check_memory/files/784/check_memory.pl
- Then move the file to the other plugins
mv check_memory.pl /usr/lib/nagios/plugins/check_memory.pl
- Make it executable
chmod +x /usr/lib/nagios/plugins/check_memory.pl
- Try to run it:
perl /usr/lib/nagios/plugins/check_memory.pl -w 50% -c 25%
- This should give something like “CHECK_MEMORY OK – […] free […]”. If an error occurs, you probably need to install the perl module Nagios::Plugin. On Debian, the easiest way is:
apt-get install libnagios-plugin-perl
On other distros, you might use CPAN:
perl -MCPAN -e 'install Nagios::Plugin'
This will ask you lots of questions and install lots of dependencies (where you should say “yes”).
- Configure the check_memory command. To do this, create a file /etc/nagios-plugins/config/memory.cfg with this content:
# 'check_memory' command definition define command{ command_name check_memory command_line perl /usr/lib/nagios/plugins/check_memory.pl -w $ARG1$ -c $ARG2$ }
- Now you can use the check_memory command to define a service. For example, add this to /etc/icinga/objects/localhost_icinga.cfg (assuming you define localhost-services there):
define service{ use generic-service host_name localhost service_description Memory check_command check_memory!50%!25% }
This will send you a warning when memory usage is 50% and critical when only 25% is free. You might want to adjust these values of course depending on what is normal on your system and how early you want to be notified.
- Check your configuration:
/usr/local/icinga/bin/icinga -v /etc/icinga/icinga.cfg
- Restart Icinga / Nagios if the preflight-check was okay:
/etc/init.d/icinga restart
This should be it.
I hope this helped somebody.
To monitor memory usage of a remote server, you’ll need SNMP for example. Maybe I’ll post another blog post on this soon.