[Nagiosplug-devel] patch: contrib/check_mem.pl using incorrect command

Nick Burch nick at torchbox.com
Tue Aug 17 05:40:02 CEST 2004


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





More information about the Devel mailing list