[system] / trunk / xmlrpc / RPC / RPC-XML-0.25 / ex / linux.proc.meminfo.code Repository:
ViewVC logotype

View of /trunk/xmlrpc/RPC/RPC-XML-0.25/ex/linux.proc.meminfo.code

Parent Directory Parent Directory | Revision Log Revision Log


Revision 279 - (download) (annotate)
Fri May 17 21:44:04 2002 UTC (17 years, 4 months ago) by gage
File size: 1394 byte(s)
Experimental xmlrpc WeBWorK webservices

    1 ###############################################################################
    2 #
    3 #   Sub Name:       linux_proc_meminfo
    4 #
    5 #   Description:    Read the /proc/meminfo on a Linux server and return a
    6 #                   STRUCT with the information.
    7 #
    8 #   Arguments:      NAME      IN/OUT  TYPE      DESCRIPTION
    9 #                   $srv      in      ref       Server object reference
   10 #
   11 #   Globals:        None.
   12 #
   13 #   Environment:    None.
   14 #
   15 #   Returns:        hashref
   16 #
   17 ###############################################################################
   18 sub linux_proc_meminfo
   19 {
   20     use strict;
   21 
   22     my $srv = shift;
   23 
   24     my (%meminfo, $line, $key, @parts);
   25     local *F;
   26 
   27     open(F, '/proc/meminfo') or
   28         return RPC::XML::fault->new(501, "Cannot open /proc/meminfo: $!");
   29 
   30     while (defined($line = <F>))
   31     {
   32         next if ($line =~ /^\s+/);
   33         chomp $line;
   34 
   35         @parts = split(/\s+/, $line);
   36         $key = shift(@parts);
   37         if ($key eq 'Mem:')
   38         {
   39             @meminfo{qw(mem_total mem_used mem_free mem_shared mem_buffers
   40                         mem_cached)} = @parts;
   41         }
   42         elsif ($key eq 'Swap:')
   43         {
   44             @meminfo{qw(swap_total swap_used swap_free)} = @parts;
   45         }
   46         else
   47         {
   48             chop $key; # Lose the trailing ':'
   49             $meminfo{$key} = join(' ', @parts);
   50         }
   51     }
   52     close(F);
   53 
   54     \%meminfo;
   55 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9