OSSP CVS Repository

ossp - Check-in [3550]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3550
Date: 2003-Sep-04 10:33:16 (local)
2003-Sep-04 08:33:16 (UTC)
User:thl
Branch:
Comment: sysVM for Linux
Tickets:
Inspections:
Files:
ossp-pkg/snmpdx/snmpdx.d/sysVM.pm      1.2 -> 1.3     93 inserted, 5 deleted

ossp-pkg/snmpdx/snmpdx.d/sysVM.pm 1.2 -> 1.3

--- sysVM.pm     2003/09/03 15:41:04     1.2
+++ sysVM.pm     2003/09/04 08:33:16     1.3
@@ -22,7 +22,7 @@
 ##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 ##  SUCH DAMAGE.
 ##
-##  sysVM: System Vritual Memory
+##  sysVM: System Virtual Memory
 ##
 
 package My::Probe::sysVM;
@@ -46,12 +46,100 @@
         # sysVMActivity vmstat: pi+po
     }
     elsif ($self->{-ctx}->{-platform}->id() =~ m/Linux/i) {
-        # sysVMRamMax   /proc/meminfo:MemTotal
-        # sysVMRamUsed  /proc/meminfo:MemTotal-Buffers-Cached-MemFree
+        # sysVMRamMax   "/bin/cat /proc/meminfo", MemTotal, convert KB to MB
+        # sysVMRamUsed  "/bin/cat /proc/meminfo", MemTotal-Buffers-Cached-MemFree, convert KB to MB
         # sysVMRamFree  sysVMRamMax - sysVMRamUsed
-        # sysVMSwapMax  /proc/meminfo:SwapTotal
+        #
+        # FIXME sysVMRamMax does not include the kernel and some of its structures so
+        # FIXME             it is not pyhsical RAM, see dmesg | egrep '^Memory:'
+        # FIXME /bin/cat is used here but could be replaced by native perl code to improve performance
+        #
+        if ($obj->{-name} =~ m/\.sysVMRam(Max|Used|Free)$/) {
+            my $sysVMRamMax  = undef;
+            my $sysVMRamUsed = undef;
+            my $sysVMRamFree = undef;
+
+            #   sysVMRamMax, sysVMRamUsed
+            my $out = $self->{-ctx}->{-sys}->run("/bin/cat /proc/meminfo", "1m");
+            my $raw = $out->{-stdout};
+            my $i_meminfo = {};
+            $i_meminfo->{MemTotal} = int($1 / 1024) if ($raw =~ m/\nMemTotal:[^\n]*\b(\d+)\b[^\n]*kB\n/s);
+                $self->{-ctx}->{-log}->printf(1, "DEBUG: 1=$1\n");
+            $i_meminfo->{Buffers}  = int($1 / 1024) if ($raw =~ m/\nBuffers:[^\n]*\b(\d+)\b[^\n]*kB\n/s);
+            $i_meminfo->{Cached}   = int($1 / 1024) if ($raw =~ m/\nCached:[^\n]*\b(\d+)\b[^\n]*kB\n/s);
+            $i_meminfo->{MemFree}  = int($1 / 1024) if ($raw =~ m/\nMemFree:[^\n]*\b(\d+)\b[^\n]*kB\n/s);
+            if (defined $i_meminfo->{MemTotal}) {
+                $self->{-ctx}->{-log}->printf(1, "DEBUG: MemTotal=%s\n", $i_meminfo->{MemTotal});
+                $sysVMRamMax = $i_meminfo->{MemTotal};
+            }
+
+            if (    defined $i_meminfo->{MemTotal}
+                and defined $i_meminfo->{Buffers}
+                and defined $i_meminfo->{Cached}
+                and defined $i_meminfo->{MemFree}
+                   ) {
+                $sysVMRamUsed  =   $i_meminfo->{MemTotal} 
+                                 - $i_meminfo->{Buffers} 
+                                 - $i_meminfo->{Cached} 
+                                 - $i_meminfo->{MemFree};
+            }
+
+            #   sysVMRamFree
+            if (defined $sysVMRamMax and defined $sysVMRamUsed) {
+                $sysVMRamFree = $sysVMRamMax - $sysVMRamUsed;
+            }
+
+            $obj->{-value} = $sysVMRamMax  if ($obj->{-name} =~ m/\.sysVMRamMax$/);
+            $obj->{-value} = $sysVMRamUsed if ($obj->{-name} =~ m/\.sysVMRamUsed$/);
+            $obj->{-value} = $sysVMRamFree if ($obj->{-name} =~ m/\.sysVMRamFree$/);
+        }
+
+        # sysVMSwapMax  "/bin/cat /proc/meminfo", SwapTotal, convert KB to MB
         # sysVMSwapUsed sysVMSwapMax - sysVMSwapFree
-        # sysVMSwapFree /proc/meminfo:SwapFree
+        # sysVMSwapFree "/bin/cat /proc/meminfo", SwapFree, convert KB to MB
+        #
+        if ($obj->{-name} =~ m/\.sysVMSwap(Max|Used|Free)$/) {
+            my $sysVMSwapMax  = undef;
+            my $sysVMSwapUsed = undef;
+            my $sysVMSwapFree = undef;
+
+            #   sysVMSwapMax, sysVMSwapFree
+            my $out = $self->{-ctx}->{-sys}->run("/bin/cat /proc/meminfo", "1m"); #FIXME this could be done in perl natively to improve performance
+            my $raw = $out->{-stdout};
+            my $i_swapl = {};
+            if ($raw =~ m/\nSwapTotal:[^\n]*\b(\d+)\b[^\n]*kB\n/s) {
+                $sysVMSwapMax  = int($1 / 1024);
+            }
+            if ($raw =~ m/\nSwapFree:[^\n]*\b(\d+)\b[^\n]*kB\n/s) {
+                $sysVMSwapFree = int($1 / 1024);
+            }
+
+            #   sysVMSwapUsed
+            if (defined $sysVMSwapMax and defined $sysVMSwapFree) {
+                $sysVMSwapUsed = $sysVMSwapMax - $sysVMSwapFree;
+            }
+
+            $obj->{-value} = $sysVMSwapMax  if ($obj->{-name} =~ m/\.sysVMSwapMax$/);
+            $obj->{-value} = $sysVMSwapUsed if ($obj->{-name} =~ m/\.sysVMSwapUsed$/);
+            $obj->{-value} = $sysVMSwapFree if ($obj->{-name} =~ m/\.sysVMSwapFree$/);
+        }
+
+        # sysVMActivity "/usr/bin/vmstat", add si and so column
+        #
+        if ($obj->{-name} =~ m/\.sysVMActivity$/) {
+            my $value = undef;
+            my $out = $self->{-ctx}->{-sys}->run("/usr/bin/vmstat", "1m");
+            my $raw = $out->{-stdout};
+            my $i_vmstat = {};
+            if ($raw =~ m/^[^\n]*\n *([^\n]*(\bs[io]\b[^\n]*){2})\n *([^\n]*)\n$/s) {
+                $i_vmstat = &n2i(split / +/, $1) if (not defined $i_vmstat->{sr});
+            }
+            if (defined $i_vmstat->{si} and defined $i_vmstat->{so}) {
+                my @data = split(/ +/, $3);
+                $value = @data[$i_vmstat->{si}] + @data[$i_vmstat->{so}];
+            }
+            $obj->{-value} = $value;
+        }
     }
     elsif ($self->{-ctx}->{-platform}->id() =~ m/SunOS/i) {
         # sysVMRamMax   "/usr/platform/$arch/sbin/prtdiag", Memory size

CVSTrac 2.0.1