#585 check_mem.pl incorrectly reads parameters from vmstat

open
nobody
5
2013-01-11
2013-01-11
Lassi Lehtinen
No

Seems like the check_mem.pl script incorrectly reads the parameters from vmstat on Linux-host:

[root@machine ~]# /usr/lib64/nagios/plugins/contrib/check_mem.pl -f -w 40 -c 20
Memory CRITICAL - 16.9% (74588 kB) free
[root@machine ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 366640 74604 9415164 0 0 5856 3863 1 5 0 2 98 0 0

Problems seems to be here:

<clip>
# This the unix command string that brings Perl the data
$command_line = `vmstat | tail -1 | awk '{print \$4,\$5}'`;

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;
</clip>

Executing $command_line first prints amount of free-memory and then amount of buffered-memory, but these
are put to variables so that $used_memory has the amount of free memory, and $free_memory the amount of
buffered memory. So the script actually reports inveresly free/used memory.

Discussion