OSSP CVS Repository

ossp - Difference in ossp-pkg/snmpdx/snmpdx.d/sysVM.pm versions 1.3 and 1.4
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

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

--- sysVM.pm     2003/09/04 08:33:16     1.3
+++ sysVM.pm     2003/09/04 09:21:04     1.4
@@ -37,13 +37,88 @@
     my ($self, $obj) = @_;
 
     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
+        # sysVMRamMax   "/sbin/sysctl -n hw.physmem", convert bytes to MB
+        # sysVMRamUsed  sysVMRamMax - sysVMRamFree
+        # sysVMRamFree  "/usr/bin/vmstat", avm, convert KB to MB
+        #
+        if ($obj->{-name} =~ m/\.sysVMRam(Max|Used|Free)$/) {
+            my $sysVMRamMax  = undef;
+            my $sysVMRamUsed = undef;
+            my $sysVMRamFree = undef;
+
+            #   sysVMRamMax
+            my $out = $self->{-ctx}->{-sys}->run("/sbin/sysctl -n hw.physmem", "forever");
+            my $raw = $out->{-stdout};
+            $sysVMRamMax = int($1 / 1024 / 1024) if ($raw =~ m/^(\d+)$/);
+
+            #   sysVMRamFree
+            my $out = $self->{-ctx}->{-sys}->run("/usr/bin/vmstat", "1m");
+            my $raw = $out->{-stdout};
+            my $i_vmstat = {};
+            if ($raw =~ m/^[^\n]*\n *([^\n]*\bavm\b[^\n]*)\n *([^\n]*)\n$/s) {
+                $i_vmstat = &n2i(split / +/, $1) if (not defined $i_vmstat->{sr});
+            }
+            if (defined $i_vmstat->{avm}) {
+                my @data = split(/ +/, $2);
+                $sysVMRamFree = int(@data[$i_vmstat->{avm}] / 1024);
+            }
+
+            #   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  "/usr/sbin/swapinfo -k", 1K-blocks, last line, convert KB to MB
+        # sysVMSwapUsed "/usr/sbin/swapinfo -k", Used, last line, convert KB to MB
         # sysVMSwapFree sysVMSwapMax - sysVMSwapUsed
-        # sysVMActivity vmstat: pi+po
+        #
+        if ($obj->{-name} =~ m/\.sysVMSwap(Max|Used|Free)$/) {
+            my $sysVMSwapMax  = undef;
+            my $sysVMSwapUsed = undef;
+            my $sysVMSwapFree = undef;
+
+            #   sysVMSwapMax, sysVMSwapUsed
+            my $out = $self->{-ctx}->{-sys}->run("/usr/sbin/swapinfo -k", "1m");
+            my $raw = $out->{-stdout};
+            my $i_swapl = {};
+            if ($raw =~ m/^\s*([^\n]*\b1K-blocks[^\n]*\bUsed[^\n]*).*\n([^\n]+)$/s) {
+                $i_swapl = &n2i(split / +/, $1) if (scalar keys %$i_swapl == 0);
+            }
+            @data = split(/ +/, $2);
+            $sysVMSwapMax  = int(@data[$i_swapl->{_1K_blocks}] / 1024) if (defined $i_swapl->{_1K_blocks});
+            $sysVMSwapUsed = int(@data[$i_swapl->{Used}]       / 1024) if (defined $i_swapl->{Used});
+
+            #   sysVMSwapFree
+            if (defined $sysVMSwapMax and defined $sysVMSwapUsed) {
+                $sysVMSwapFree = $sysVMSwapMax - $sysVMSwapUsed;
+            }
+
+            $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 pi and po 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]*(\bp[io]\b[^\n]*){2})\n *([^\n]*)\n$/s) {
+                $i_vmstat = &n2i(split / +/, $1) if (not defined $i_vmstat->{sr});
+            }
+            if (defined $i_vmstat->{pi} and defined $i_vmstat->{po}) {
+                my @data = split(/ +/, $3);
+                $value = @data[$i_vmstat->{pi}] + @data[$i_vmstat->{po}];
+            }
+            $obj->{-value} = $value;
+        }
     }
     elsif ($self->{-ctx}->{-platform}->id() =~ m/Linux/i) {
         # sysVMRamMax   "/bin/cat /proc/meminfo", MemTotal, convert KB to MB
@@ -64,12 +139,10 @@
             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};
             }
 
@@ -255,6 +328,8 @@
     my $rc = {};
     my $i = 0;
     foreach my $f (@name) {
+        $f =~ s/[^\w]/_/;
+        $f =~ s/^([^a-zA-Z_])/_$1/;
         $rc->{$f} = $i++;
     };
     return $rc;

CVSTrac 2.0.1