Has anyone an plugin for linux memory in NAGIOS?


#1
  1. I can’t find an plugin fot memory in nagios for linux servers. Only for nt servers. Please help!
  2. I can’t open in browser statuswrl. Any clue? :cry:

#2

Hi

1 Below is a perl script we altered a little to do a memory check on a linux box. It runs using the NRPE plugin so once you have that configured just put the script in your plugins folder and define it in the nrpe.cfg file. What’s important is the awk command to return the correct information. You may need to edit this depending on how your version of linux displays the results of free -m

  1. If you want to view the statuswrl you need a VRML plugin for your browser. I found mine here cic.nist.gov/vrml/vbdetect.html

Adathaim

--------------------- check_mem.pl ----------------------------------

#!/usr/bin/perl -w

$Id: check_mem.pl,v 1.1.1.1 2002/02/28 06:42:54 egalstad Exp $

check_mem.pl Copyright © 2000 Dan Larsson [email protected]

This program is free software; you can redistribute it and/or

modify it under the terms of the GNU General Public License

as published by the Free Software Foundation; either version 2

of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty

of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

you should have received a copy of the GNU General Public License

along with this program (or with Nagios); if not, write to the

Free Software Foundation, Inc., 59 Temple Place - Suite 330,

Boston, MA 02111-1307, USA

Tell Perl what we need to use

use strict;
use Getopt::Std;

use vars qw($opt_c $opt_f $opt_u $opt_w
$free_memory $used_memory $total_memory
$crit_level $warn_level
%exit_codes @memlist
$percent $fmt_pct
$verb_err $command_line);

Predefined exit codes for Nagios

%exit_codes = (‘UNKNOWN’ ,-1,
‘OK’ , 0,
‘WARNING’ , 1,
‘CRITICAL’, 2,);

Turn this to 1 to see reason for parameter errors (if any)

$verb_err = 0;

This the unix command string that brings Perl the data

$command_line = free -m | awk '{ print \$16, \$17}' RS='\f';

chomp $command_line;
@memlist = split(/ /, $command_line);

Define the calculating scalars

$used_memory = $memlist[0];
$free_memory = $memlist[1];
$total_memory = $used_memory + $free_memory;

Get the options

if ($#ARGV le 0)
{
&usage;
}
else
{
getopts(‘c:fuw:’);
}

Shortcircuit the switches

if (!$opt_w or $opt_w == 0 or !$opt_c or $opt_c == 0)
{
print “*** You must define WARN and CRITICAL levels!” if ($verb_err);
&usage;
}
elsif (!$opt_f and !$opt_u)
{
print “*** You must select to monitor either USED or FREE memory!” if ($verb_err);
&usage;
}

Check if levels are sane

if ($opt_w <= $opt_c and $opt_f)
{
print “*** WARN level must not be less than CRITICAL when checking FREE memory!” if ($verb_err);
&usage;
}
elsif ($opt_w >= $opt_c and $opt_u)
{
print “*** WARN level must not be greater than CRITICAL when checking USED memory!” if ($verb_err);
&usage;
}

$warn_level = $opt_w;
$crit_level = $opt_c;

if ($opt_f)
{
$percent = $free_memory / $total_memory * 100;
$fmt_pct = sprintf “%.1f”, $percent;
if ($percent <= $crit_level)
{
print “Memory CRITICAL - $fmt_pct% ($free_memory k:roll: free | total=$total_memory, used=$used_memory, free=$free_memory\n”;
exit $exit_codes{‘CRITICAL’};
}
elsif ($percent <= $warn_level)
{
print “Memory WARNING - $fmt_pct% ($free_memory k:roll: free | total=$total_memory, used=$used_memory, free=$free_memory\n”;
exit $exit_codes{‘WARNING’};
}
else
{
print “Memory OK - $fmt_pct% ($free_memory k:roll: free | total=$total_memory, used=$used_memory, free=$free_memory\n”;
exit $exit_codes{‘OK’};
}
}
elsif ($opt_u)
{
$percent = $used_memory / $total_memory * 100;
$fmt_pct = sprintf “%.1f”, $percent;
if ($percent >= $crit_level)
{
print “Memory CRITICAL - $fmt_pct% ($used_memory k:roll: used | total=$total_memory, used=$used_memory, free=$free_memory\n”;
exit $exit_codes{‘CRITICAL’};
}
elsif ($percent >= $warn_level)
{
print “Memory WARNING - $fmt_pct% ($used_memory k:roll: used | total=$total_memory, used=$used_memory, free=$free_memory\n”;
exit $exit_codes{‘WARNING’};
}
else
{
print “Memory OK - $fmt_pct% ($used_memory k:roll: used | total=$total_memory, used=$used_memory, free=$free_memory\n”;
exit $exit_codes{‘OK’};
}
}

Show usage

sub usage()
{
print “\ncheck_mem.pl v1.1 - Nagios Plugin\n\n”;
print “usage:\n”;
print " check_mem.pl -<f|u> -w -c \n\n";
print “options:\n”;
print " -f Check FREE memory\n";
print " -u Check USED memory\n";
print " -w PERCENT Percent free/used when to warn\n";
print " -c PERCENT Percent free/used when critical\n";
print “\nCopyright © 2000 Dan Larsson <[email protected]>\n”;
print “check_mem.pl comes with absolutely NO WARRANTY either implied or explicit\n”;
print “This program is licensed under the terms of the\n”;
print “GNU General Public License (check source code for details)\n”;
exit $exit_codes{‘UNKNOWN’};
}


#3

If this is the same as the one in the contrib folder, it deosn’t work. I have a machine with 2GB of RAM, top says:

Mem: 2074484k total, 1500392k used, 574092k free, 125868k buffers

check_mem.pl says:

Memory Usage WARNING 25-01-2006 12:58:36 0d 3h 12m 27s 4/4 Memory WARNING - 81.7% (559916 k:roll: used


#4

I’ve encountered that error as well. My guess is that the values defined in the plugin are incorrect. It seems that it reflects available memory as used memory, and therefore will only return an OK status when memory is actually critical.

However, there is a check command that’s called check_mem aside from the perl file in the contrib folder. I can’t remember exactly where it is, but if it doesn’t come with the standard plugins, then check Nagiosexchange.org.

You’ll still need NRPE to run this check locally on remote hosts, of course, as it’s still a local check.
Edited Wed Jan 25 2006, 12:31AM ]