#!/usr/bin/perl -w use strict; use RRDs; use English; my $RRDPATH = shift @ARGV; die ("Usage: $PROGRAM_NAME \n") if (!defined $RRDPATH || scalar @ARGV > 0); my $HOSTNAME = `hostname`; my @MONTH = qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec}; #my $IMG_URL = 'http://images.noreply.org/load/'; my $IMG_URL = ''; my $NOW = time; my $GMTIME = gmtime($NOW); my $START_AT = $NOW-10*30*24*3600; opendir(D,$RRDPATH) or die ("Cannot opendir $RRDPATH: $!\n"); my @SOURCES = sort {$a cmp $b} grep { /\.rrd$/ && ! /\.pool\.rrd$/ } readdir(D); @SOURCES = grep { my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($RRDPATH.'/'.$_); $mtime >= $START_AT; } @SOURCES; closedir(D); my @params = qw{result/total.png}; push @params, sprintf('-s %s', $START_AT); #push @params, sprintf('-e %s', $NOW- 2*24*3600); push @params, sprintf('-t %s', "Network Load"); push @params, sprintf('-v %s', "Messages per day"); push @params, sprintf('-w %d', 600); push @params, sprintf('-h %d', 400); my @COLOR = qw{ 000000 0000FF 00FF00 00FFFF FF0000 FF00FF FFFF00 }; my $coli = 0; my $first = 1; my $body; my $index; for my $source (@SOURCES) { my $def = $source; $source = $RRDPATH.'/'.$source; $def =~ s/\.rrd$//; my $cdef = 'c_'.$def; my $color = $COLOR[ ($coli++) % (scalar @COLOR) ]; my $label = $def; push @params , sprintf('DEF:%s=%s:%s:%s', $def , $source, 'total', 'AVERAGE'); push @params , sprintf('CDEF:%s=%s' , $cdef , $def); push @params , sprintf('%s:%s#%s:%s' , $first ? 'AREA' : 'STACK' , $cdef , $color, $label ); $first = 0; my @this; push @this, sprintf('result/%s.png', $def); push @this, sprintf('-s %s', $START_AT); push @this, sprintf('-t %s', "$def Load"); push @this, sprintf('-v %s', "Messages per day"); push @this , sprintf('DEF:%s=%s:%s:%s', 't2' , $source, 'typeII', 'AVERAGE'); push @this , sprintf('CDEF:%s=%s' , 'ct2' , 't2'); push @this , sprintf('%s:%s#%s:%s' , 'AREA' , 'ct2' , '00FF00', 'Type II' ); push @this , sprintf('DEF:%s=%s:%s:%s', 't1' , $source, 'typeI', 'AVERAGE'); push @this , sprintf('CDEF:%s=%s' , 'ct1' , 't1'); push @this , sprintf('%s:%s#%s:%s' , 'STACK' , 'ct1' , '0000FF', 'Type I' ); push @this , sprintf('DEF:%s=%s:%s:%s', 'total' , $source, 'total', 'AVERAGE'); push @this , sprintf('CDEF:%s=%s' , 'ctotal' , 'total'); push @this , sprintf('%s:%s#%s:%s' , 'LINE3' , 'ctotal' , '000000', 'total' ); push @this , sprintf('CDEF:%s=total,0,*,%s,+' , 'topline' , '20000'); push @this , sprintf('CDEF:%s=total,0,*,%s,+' , 'zeroline' , '0'); push @this , sprintf('%s:%s' , 'LINE1' , 'topline' ); push @this , sprintf('%s:%s' , 'LINE1' , 'zeroline' ); my ($averages,$xsize,$ysize) = RRDs::graph @this; warn RRDs::error if RRDs::error; my $poolSize = ''; my $sourcePoolSize = $RRDPATH.'/'.$def.'.pool.rrd'; if ( -e $sourcePoolSize ) { my $that; my @that; push @that, sprintf('result/%s.pool.png', $def); push @that, sprintf('-s %s', $START_AT); push @that, sprintf('-t %s', "$def Pool Size"); push @that, sprintf('-v %s', "Messages in Pool"); push @that , sprintf('DEF:%s=%s:%s:%s', 'poolsizeA' , $sourcePoolSize, 'poolSize', 'AVERAGE'); push @that , sprintf('CDEF:%s=%s' , 'cpoolsizeA' , 'poolsizeA'); push @that , sprintf('%s:%s#%s:%s' , 'LINE3' , 'poolsizeA' , '0000FF', 'Pool Size' ); push @that , sprintf('CDEF:%s=poolsizeA,0,*,%s,+' , 'topline' , '400'); push @that , sprintf('CDEF:%s=poolsizeA,0,*,%s,+' , 'zeroline' , '0'); push @that , sprintf('%s:%s' , 'LINE1' , 'topline' ); push @that , sprintf('%s:%s' , 'LINE1' , 'zeroline' ); my ($PSaverages,$PSxsize,$PSysize) = RRDs::graph @that; warn RRDs::error if RRDs::error; $poolSize = " \"Pool"; } $body .= "

$def

top | latency

\"Load$poolSize

\n"; $index .= "
  • $def
  • \n"; } my ($averages,$xsize,$ysize) = RRDs::graph @params; die RRDs::error if RRDs::error; my $html = "Network Load"; $html .= "

    Network Load

    "; $html .= "..
    \n"; $html .= "

    "; $html .= "

    Single Nodes

    "; $html .= ""; $html .= $body; $html .= "


    \n"; $html .= 'Images created with Tobi Oetiker\'s rrdtool'."\n"; $html .= "
    \nBuilt at $GMTIME on $HOSTNAME
    \n"; $html .= "Peter Palfrader <web\@palfrader.org>\n"; $html .= "\n"; open (F, ">result/index.html") or die ("Cannot open index.html: $!\n"); print F $html; close F;