OSSP CVS Repository

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

Check-in Number: 3553
Date: 2003-Sep-04 12:07:47 (local)
2003-Sep-04 10:07:47 (UTC)
User:thl
Branch:
Comment: variable name, namespace and coding style cleanup
Tickets:
Inspections:
Files:
ossp-pkg/snmpdx/snmpdx.d/sysVM.pm      1.4 -> 1.5     133 inserted, 92 deleted

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

--- sysVM.pm     2003/09/04 09:21:04     1.4
+++ sysVM.pm     2003/09/04 10:07:47     1.5
@@ -46,21 +46,26 @@
             my $sysVMRamUsed = undef;
             my $sysVMRamFree = undef;
 
+            #   local workspace
+            my $out; my $raw; my $n2i; my @dat;
+
             #   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+)$/);
+            $out = $self->{-ctx}->{-sys}->run("/sbin/sysctl -n hw.physmem", "forever");
+            $raw = $out->{-stdout};
+            if ($raw =~ m/^(\d+)$/) {
+                $sysVMRamMax = int($1 / 1024 / 1024);
+            }
 
             #   sysVMRamFree
-            my $out = $self->{-ctx}->{-sys}->run("/usr/bin/vmstat", "1m");
-            my $raw = $out->{-stdout};
-            my $i_vmstat = {};
+            $out = $self->{-ctx}->{-sys}->run("/usr/bin/vmstat", "1m");
+            $raw = $out->{-stdout};
+            $n2i = {};
             if ($raw =~ m/^[^\n]*\n *([^\n]*\bavm\b[^\n]*)\n *([^\n]*)\n$/s) {
-                $i_vmstat = &n2i(split / +/, $1) if (not defined $i_vmstat->{sr});
+                $n2i = &mkn2i(split / +/, $1);
             }
-            if (defined $i_vmstat->{avm}) {
-                my @data = split(/ +/, $2);
-                $sysVMRamFree = int(@data[$i_vmstat->{avm}] / 1024);
+            if (defined $n2i->{avm}) {
+                @dat = split(/ +/, $2);
+                $sysVMRamFree = int(@dat[$n2i->{avm}] / 1024);
             }
 
             #   sysVMRamUsed
@@ -82,16 +87,23 @@
             my $sysVMSwapUsed = undef;
             my $sysVMSwapFree = undef;
 
+            #   local workspace
+            my $out; my $raw; my $n2i; my @dat;
+
             #   sysVMSwapMax, sysVMSwapUsed
-            my $out = $self->{-ctx}->{-sys}->run("/usr/sbin/swapinfo -k", "1m");
-            my $raw = $out->{-stdout};
-            my $i_swapl = {};
+            $out = $self->{-ctx}->{-sys}->run("/usr/sbin/swapinfo -k", "1m");
+            $raw = $out->{-stdout};
+            $n2i = {};
             if ($raw =~ m/^\s*([^\n]*\b1K-blocks[^\n]*\bUsed[^\n]*).*\n([^\n]+)$/s) {
-                $i_swapl = &n2i(split / +/, $1) if (scalar keys %$i_swapl == 0);
+                $n2i = &mkn2i(split / +/, $1);
+            }
+            @dat = split(/ +/, $2);
+            if (defined $n2i->{_1K_blocks}) {
+                $sysVMSwapMax  = int(@dat[$n2i->{_1K_blocks}] / 1024)
+            }
+            if (defined $n2i->{Used}) {
+                $sysVMSwapUsed = int(@dat[$n2i->{Used}] / 1024)
             }
-            @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) {
@@ -106,18 +118,22 @@
         # 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 = {};
+            my $sysVMActivity = undef;
+
+            #   local workspace
+            my $out; my $raw; my $n2i; my @dat;
+
+            $out = $self->{-ctx}->{-sys}->run("/usr/bin/vmstat", "1m");
+            $raw = $out->{-stdout};
+            $n2i = {};
             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});
+                $n2i = &mkn2i(split / +/, $1);
             }
-            if (defined $i_vmstat->{pi} and defined $i_vmstat->{po}) {
-                my @data = split(/ +/, $3);
-                $value = @data[$i_vmstat->{pi}] + @data[$i_vmstat->{po}];
+            if (defined $n2i->{pi} and defined $n2i->{po}) {
+                @dat = split(/ +/, $3);
+                $sysVMActivity = @dat[$n2i->{pi}] + @dat[$n2i->{po}];
             }
-            $obj->{-value} = $value;
+            $obj->{-value} = $sysVMActivity;
         }
     }
     elsif ($self->{-ctx}->{-platform}->id() =~ m/Linux/i) {
@@ -134,27 +150,31 @@
             my $sysVMRamUsed = undef;
             my $sysVMRamFree = undef;
 
+            #   local workspace
+            my $out; my $raw; my $n2i; my @dat; my $tmp;
+
             #   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);
-            $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}) {
-                $sysVMRamMax = $i_meminfo->{MemTotal};
+            $out = $self->{-ctx}->{-sys}->run("/bin/cat /proc/meminfo", "1m");
+            $raw = $out->{-stdout};
+            $tmp = {};
+            $tmp->{MemTotal} = $1 if ($raw =~ m/\nMemTotal:[^\n]*\b(\d+)\b[^\n]*kB\n/s);
+            $tmp->{Buffers}  = $1 if ($raw =~ m/\nBuffers:[^\n]*\b(\d+)\b[^\n]*kB\n/s);
+            $tmp->{Cached}   = $1 if ($raw =~ m/\nCached:[^\n]*\b(\d+)\b[^\n]*kB\n/s);
+            $tmp->{MemFree}  = $1 if ($raw =~ m/\nMemFree:[^\n]*\b(\d+)\b[^\n]*kB\n/s);
+            if (defined $tmp->{MemTotal}) {
+                $sysVMRamMax = int($tmp->{MemTotal} / 1024);
             }
 
-            if (    defined $i_meminfo->{MemTotal}
-                and defined $i_meminfo->{Buffers}
-                and defined $i_meminfo->{Cached}
-                and defined $i_meminfo->{MemFree}
+            if (    defined $tmp->{MemTotal}
+                and defined $tmp->{Buffers}
+                and defined $tmp->{Cached}
+                and defined $tmp->{MemFree}
                    ) {
-                $sysVMRamUsed  =   $i_meminfo->{MemTotal} 
-                                 - $i_meminfo->{Buffers} 
-                                 - $i_meminfo->{Cached} 
-                                 - $i_meminfo->{MemFree};
+                $sysVMRamUsed  = int ((  $tmp->{MemTotal} 
+                                       - $tmp->{Buffers} 
+                                       - $tmp->{Cached} 
+                                       - $tmp->{MemFree}
+                                       ) / 1024 );
             }
 
             #   sysVMRamFree
@@ -176,10 +196,12 @@
             my $sysVMSwapUsed = undef;
             my $sysVMSwapFree = undef;
 
+            #   local workspace
+            my $out; my $raw; my $n2i; my @dat;
+
             #   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 = {};
+            $out = $self->{-ctx}->{-sys}->run("/bin/cat /proc/meminfo", "1m");
+            $raw = $out->{-stdout};
             if ($raw =~ m/\nSwapTotal:[^\n]*\b(\d+)\b[^\n]*kB\n/s) {
                 $sysVMSwapMax  = int($1 / 1024);
             }
@@ -200,18 +222,22 @@
         # 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 = {};
+            my $sysVMActivity = undef;
+
+            #   local workspace
+            my $out; my $raw; my $n2i; my @dat;
+
+            $out = $self->{-ctx}->{-sys}->run("/usr/bin/vmstat", "1m");
+            $raw = $out->{-stdout};
+            $n2i = {};
             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});
+                $n2i = &mkn2i(split / +/, $1) if (not defined $n2i->{sr});
             }
-            if (defined $i_vmstat->{si} and defined $i_vmstat->{so}) {
-                my @data = split(/ +/, $3);
-                $value = @data[$i_vmstat->{si}] + @data[$i_vmstat->{so}];
+            if (defined $n2i->{si} and defined $n2i->{so}) {
+                my @dat = split(/ +/, $3);
+                $sysVMActivity = @dat[$n2i->{si}] + @dat[$n2i->{so}];
             }
-            $obj->{-value} = $value;
+            $obj->{-value} = $sysVMActivity;
         }
     }
     elsif ($self->{-ctx}->{-platform}->id() =~ m/SunOS/i) {
@@ -224,31 +250,37 @@
             my $sysVMRamUsed = undef;
             my $sysVMRamFree = undef;
 
+            #   local workspace
+            my $out; my $raw; my $n2i; my @dat; my $arch; my $pagesize; my $tmp;
+
             #   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;
+            $arch = $self->{-ctx}->{-platform}->arch();
+            $out = $self->{-ctx}->{-sys}->run("/bin/pagesize", "forever");
+            $raw = $out->{-stdout};
+            $pagesize = 4096;
+            if ($raw =~ m/^(\d+)$/) {
+                $pagesize = $1;
+            }
 
             #   sysVMRamMax
-            my $out = $self->{-ctx}->{-sys}->run("/usr/platform/$arch/sbin/prtdiag -v", "1m");
-            my $raw = $out->{-stdout};
+            $out = $self->{-ctx}->{-sys}->run("/usr/platform/$arch/sbin/prtdiag -v", "1m");
+            $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 = {};
+            $out = $self->{-ctx}->{-sys}->run("/bin/sar -r 1 1", "1m");
+            $raw = $out->{-stdout};
+            $n2i = {};
             if ($raw =~ m/^.*\n([^\n]*\bfreemem[^\n]*)\n(.*)$/s) {
-                $i_sarr = &n2i(split / +/, $1) if (scalar keys %$i_sarr == 0);
+                $n2i = &mkn2i(split / +/, $1);
             }
-            @data = split(/ +/, $2);
-            if (defined $i_sarr->{freemem}) {
-                $sysVMRamFree  = 0 if (not defined $sysVMRamFree);
-                $sysVMRamFree  += @data[$i_sarr->{freemem}];
+            @dat = split(/ +/, $2);
+            if (defined $n2i->{freemem}) {
+                $tmp = @dat[$n2i->{freemem}];
             }
-            $sysVMRamFree = int($sysVMRamFree * $pagesize / 1024 / 1024) if (defined $sysVMRamFree);
+            $sysVMRamFree = int($tmp * $pagesize / 1024 / 1024) if (defined $tmp);
 
             #   sysVMRamUsed
             if (defined $sysVMRamMax and defined $sysVMRamFree) {
@@ -269,28 +301,33 @@
             my $sysVMSwapUsed = undef;
             my $sysVMSwapFree = undef;
 
+            #   local workspace
+            my $out; my $raw; my $n2i; my @dat; my $tmpMax; my $tmpFree;
+
             #   sysVMSwapMax, sysVMSwapFree
-            my $out = $self->{-ctx}->{-sys}->run("/usr/sbin/swap -l", "1m");
-            my $raw = $out->{-stdout};
-            my $i_swapl = {};
+            $out = $self->{-ctx}->{-sys}->run("/usr/sbin/swap -l", "1m");
+            $raw = $out->{-stdout};
+            my $n2i = {};
             if ($raw =~ m/^\s*([^\n]*\bblocks[^\n]*\bfree[^\n]*)\n(.*)$/s) {
-                $i_swapl = &n2i(split / +/, $1) if (scalar keys %$i_swapl == 0);
+                $n2i = &mkn2i(split / +/, $1) if (scalar keys %$n2i == 0);
             }
+            $tmpMax = undef;
+            $tmpFree = undef;
             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}];
+                    @dat = split(/ +/, $r);
+                    if (defined $n2i->{blocks}) {
+                        $tmpMax  = 0 if (not defined $tmpMax);
+                        $tmpMax  += @dat[$n2i->{blocks}];
                     }
-                    if (defined $i_swapl->{free}) {
-                        $sysVMSwapFree = 0 if (not defined $sysVMSwapFree);
-                        $sysVMSwapFree += @data[$i_swapl->{free}];
+                    if (defined $n2i->{free}) {
+                        $tmpFree = 0 if (not defined $tmpFree);
+                        $tmpFree += @dat[$n2i->{free}];
                     }
                 }
             }
-            $sysVMSwapMax  = int($sysVMSwapMax  * 512 / 1024 / 1024) if (defined $sysVMSwapMax);
-            $sysVMSwapFree = int($sysVMSwapFree * 512 / 1024 / 1024) if (defined $sysVMSwapFree);
+            $sysVMSwapMax  = int($tmpMax  * 512 / 1024 / 1024) if (defined $tmpMax);
+            $sysVMSwapFree = int($tmpFree * 512 / 1024 / 1024) if (defined $tmpFree);
 
             #   sysVMSwapUsed
             if (defined $sysVMSwapMax and defined $sysVMSwapFree) {
@@ -305,25 +342,29 @@
         # 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 = {};
+            my $sysVMActivity = undef;
+
+            #   local workspace
+            my $out; my $raw; my $n2i; my @dat;
+
+            $out = $self->{-ctx}->{-sys}->run("/bin/vmstat", "1m");
+            $raw = $out->{-stdout};
+            $n2i = {};
             if ($raw =~ m/^[^\n]*\n *([^\n]*\bsr\b[^\n]*)\n *([^\n]*)\n$/s) {
-                $i_vmstat = &n2i(split / +/, $1) if (not defined $i_vmstat->{sr});
+                $n2i = &mkn2i(split / +/, $1) if (not defined $n2i->{sr});
             }
-            if (defined $i_vmstat->{sr}) {
-                my @data = split(/ +/, $2);
-                $value = @data[$i_vmstat->{sr}];
+            if (defined $n2i->{sr}) {
+                @dat = split(/ +/, $2);
+                $sysVMActivity = @dat[$n2i->{sr}];
             }
-            $obj->{-value} = $value;
+            $obj->{-value} = $sysVMActivity;
         }
     }
     return;
 }
 
 # name to index
-sub n2i ($) {
+sub mkn2i ($) {
     my (@name) = @_;
     my $rc = {};
     my $i = 0;

CVSTrac 2.0.1