diff -r 6f49d13a20aa -r b5d9151a01f4 check_mem.pl --- a/check_mem.pl Thu Jun 30 14:44:08 2011 +0200 +++ b/check_mem.pl Thu Jun 30 15:58:49 2011 +0200 @@ -41,7 +41,7 @@ my $ME = basename $0; my $NAME = "MEM"; -my $VERSION = "0.1"; +my $VERSION = "0.2"; my %opt = ( warning => 70, @@ -81,23 +81,19 @@ } sub get_meminfo() { - my ( $total, $free, $used, $percent ); - my $file = '/proc/meminfo'; - - open( FH, $file ) - or say "$NAME CRITICAL: $file - $!." and exit $ERRORS{CRITICAL}; + my ( $total, $used, $free, $percent ); + my @cmd = ( '/usr/bin/free', '-m' ); - while () { - /^MemTotal:\s+(?[\d.]+)/ - and $total = ( sprintf( "%.0f", $+{total} / 1024 ) ) + foreach (`/usr/bin/free -m`) { + /^Mem:\s+(?[\d.]+)/ + and $total = $+{total} and next; - /^MemFree:\s+(?[\d.]+)/ - and $free = ( sprintf( "%.0f", $+{free} / 1024 ) ) + /^.+buffers\/cache:\s+(?[\d.]+)/ + and $used = $+{used} and last; } - close(FH); - $used = ( $total - $free ); + $free = ( $total - $used ); $percent = ( sprintf( "%.0f", ( $used / $total ) * 100 ) ); return ( $percent, $total, $used, $free ); @@ -164,7 +160,7 @@ =head1 VERSION -This man page is current for version 0.1 of B. +This man page is current for version 0.2 of B. =head1 AUTHOR