[Nagiosplug-devel] patch: contrib/check_mem.pl using incorrect command
Cook, Garry
GWCOOK at mactec.com
Tue Aug 17 16:03:18 CEST 2004
nagiosplug-devel-admin at lists.sourceforge.net wrote:
> Hi All
>
> I've just noticed that check_mem.pl from the contrib section
> is using the
> following command to check memory useage:
> vmstat | tail -1 | awk '{print \$4,\$5}'
> And then treating the two numbers it gets back as used and
> free memory
> respectively.
>
> Only one slight problem - all the copies of vmstat I can find report:
> procs-r procs-b procs-w swap-used mem-free ....
> i.e. the 5th value is the free memory, but the 4td is swap
> useage, not
> total memory useage.
>
> To get memory useage and free memory, you need to use command "free"
> (on all the systems I have, at any rate). The following patch will get
> check_mem.pl to check for free and used memory, ignoring
> memory used for
> buffering:
>
>
> --- check_mem.pl.old 2004-08-16 16:30:45.000000000 +0100
> +++ check_mem.pl 2004-08-16 16:35:43.000000000 +0100 @@ -39,7
> +39,7 @@ $verb_err = 0;
>
> # This the unix command string that brings Perl the data
> -$command_line = `vmstat | tail -1 | awk '{print \$4,\$5}'`;
> +$command_line = `free | head -3 | tail -1 | awk '{print \$3,\$4}'`;
>
> chomp $command_line;
>
>
> Could someone verify this patch does the right things, and if
> it does,
> update the contrib with it?
>
> Thanks
> Nick
I can verify that neither of them works properly on my system (RH9). The
'-f' option to get free memory does not work at all. However, with the
-u option, it does appear to work as you have said in the original
version, but the patched version does not. Observe:
/usr/local/src/nagios/nagios-plugins-HEAD-200408121647/contrib: top
07:15:14 up 180 days, 18:56, 3 users, load average: 1.05, 0.73, 0.66
120 processes: 113 sleeping, 1 running, 6 zombie, 0 stopped
CPU0 states: 14.0% user 2.0% system 0.0% nice 0.0% iowait 82.0%
idle
CPU1 states: 1.0% user 1.0% system 0.0% nice 0.0% iowait 96.0%
idle
Mem: 1030344k av, 971092k used, 59252k free, 0k shrd, 182032k
buff
649668k actv, 4996k in_d, 18540k in_c
Swap: 2040212k av, 143864k used, 1896348k free 519776k
cached
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU
COMMAND
[snip]
/usr/local/src/nagios/nagios-plugins-HEAD-200408121647/contrib: sudo
perl check_mem.pl -u -w 80 -c 90
Memory OK - 26.1% (269200 kB) used
/usr/local/src/nagios/nagios-plugins-HEAD-200408121647/contrib: sudo
perl check_mem.orig.pl -u -w 80 -c 90
Memory OK - 70.2% (143852 kB) used
The patched version (check_mem.pl above) shows used memory when using
the -u option. But I'm not sure where the figure (269200 kB) is coming
from. Perhaps I'm not reading the output of top correctly, and this is
correct? If so, please explain.
The original version (check_mem.orig.pl), when used with the -u option,
does indeed appear to show the swap space in use.
Instead of fixing it the way that you have, why not add a third option
to check the swap?
Also, since you are taking the time to get in there and fix the code,
why not add Performance Data output as well?
Garry W. Cook, CCNA
Network Infrastructure Manager
MACTEC, Inc. - http://www.mactec.com/
303.308.6228 (Office) - 720.220.1862 (Mobile)
More information about the Devel
mailing list