1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#!/usr/bin/perl
#
# A perl script that analyses the log file to extract one statistic.
#
# Written by Andrew M. Bishop
#
# This file Copyright 1997 Andrew M. Bishop
# It may be distributed under the GNU Public License, version 2, or
# any higher version. See section COPYING of the GNU Public license
# for conditions under which this file may be redistributed.
#
die "Usage: procmeter-xlog statistic < logfile\n" if($#ARGV==-1);
$statistic=$ARGV[0];
$position=-1;
$_=<STDIN>;
print $_;
print "# Data for '$statistic'\n";
while(<STDIN>)
{
chop;
if(/^\#/)
{
($hash,$time,@stats)=split(/ +/);
$old_position=$position;
$position=-1;
foreach $n (0 .. $#stats)
{
if($stats[$n] eq $statistic)
{$position=$n;}
}
if($position!=-1 && $old_position==-1)
{print "\n";}
}
elsif($position!=-1)
{
($time,@stats)=split(/ +/);
print "$time $stats[$position]\n";
}
}
|