swrd / check-mysql-all

Automatically exported from code.google.com/p/check-mysql-all
0 stars 0 forks source link

Wrong free memory calculation for check-linux-memory #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In order to calculate Linux free memory, the amount of memory in "cached"
and "buffers" need to be taken into account.

the following:

[root@slave01 check-mysql-all]# free -m
             total       used       free     shared    buffers     cached
Mem:         16046      15212        834          0       4020       7402
-/+ buffers/cache:       3788      12258
Swap:         1983          0       1983

Means 12258MB free (834 + 4020 + 7402) out of 16046MB.  The percentage free
should be 12258/16046 * 100 = 76.4% 
and used memory should be 3788/16046 * 100 ~ 23.6

but:

./check_linux_mem -w 90 -c 97
WARNING: 95% memory used

which is 15212/16046 = 94.8

Original issue reported on code.google.com by trudea...@gmail.com on 15 Feb 2010 at 4:45

GoogleCodeExporter commented 8 years ago
proposed patch:

--- check-mysql-all/check_linux_mem     2009-11-26 02:34:43.000000000 -0500
+++ ./check_linux_mem_new       2010-02-15 11:53:03.000000000 -0500
@@ -56,9 +56,13 @@

 my $total_memory = `/bin/cat /proc/meminfo |/bin/grep -i MemTotal | /bin/awk {'print
\$2'}`;
 my $free_memory  = `/bin/cat /proc/meminfo |/bin/grep -i MemFree  | /bin/awk {'print
\$2'}`;
+my $buffers  = `/bin/cat /proc/meminfo |/bin/grep -i Buffers  | /bin/awk 
{'print \$2'}`;
+my $cached  = `/bin/cat /proc/meminfo |/bin/egrep -i '^Cached'  | /bin/awk 
{'print
\$2'}`;
 chomp($total_memory);
 chomp($free_memory);
-my $pct_used     = int(100 - ((($free_memory / $total_memory) * 100) - 0.5));
+chomp($buffers);
+chomp($cached);
+my $pct_used     = int(100 - (((($free_memory + $buffers + $cached) / 
$total_memory)
* 100) - 0.5));

 if ($pct_used >= $opts{critical}) {
     print "CRITICAL: $pct_used% memory used\n";

Original comment by trudea...@gmail.com on 15 Feb 2010 at 4:54

GoogleCodeExporter commented 8 years ago

Original comment by ryan.a.l...@gmail.com on 18 Nov 2010 at 11:30

GoogleCodeExporter commented 8 years ago
Fixed in 0.1.1

Original comment by ryan.a.l...@gmail.com on 11 Feb 2011 at 8:53