79 "$NAME OK: $percent\% used memory - total: $total MB, used: $used MB, free: $free MB|MemUsed=$percent\%;$opt{warning};$opt{critical}"; |
79 "$NAME OK: $percent\% used memory - total: $total MB, used: $used MB, free: $free MB|MemUsed=$percent\%;$opt{warning};$opt{critical}"; |
80 exit $ERRORS{OK}; |
80 exit $ERRORS{OK}; |
81 } |
81 } |
82 |
82 |
83 sub get_meminfo() { |
83 sub get_meminfo() { |
84 my ( $total, $free, $used, $percent ); |
84 my ( $total, $used, $free, $percent ); |
85 my $file = '/proc/meminfo'; |
85 my @cmd = ( '/usr/bin/free', '-m' ); |
86 |
86 |
87 open( FH, $file ) |
87 foreach (`/usr/bin/free -m`) { |
88 or say "$NAME CRITICAL: $file - $!." and exit $ERRORS{CRITICAL}; |
88 /^Mem:\s+(?<total>[\d.]+)/ |
89 |
89 and $total = $+{total} |
90 while (<FH>) { |
|
91 /^MemTotal:\s+(?<total>[\d.]+)/ |
|
92 and $total = ( sprintf( "%.0f", $+{total} / 1024 ) ) |
|
93 and next; |
90 and next; |
94 /^MemFree:\s+(?<free>[\d.]+)/ |
91 /^.+buffers\/cache:\s+(?<used>[\d.]+)/ |
95 and $free = ( sprintf( "%.0f", $+{free} / 1024 ) ) |
92 and $used = $+{used} |
96 and last; |
93 and last; |
97 } |
94 } |
98 close(FH); |
|
99 |
95 |
100 $used = ( $total - $free ); |
96 $free = ( $total - $used ); |
101 $percent = ( sprintf( "%.0f", ( $used / $total ) * 100 ) ); |
97 $percent = ( sprintf( "%.0f", ( $used / $total ) * 100 ) ); |
102 |
98 |
103 return ( $percent, $total, $used, $free ); |
99 return ( $percent, $total, $used, $free ); |
104 } |
100 } |
105 |
101 |