DeutschEnglish

Submenu

 - - - By CrazyStat - - -

30. January 2013

Nagios / Icinga: Monitor (local) memory usage

Filed under: Linux,Server Administration — Tags: , , , , , , , , , , , , , — Christopher Kramer @ 17:55

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.

  1. Download the plugin here
    e.g. from the shell:

    wget https://exchange.icinga.com/exchange/check_memory/files/784/check_memory.pl
  2. Then move the file to the other plugins
    mv check_memory.pl /usr/lib/nagios/plugins/check_memory.pl
  3. Make it executable
    chmod +x /usr/lib/nagios/plugins/check_memory.pl
  4. Try to run it:
    perl /usr/lib/nagios/plugins/check_memory.pl -w 50% -c 25%
  5. 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”).

  6. 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$
            }
  7. 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.

  8. Check your configuration:
    /usr/local/icinga/bin/icinga -v /etc/icinga/icinga.cfg
  9. 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.

Recommendation

Try my Open Source PHP visitor analytics script CrazyStat.

4 Comments »

  1. Dear Sir ,

    We are try to enable monitoring ram utilization in nagios (Linux based servers)like RHEL 6.0 we are facing the below error so kindly help us how to proceed further.

    ./check_snmp -H 192.168.50.61 -C SifyOpVps -o .1.3.6.1.4.1.2021.56.101.1
    External command error: Error in packet
    Reason: (noSuchName) There is no such variable name in this MIB.
    Failed object: iso.3.6.1.4.1.2021.56.101.1

    Comment by Raghu — 29. March 2013 @ 20:45

  2. @Raghu: You are monitoring ram utilization over snmp (not using the local plugin as described here). The snmpd server installed on the monitored system does not seem to include the variable you specified.
    Have you tried querying the data manually with snmpwalk or snmpget?
    Like
    snmpwalk -v1 -c SifyOpVps 192.168.50.61 memory
    snmpget -v1 -c SifyOpVps 192.168.50.61 .1.3.6.1.4.1.2021.56.101.1

    Maybe the MIB is just incorrect, or the snmpd server is not configured correctly.

    Comment by Christopher Kramer — 2. April 2013 @ 22:00

  3. Thank you, works nicely. Using it on remote servers with NRPE.

    Comment by Jason Robinson — 24. April 2013 @ 06:39

  4. Thanks for this great tut! It works great with NRPE!

    Comment by Smika — 26. August 2013 @ 09:24

RSS feed for comments on this post. TrackBack URL

Leave a comment