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";
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:freq=rrd/$dev:freq:AVERAGE",
"DEF:mcs=rrd/$dev:mcs:AVERAGE",
"DEF:signal=rrd/$dev:signal:AVERAGE",
"DEF:txsec=rrd/$dev:txsec:AVERAGE",
"DEF:rssi=rrd/$dev:rssi:AVERAGE",
"DEF:rate=rrd/$dev:rate:AVERAGE",
"LINE2:freq#000080:freq",
"GPRINT:freq:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:freq:MIN: min\\:%3.1lf %s \\g",
"GPRINT:freq:MAX: max\\:%3.1lf %s \\g",
"GPRINT:freq:LAST: current\\:%3.1lf %s GHz\\n",
"LINE2:mcs#800000:mcs",
"GPRINT:mcs:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:mcs:MIN: min\\:%3.1lf %s \\g",
"GPRINT:mcs:MAX: max\\:%3.1lf %s \\g",
"GPRINT:mcs:LAST: current\\:%3.1lf %s \\n",
"LINE2:signal#008000:signal",
"GPRINT:signal:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:signal:MIN: min\\:%3.1lf %s \\g",
"GPRINT:signal:MAX: max\\:%3.1lf %s \\g",
"GPRINT:signal:LAST: current\\:%3.1lf %s \\n",
"LINE2:txsec#808080:txsec",
"GPRINT:txsec:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:txsec:MIN: min\\:%3.1lf %s \\g",
"GPRINT:txsec:MAX: max\\:%3.1lf %s \\g",
"GPRINT:txsec:LAST: current\\:%3.1lf %s \\n",
"LINE2:rssi#0000FF:rssi",
"GPRINT:rssi:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:rssi:MIN: min\\:%3.1lf %s \\g",
"GPRINT:rssi:MAX: max\\:%3.1lf %s \\g",
"GPRINT:rssi:LAST: current\\:%3.1lf %s dB\\n",
"LINE2:rate#FF0000:rate",
"GPRINT:rate:AVERAGE: avg\\:%3.1lf %s \\g",
"GPRINT:rate:MIN: min\\:%3.1lf %s \\g",
"GPRINT:rate:MAX: max\\:%3.1lf %s \\g",
"GPRINT:rate:LAST: current\\:%3.1lf %s Gbps\\n",
"HRULE:0#000000";
rename $TEMPNAME,$FILENAME;
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";