[mrtg] Re: 95th%

Pete Templin templin at urdirect.net
Tue Feb 22 01:49:23 MET 2000


On Mon, 21 Feb 2000, Jon Rust wrote:

> At 3:46 PM -0500 2/21/00, John Lord wrote:
> >
> >I just got my servers colocated at above net and noticed that on their graph
> >they gave me for my site there is a 95th% on the months graph. How do you
> >get mrtg to out that there? I run mrtg on nt to monitor my other routers
> >here and have never seen that.
> 
> Above uses a heavily hacked version of MRTG to do it. It is not 
> publicly available to the best of my knowledge. Bummer.

I don't know how to have MRTG display it, but I wrote scripts to calculate
it.  I make no promises for the quality of the code, but it works fine for
me.  Someday, it'll weed out duplicate data, but for now I know that it is
working for me.

mrtg_archive (archives the data):

#!/usr/bin/perl
#

# Configurations
$mrtg_dir = "/usr/local/mrtg";
$archive_dir = "/usr/local/mrtg/archives";
$conf = "/usr/local/scripts/mrtg_archive.conf";

# Read a config file if present.
if (-e $conf) {
    open(CONF,"$conf");
    while(<CONF>) {
	chomp;
	push(@elements,$_);
    }
}

# Take arguments from the command line if present.
@elements = @ARGV if (@ARGV);

# Fail if no arguments.
die "Need a list of parameters to monitor!\n" unless (@elements);

# Process each of the elements
for ($a=0; $a<=$#elements; $a++) {
    $count = undef;
    ($path,$comment) = split(/:/,$elements[$a]);
    (@path) = split(/\//,$path);
    unless (-d "$archive_dir/$path[0]") {
	system("mkdir $archive_dir/$path[0]");
    }

    unless (-f "$archive_dir/$path") {
	system("touch $archive_dir/$path");
    }

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

mrtg_archive.conf:

catalyst/catalyst1-bldg1.1.log:Smith Barney, 300 Convent
cisco/cisco2.2.log:Pete Templin, Camino Villa
cisco/cisco1.2.log:On-Line Computers, Internet Feed


mrtg95 (reads the data):

#!/usr/bin/perl
#

# Configurations
$archive_dir = "/usr/local/mrtg/archives";
$threshold = "95";
$conf = "/usr/local/scripts/mrtg_archive.conf";
@months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

# Check for configuration file
if (-e $conf) {
    open(CONF,"$conf");
    while(<CONF>) {
	chomp;
	push(@elements,$_);
    }
}

# Use command-line arguments
@elements = @ARGV if (@ARGV);

# Fail if no arguments present
die "Need a list of parameters to monitor!\n" unless (@elements);

# Process the elements
for ($a=0; $a<=$#elements; $a++) {	# Each logfile as an argument.
    %data = undef;
    %record = undef;

    ($path,$comment) = split(/:/,$elements[$a]);
    open(LOG,"$archive_dir/$path") || next;
    while (<LOG>) {
	(@data) = split(/ /);
	@date_info = localtime($data[0]); # Get the date info
	$date_info[5] = $date_info[5] + 1900; # Calendar Year
	if ($date_info[4] < 10) {
	    $date_info[4] = "0" . $date_info[4];
	}
	$date_info[4] = "00" unless ($date_info[4]);
	$datestamp = "$date_info[5]$date_info[4]";
	$record{$datestamp} = 1;	# Know which months our data covers
	$data{$datestamp}{$data[0]} = "$data[1]:$data[2]";
    }

    @dates = keys ( %record );
    @sorted_dates = sort {$a <=> $b} @dates;

    for ($b=0; $b<=$#sorted_dates; $b++) { # Loop through each month
	@in = undef;
	@out = undef;

	$year = substr($sorted_dates[$b],0,4);
	$month = substr($sorted_dates[$b],4,2);
	$month_name = $months[$month];

	@values = values %{ $data{$sorted_dates[$b]}};

	$entries = scalar (@values);

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

#	print "$entries\t$index\n";

	for ($c=0; $c<=$#values; $c++) {
	    ($in,$out) = split(/:/,$values[$c]);
	    push(@in,$in);
	    push(@out,$out);
	}
	
	@sort_in = sort {$a <=> $b} @in;
	@sort_out = sort {$a <=> $b} @out;

	$high_in = $sort_in[$index];
	$high_out = $sort_out[$index];

	$level = $high_in;
	$level = $high_out if ($high_out >= $level);

	$level = $level * 8;

	if ($comment) {
	    print "$comment usage for $month_name $ year is ";
	}
	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