]> git.etc.gen.nz Git - spong.git/commitdiff
Added patch Ilya Martynov for FreeBSD support
authorStephen L Johnson <sjohnson@monsters.org>
Wed, 24 Jul 2002 18:30:17 +0000 (18:30 +0000)
committerStephen L Johnson <sjohnson@monsters.org>
Wed, 24 Jul 2002 18:30:17 +0000 (18:30 +0000)
src/lib/Spong/Client/plugins/check_memory

index 00e28d014661476e2504c36a20bff6c2ba8778e0..cb22193e2e66a5c110c1e8c64ac10dc1020d72f0 100755 (executable)
@@ -1,4 +1,4 @@
-# $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;
@@ -63,7 +63,7 @@ sub check_memory_free {
 
 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;
@@ -81,9 +81,24 @@ sub check_memory_top {
                &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);
@@ -98,7 +113,7 @@ sub check_memory_top {
             $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);