parse out memory usage data

chris (2004-05-03 15:36:59)
1309 views
0 replies

We were fiddling with snmp and mrtg in the office the other day. A colleague of mine needed a quick script to give him data on total memory and total free, then total swap and total free. It was a 5 minute job and here's the simple solution. (linux only).

#!/usr/bin/perl
use strict;

my $result=`cat /proc/meminfo`;
my @results=split("n",$result);

# iterate and copy each one
foreach (@results){
        chomp;
        $_ =~ /^MemTotal:s+(d+)/i && print "$1n";
        $_ =~ /^MemFree:s+(d+)/i && print "$1n";
        $_ =~ /^SwapTotal:s+(d+)/i && print "$1n";
        $_ =~ /^SwapFree:s+(d+)/i && print "$1n";
}

christo
Digg it! Submit to Slashdot Add to Blinklist Del.icio.us Add to Newsvine Add to Technorati Add it to Google Bookmarks
comment