[svn:p5ee] r6606 - p5ee/trunk/App-Context/lib/App

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Sat Jul  1 20:43:45 2006
New Revision: 6606

Modified:
   p5ee/trunk/App-Context/lib/App/Context.pm

Log:
add get_sys_info() [Linux only]

Modified: p5ee/trunk/App-Context/lib/App/Context.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context.pm	(original)
+++ p5ee/trunk/App-Context/lib/App/Context.pm	Sat Jul  1 20:43:45 2006
@@ -838,7 +838,8 @@
 sub get_user_option {
     &App::sub_entry if ($App::trace);
     my ($self, $var) = @_;
-    my $value = $self->so_get($var) || $self->{options}{$var};
+    my $value = $self->so_get($var);
+    $value = $self->{options}{$var} if (!defined $value);
     &App::sub_exit($value) if ($App::trace);
     return($value);
 }
@@ -2519,5 +2520,64 @@
     return($response);
 }
 
+# /proc/meminfo
+#         total:    used:    free:  shared: buffers:  cached:
+# Mem:  525942784 468914176 57028608        0 69124096 51593216
+# Swap: 1069268992 56954880 1012314112
+# MemTotal:       513616 kB
+# MemFree:         55692 kB
+# MemShared:           0 kB
+# Buffers:         67504 kB
+# Cached:          42328 kB
+# SwapCached:       8056 kB
+# Active:         171720 kB
+# ActiveAnon:      88224 kB
+# ActiveCache:     83496 kB
+# Inact_dirty:     22032 kB
+# Inact_laundry:    3120 kB
+# Inact_clean:      5572 kB
+# Inact_target:    40488 kB
+# HighTotal:           0 kB
+# HighFree:            0 kB
+# LowTotal:       513616 kB
+# LowFree:         55692 kB
+# SwapTotal:     1044208 kB
+# SwapFree:       988588 kB
+
+# /proc/loadavg
+# 0.02 0.12 0.15 1/138 30412
+
+# This only works on Linux (as far as I know)
+sub get_sys_info {
+    my ($self) = @_;
+    my $info = {};
+    # print "FILE: /proc/meminfo\n";
+    if (open(App::Context::FILE, "/proc/meminfo")) {
+        while (<App::Context::FILE>) {
+            if (/^([A-Za-z]+):\s*([0-9]+)/) {
+                $info->{lc($1)} = $2;
+                # print ">>> $1 = $2\n";
+            }
+        }
+        close(App::Context::FILE);
+    }
+    # print "FILE: /proc/loadavg\n";
+    if (open(App::Context::FILE, "/proc/loadavg")) {
+        while (<App::Context::FILE>) {
+            if (/^([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9]+)\/([0-9]+)\s+([0-9]+)/) {
+                $info->{load}     = $1;
+                $info->{load5}    = $2;
+                $info->{load15}   = $3;
+                $info->{runprocs} = $4;
+                $info->{nprocs}   = $5;
+                $info->{unknown}  = $6;
+                # print ">>> [$1][$2][$3][$4][$5][$6]\n";
+            }
+        }
+        close(App::Context::FILE);
+    }
+    return($info);
+}
+
 1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.