-# $Id: check_memory,v 1.3 2002/01/07 21:25:24 supermathie Exp $
+# $Id: check_memory,v 1.4 2002/07/24 18:30:17 sljohnson Exp $
# vim:syn=perl:expandtab:ts=3:sw=3:ai:si
# Register this routine with the plugin registry
$CHECKFUNCS{'memory'} = \&check_memory;
sub check_memory_top {
$kmb='\s+(\d+[KM])';
- $message = "";
+ @parse_error = ("yellow", "Can't parse memory line", $message);
open CMD, "$MEMCHECK |";
while (<CMD>) {
/PID/ && last;
&to_KB($swaptotal, $swapused, $swapfree, $cached);
} else {
close CMD;
- return ("yellow", "Can't parse memory line", $message);
+ return @parse_error;
};
$hardmemused = $memused-$buffers-$cached;
+ } elsif (/^Mem:$kmb Active,$kmb Inact,$kmb Wired,$kmb Cache,$kmb Buf,$kmb Free/) {
+ # the top package supporting FreeBSD has this format
+ ($memactive,$meminact,$memwired,$memcache,$buffers,$memfree) = ($1,$2,$3,$4,$5,$6);
+ &to_KB($memactive,$meminact,$memwired,$cached,$buffers,$memfree);
+ $memtotal = $memactive+$meminact+$memwired+$memcache;
+ $hardmemused = $memtotal-$memfree;
+ $_ = <CMD>;
+ $message .= $_;
+ if (/^Swap:$kmb Total,$kmb Used,$kmb Free/) {
+ ($swaptotal, $swapused, $swapfree) = ($1,$2,$3);
+ &to_KB($swaptotal, $swapused, $swapfree);
+ } else {
+ close CMD;
+ return @parse_error;
+ }
} elsif (/^Memory:$kmb real,$kmb free,$kmb swap,$kmb free swap/) {
# the top package supporting various unices has this format
($memtotal,$memfree,$swapused,$swapfree) = ($1,$2,$3,$4);
$swaptotal = $swapused+$swapfree;
} else {
close CMD;
- return ("yellow", "Can't parse memory line", $message);
+ return @parse_error;
}
$physpctused = floor($hardmemused/$memtotal*100);
$virtpctused = floor(($hardmemused+$swapused)/($memtotal+$swaptotal)*100);