OSSP CVS Repository

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

Check-in Number: 3549
Date: 2003-Sep-03 17:41:04 (local)
2003-Sep-03 15:41:04 (UTC)
User:thl
Branch:
Comment: sysVM for SunOS
Tickets:
Inspections:
Files:
ossp-pkg/snmpdx/snmpdx.d/sysVM.pm      1.1 -> 1.2     133 inserted, 13 deleted

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

--- sysVM.pm     2003/09/03 09:22:03     1.1
+++ sysVM.pm     2003/09/03 15:41:04     1.2
@@ -36,21 +36,141 @@
 sub probe ($$) {
     my ($self, $obj) = @_;
 
-    #               FreeBSD                Linux                                          Solaris
-    #Mem Total      sysctl -n hw.physmem   /proc/meminfo:MemTotal                         /usr/platform/`uname -i`/sbin/prtdiag:Memory size
-    #Mem Used       vmstat: avm            /proc/meminfo:MemTotal-Buffers-Cached-MemFree  "total" - "free"
-    #Mem Free       "total"-"used"         "total"-"used"                                 sar -r  1 1: freemem * `pagesize`
-    #Mem Status     N.A.                   N.A.                                           /usr/platform/`uname -i`/sbin/prtdiag:Status col. 
-    #
-    #Swap Total     swapinfo -k | tail -1  /proc/meminfo:SwapTotal                        swap -l: blocks * 512 (accumulate)
-    #Swap Used      swapinfo -k | tail -1  "total" - "free"                               "total"-"free"
-    #Swap Free      "total"-"used"         /proc/meminfo:SwapFree                         swap -l: free * 512 (accumulate)
-    #
-    #Mem/Swap       vmstat: pi+po          vmstat: si+so                                  vmstat: sr
-    #Page Activity
-   
+    if ($self->{-ctx}->{-platform}->id() =~ m/FreeBSD/i) {
+        # sysVMRamMax   sysctl -n hw.physmem
+        # sysVMRamUsed  vmstat: avm
+        # sysVMRamFree  sysVMRamMax - sysVMRamUsed
+        # sysVMSwapMax  swapinfo -k | tail -1
+        # sysVMSwapUsed swapinfo -k | tail -1
+        # sysVMSwapFree sysVMSwapMax - sysVMSwapUsed
+        # sysVMActivity vmstat: pi+po
+    }
+    elsif ($self->{-ctx}->{-platform}->id() =~ m/Linux/i) {
+        # sysVMRamMax   /proc/meminfo:MemTotal
+        # sysVMRamUsed  /proc/meminfo:MemTotal-Buffers-Cached-MemFree
+        # sysVMRamFree  sysVMRamMax - sysVMRamUsed
+        # sysVMSwapMax  /proc/meminfo:SwapTotal
+        # sysVMSwapUsed sysVMSwapMax - sysVMSwapFree
+        # sysVMSwapFree /proc/meminfo:SwapFree
+    }
+    elsif ($self->{-ctx}->{-platform}->id() =~ m/SunOS/i) {
+        # sysVMRamMax   "/usr/platform/$arch/sbin/prtdiag", Memory size
+        # sysVMRamUsed  sysVMRamMax - sysVMRamFree
+        # sysVMRamFree  "/bin/pagesize" * "/bin/sar -r 1 1", freemem, convert bytes to MB
+        #
+        if ($obj->{-name} =~ m/\.sysVMRam(Max|Used|Free)$/) {
+            my $sysVMRamMax  = undef;
+            my $sysVMRamUsed = undef;
+            my $sysVMRamFree = undef;
+
+            #   initialize arch; get or assume pagesize(1)
+            my $arch = $self->{-ctx}->{-platform}->arch();
+            my $out = $self->{-ctx}->{-sys}->run("/bin/pagesize", "forever");
+            my $pagesize = $out->{-stdout} || 4096;
+
+            #   sysVMRamMax
+            my $out = $self->{-ctx}->{-sys}->run("/usr/platform/$arch/sbin/prtdiag -v", "1m");
+            my $raw = $out->{-stdout};
+            if ($raw =~ m/\nMemory size: (\d+) Megabytes/s) {
+                $sysVMRamMax = $1;
+            }
+
+            #   sysVMRamFree
+            my $out = $self->{-ctx}->{-sys}->run("/bin/sar -r 1 1", "1m");
+            my $raw = $out->{-stdout};
+            my $i_sarr = {};
+            if ($raw =~ m/^.*\n([^\n]*\bfreemem[^\n]*)\n(.*)$/s) {
+                $i_sarr = &n2i(split / +/, $1) if (scalar keys %$i_sarr == 0);
+            }
+            @data = split(/ +/, $2);
+            if (defined $i_sarr->{freemem}) {
+                $sysVMRamFree  = 0 if (not defined $sysVMRamFree);
+                $sysVMRamFree  += @data[$i_sarr->{freemem}];
+            }
+            $sysVMRamFree = int($sysVMRamFree * $pagesize / 1024 / 1024) if (defined $sysVMRamFree);
+
+            #   sysVMRamUsed
+            if (defined $sysVMRamMax and defined $sysVMRamFree) {
+                $sysVMRamUsed = $sysVMRamMax - $sysVMRamFree;
+            }
+
+            $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  "swap -l", egrep ^/ and accumulate, convert 512byte blocks to MB
+        # sysVMSwapUsed sysVMSwapMax - sysVMSwapFree
+        # sysVMSwapFree "swap -l", egrep ^/ and accumulate, convert 512byte blocks 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("/usr/sbin/swap -l", "1m");
+            my $raw = $out->{-stdout};
+            my $i_swapl = {};
+            if ($raw =~ m/^\s*([^\n]*\bblocks[^\n]*\bfree[^\n]*)\n(.*)$/s) {
+                $i_swapl = &n2i(split / +/, $1) if (scalar keys %$i_swapl == 0);
+            }
+            foreach my $r (split /\n/, $2) {
+                if ($r =~ m/^\//) {
+                    @data = split(/ +/, $r);
+                    if (defined $i_swapl->{blocks}) {
+                        $sysVMSwapMax  = 0 if (not defined $sysVMSwapMax);
+                        $sysVMSwapMax  += @data[$i_swapl->{blocks}];
+                    }
+                    if (defined $i_swapl->{free}) {
+                        $sysVMSwapFree = 0 if (not defined $sysVMSwapFree);
+                        $sysVMSwapFree += @data[$i_swapl->{free}];
+                    }
+                }
+            }
+            $sysVMSwapMax  = int($sysVMSwapMax  * 512 / 1024 / 1024) if (defined $sysVMSwapMax);
+            $sysVMSwapFree = int($sysVMSwapFree * 512 / 1024 / 1024) if (defined $sysVMSwapFree);
+
+            #   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 "/bin/vmstat", sr column
+        #
+        if ($obj->{-name} =~ m/\.sysVMActivity$/) {
+            my $value = undef;
+            my $out = $self->{-ctx}->{-sys}->run("/bin/vmstat", "1m");
+            my $raw = $out->{-stdout};
+            my $i_vmstat = {};
+            if ($raw =~ m/^[^\n]*\n *([^\n]*\bsr\b[^\n]*)\n *([^\n]*)\n$/s) {
+                $i_vmstat = &n2i(split / +/, $1) if (not defined $i_vmstat->{sr});
+            }
+            if (defined $i_vmstat->{sr}) {
+                my @data = split(/ +/, $2);
+                $value = @data[$i_vmstat->{sr}];
+            }
+            $obj->{-value} = $value;
+        }
+    }
     return;
 }
 
+# name to index
+sub n2i ($) {
+    my (@name) = @_;
+    my $rc = {};
+    my $i = 0;
+    foreach my $f (@name) {
+        $rc->{$f} = $i++;
+    };
+    return $rc;
+}
+
 1;
 

CVSTrac 2.0.1