in reply to vmstat threshold script

On Linux I'd rather use /proc/meminfo: it's fast and you obtain the total amount of mem/swap, too. A simplistic solution could be this:
use strict; use warnings; my $meminfo='/proc/meminfo'; my %Limits=('mem'=>0.99, 'swap'=>0.60); my %Info=(); open(MEM,"<$meminfo") or die "Can't read $meminfo: $!"; while(defined($_=<MEM>)){ if(/^(Mem|Swap):\s*/){ my $which=lc($1); my ($total,$used)=split(/\s/,$'); my $pct=$total?($used/$total):0; my $test=($pct ge $Limits{$which}?"WARN":"OK"); $Info{$which}=[$used, $total, $pct, $test]; } } close(MEM); #Quick and dirty way to print the %Info hash in a readable form use Data::Dumper; print Dumper(\%Info);

This way, the parsing code is pretty easy; after that, you can use %Info for anything you need.

Replies are listed 'Best First'.
Re: Re: vmstat threshold script
by Anonymous Monk on Jun 23, 2003 at 18:10 UTC
    Thanks! Although this is for a large Sun server running Solaris 8