hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/usr/bin/env perl
use strict;
use warnings;
use diagnostics;
use lib "../../lib";
use HotSaNICparser;
use HotSaNICdiagram;
use RRDs;
# read global settings
#
my $MODNAME=HotSaNICparser::get_module_name();
my %CONFIG=HotSaNICparser::get_config("../..");
my $OUTDIR=$CONFIG{"WEBDIR"}."/".lc $MODNAME;
if ( ! -e $OUTDIR ) { mkdir $OUTDIR,0755; }
my $IMGFMT=lc $CONFIG{"IMAGEFORMAT"};
my $TEMPNAME="$OUTDIR/temp.$IMGFMT";
my ($LEGEND,@ITEMS,$name,$range,$descr);
my $IOMIN=500;
my $FORCE=@ARGV;
$LEGEND="accesses";
# generate diagrams
#
opendir DIR,"rrd";
@ITEMS=grep /\.rrd/,readdir DIR;
closedir DIR;
#if (! (@ITEMS) ) { print " No database found\n Please check if the daemon is running.\n";next; }
# if database exists, create images...
foreach my $dev (@ITEMS) {
($name=$dev) =~ s/\.rrd//g;
my $description=$name;
my $var;
my $mode;
my $command;
print "creating images for $description...\n";
foreach $range ("1h","6h","1day","1week","1month","1year") {
my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
my $FILENAME="$OUTDIR/$name-$file.$IMGFMT";
# print "$OUTDIR/$name-$file.$IMGFMT\n";
my $make=$FORCE;
if ($range eq "1h") { $make++; }
elsif (! -e "$FILENAME") { $make++; }
else {
my (undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime,undef,undef,undef) = stat( "$FILENAME" );
if (time > ($mtime+$build)) { $make++; }
}
if ($make>0) {
# print "make: $make $TEMPNAME $range $CONFIG{'WIDTH'} \n";
my ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b", "1024",
"-s","-$range", "-w",$CONFIG{"WIDTH"}, "-h",$CONFIG{"HEIGHT"}, "-a", uc($IMGFMT),
"-l 0", "--title", "$dev - last $descr ($DATESTRING)",
"DEF:ber=rrd/$dev:ber:AVERAGE",
"DEF:temp=rrd/$dev:temp:AVERAGE",
"DEF:rx1=rrd/$dev:rx1:AVERAGE",
"DEF:snr1=rrd/$dev:snr1:AVERAGE",
"DEF:rx2=rrd/$dev:rx2:AVERAGE",
"DEF:snr2=rrd/$dev:snr2:AVERAGE",
"DEF:preber=rrd/$dev:preber:AVERAGE",
"DEF:isi1=rrd/$dev:isi1:AVERAGE",
"DEF:isi2=rrd/$dev:isi2:AVERAGE",
"LINE2:ber#000080:ber",
"GPRINT:ber:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:ber:MIN: min\\:%3.1lf %s \\g",
"GPRINT:ber:MAX: max\\:%3.1lf %s \\g",
"GPRINT:ber:LAST: current\\:%3.1lf %s x100\\n",
"LINE2:temp#800000:temp",
"GPRINT:temp:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:temp:MIN: min\\:%3.1lf %s \\g",
"GPRINT:temp:MAX: max\\:%3.1lf %s \\g",
"GPRINT:temp:LAST: current\\:%3.1lf %s C\\n",
"LINE2:rx1#008000:rx1",
"GPRINT:rx1:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:rx1:MIN: min\\:%3.1lf %s \\g",
"GPRINT:rx1:MAX: max\\:%3.1lf %s \\g",
"GPRINT:rx1:LAST: current\\:%3.1lf %s dB\\n",
"LINE2:snr1#808080:snr1",
"GPRINT:snr1:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:snr1:MIN: min\\:%3.1lf %s \\g",
"GPRINT:snr1:MAX: max\\:%3.1lf %s \\g",
"GPRINT:snr1:LAST: current\\:%3.1lf %s dB\\n",
"LINE2:rx2#0000FF:rx2",
"GPRINT:rx2:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:rx2:MIN: min\\:%3.1lf %s \\g",
"GPRINT:rx2:MAX: max\\:%3.1lf %s \\g",
"GPRINT:rx2:LAST: current\\:%3.1lf %s dB\\n",
"LINE2:snr2#FF0000:snr2",
"GPRINT:snr2:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:snr2:MIN: min\\:%3.1lf %s \\g",
"GPRINT:snr2:MAX: max\\:%3.1lf %s \\g",
"GPRINT:snr2:LAST: current\\:%3.1lf %s dB\\n",
"LINE2:preber#7050D0:preber",
"GPRINT:preber:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:preber:MIN: min\\:%3.1lf %s \\g",
"GPRINT:preber:MAX: max\\:%3.1lf %s \\g",
"GPRINT:preber:LAST: current\\:%3.1lf %s x100\\n",
"LINE2:isi1#FF9000:isi1",
"GPRINT:isi1:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:isi1:MIN: min\\:%3.1lf %s \\g",
"GPRINT:isi1:MAX: max\\:%3.1lf %s \\g",
"GPRINT:isi1:LAST: current\\:%3.1lf %s ps/nm x100\\n",
"LINE2:isi2#EF80EF:isi2",
"GPRINT:isi2:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:isi2:MIN: min\\:%3.1lf %s \\g",
"GPRINT:isi2:MAX: max\\:%3.1lf %s \\g",
"GPRINT:isi2:LAST: current\\:%3.1lf %s ps/nm x100\\n",
"HRULE:0#000000";
# print "$TEMPNAME >> $FILENAME\n";
rename $TEMPNAME,$FILENAME;
# $xs = 0;
# $ys = 0;
printf " %-7s %d"."x%d %s\n",$descr,$xs,$ys,$FILENAME;
}
}
}
print "\n";
exit 0;
# if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},": unable to generate `$FILENAME': $ERROR\n"; }
#print "pred descr: $descr xs: $xs ys: $ys \n";