[mrtg] Re: Whither the 95th percentile parser?

Pete Templin templin at urdirect.net
Wed Dec 15 05:45:46 MET 1999


On Tue, 14 Dec 1999, Norm Mackey wrote:

> Does anyone have a copy of the "95th percentile Parser for 
> MRTG logfiles by Bradley Reynolds" that is supposed to be at 
> http://null0.qual.net/src/gparse.tar.gz ?  I get "Cannot find 
> server or DNS error" trying for it from the MRTG and email to
> Brad bounces for me. 
> 
> My boss has set up a customer with one of these 95th percentile
> billing agreements and now I have to come up with a way of 
> measuring the bandwidth according to this rule.

Disclaimer: I wrote this, and I haven't spent much time checking over it.
But, so far, it works.  Pathnames will almost definitely need to be
changed to suit your environment, but I think it'll handle what you need.
There are two parts: mrtg_archive, which archives approximately 48 hours
of info, and is to be run daily; and mrtg95, which parses a specified
archive to calculate the 95th percentile.  

If anyone has any updates to it, please send them to me so that everyone
can benefit from them.  And if you can teach me anything about how to
write neater, cleaner Perl, pleasepleaseplease send it to me.  :)

First, mrtg_archive:

-------------------------------------------------------------------
#!/usr/bin/perl

die "Need a list of parameters to monitor!\n" unless ($ARGV[0]);

$mrtg_dir = "/usr/local/mrtg";
$archive_dir = "/usr/local/mrtg/archives";

@time_data = localtime(time);
$time_data[4]++;
$time_data[5] = $time_data[5] + 1900;
@months = ("Skip","Jan","Feb","Mar","Apr","May","Jun",
	   "Jul","Aug","Sep","Oct","Nov","Dec");

$datestamp = "$time_data[5]$time_data[4]$time_data[3]";

for ($a=0; $a<=$#ARGV; $a++) {
    (@path) = split(/\//,$ARGV[$a]);
    unless (-d "$archive_dir/$path[0]") {
	system("mkdir $archive_dir/$path[0]");
    }

    unless (-f "$archive_dir/$ARGV[$a]") {
	system("touch $archive_dir/$path[0]");
    }

    open(LOG,"$mrtg_dir/$ARGV[$a]");
    open(COPY,">>$archive_dir/$ARGV[$a]");
    while (<LOG>) {
	if ($count >= 3) {
	    print COPY;
	}
	if ($count >= 598) {
	    last;
	}
	$count++;
    }
}
-----------------------------------------------

Second, mrtg95:

--------------------------------------------------

#!/usr/bin/perl
#

die "Need to know what files to open!\n" unless ($ARGV[0]);

$archive_dir = "/usr/local/mrtg/archives";
$threshold = "95";

for ($a=0; $a<=$#ARGV; $a++) {
    open(LOG,"$archive_dir/$ARGV[$a]");
    while (<LOG>) {
	(@data) = split(/ /);
	$in_avg{$data[0]} = "$data[1]";
	$out_avg{$data[0]} = "$data[2]";
    }

    @keys = keys %in_avg;
    $entries = @keys;

    $index = -1 + int($entries * $threshold / 100);

    @in_avg = values(%in_avg);
    @out_avg = values (%out_avg);

    @sort_in_avg = sort {$a <=> $b} @in_avg;
    @sort_out_avg = sort {$a <=> $b} @out_avg;

    $high_in_avg = $sort_in_avg[$index];
    $high_out_avg = $sort_out_avg[$index];

    $level = $high_in_avg;
    $level = $high_out_avg if ($high_out_avg > $level);

    $level = $level * 8;

    print "$level\n";

}




Pete

--
Peter J. Templin, Jr., CCNA
Systems and Networks Administrator

On-Line Internet Services - URDirect.net
A division of Global On-Line Computers
2414 Babcock Rd. Suite 106		templin at urdirect.net
San Antonio, TX 78229			(210)692-9911

--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:mrtg-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/mrtg



More information about the mrtg mailing list