| 1 | 29 | simandl | #!/usr/bin/env perl |
| 2 | | | use strict; |
| 3 | | | use warnings; |
| 4 | | | use diagnostics; |
| 5 | | | |
| 6 | | | use lib "../../lib"; |
| 7 | | | use HotSaNICparser; |
| 8 | | | use HotSaNICdiagram; |
| 9 | | | use RRDs; |
| 10 | | | |
| 11 | | | # read global settings |
| 12 | | | # |
| 13 | | | my $MODNAME=HotSaNICparser::get_module_name(); |
| 14 | | | my %CONFIG=HotSaNICparser::get_config("../.."); |
| 15 | | | |
| 16 | | | my $OUTDIR=$CONFIG{"WEBDIR"}."/".lc $MODNAME; |
| 17 | | | if ( ! -e $OUTDIR ) { mkdir $OUTDIR,0755; } |
| 18 | | | |
| 19 | | | my $IMGFMT=lc $CONFIG{"IMAGEFORMAT"}; |
| 20 | | | my $TEMPNAME="$OUTDIR/temp.$IMGFMT"; |
| 21 | | | |
| 22 | | | my ($LEGEND,@ITEMS,$name,$range,$descr); |
| 23 | | | my $IOMIN=500; |
| 24 | | | |
| 25 | | | my $FORCE=@ARGV; |
| 26 | | | |
| 27 | | | $LEGEND="accesses"; |
| 28 | | | |
| 29 | | | # generate diagrams |
| 30 | | | # |
| 31 | | | |
| 32 | | | opendir DIR,"rrd"; |
| 33 | | | @ITEMS=grep /\.rrd/,readdir DIR; |
| 34 | | | closedir DIR; |
| 35 | | | |
| 36 | | | if (! (@ITEMS) ) { print " No database found\n Please check if the daemon is running.\n";next; } |
| 37 | | | |
| 38 | | | # if database exists, create images... |
| 39 | | | foreach my $dev (@ITEMS) { |
| 40 | | | ($name=$dev) =~ s/\.rrd//g; |
| 41 | | | my $description=$name; |
| 42 | | | my $var; |
| 43 | | | my $mode; |
| 44 | | | my $command; |
| 45 | | | |
| 46 | | | print "creating images for $description...\n"; |
| 47 | | | |
| 48 | | | foreach $range ("1h","6h","1day","1week","1month","1year") { |
| 49 | | | my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range); |
| 50 | | | |
| 51 | | | my $FILENAME="$OUTDIR/$name-$file.$IMGFMT"; |
| 52 | | | |
| 53 | | | my $make=$FORCE; |
| 54 | | | if ($range eq "1h") { $make++; } |
| 55 | | | elsif (! -e "$FILENAME") { $make++; } |
| 56 | | | else { |
| 57 | | | my (undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime,undef,undef,undef) = stat( "$FILENAME" ); |
| 58 | | | if (time > ($mtime+$build)) { $make++; } |
| 59 | | | } |
| 60 | | | |
| 61 | | | if ($make>0) { |
| 62 | | | #print "make: $make $TEMPNAME $range $CONFIG{"WIDTH"} \n"; |
| 63 | | | my ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b", "1024", |
| 64 | | | "-s","-$range", "-w",$CONFIG{"WIDTH"}, "-h",$CONFIG{"HEIGHT"}, "-a", uc($IMGFMT), |
| 65 | | | "-l 0", "--title", "$dev - last $descr ($DATESTRING)", |
| 66 | | | "DEF:freq=rrd/$dev:freq:AVERAGE", |
| 67 | | | "DEF:mcs=rrd/$dev:mcs:AVERAGE", |
| 68 | | | "DEF:signal=rrd/$dev:signal:AVERAGE", |
| 69 | | | "DEF:txsec=rrd/$dev:txsec:AVERAGE", |
| 70 | | | "DEF:rssi=rrd/$dev:rssi:AVERAGE", |
| 71 | | | "DEF:rate=rrd/$dev:rate:AVERAGE", |
| 72 | | | "LINE2:freq#000080:freq", |
| 73 | | | "GPRINT:freq:AVERAGE: avg\\:%3.1lf %s \\g", |
| 74 | | | "GPRINT:freq:MIN: min\\:%3.1lf %s \\g", |
| 75 | | | "GPRINT:freq:MAX: max\\:%3.1lf %s \\g", |
| 76 | | | "GPRINT:freq:LAST: current\\:%3.1lf %s GHz\\n", |
| 77 | | | "LINE2:mcs#800000:mcs", |
| 78 | | | "GPRINT:mcs:AVERAGE: avg\\:%3.1lf %s \\g", |
| 79 | | | "GPRINT:mcs:MIN: min\\:%3.1lf %s \\g", |
| 80 | | | "GPRINT:mcs:MAX: max\\:%3.1lf %s \\g", |
| 81 | | | "GPRINT:mcs:LAST: current\\:%3.1lf %s \\n", |
| 82 | | | "LINE2:signal#008000:signal", |
| 83 | | | "GPRINT:signal:AVERAGE: avg\\:%3.1lf %s \\g", |
| 84 | | | "GPRINT:signal:MIN: min\\:%3.1lf %s \\g", |
| 85 | | | "GPRINT:signal:MAX: max\\:%3.1lf %s \\g", |
| 86 | | | "GPRINT:signal:LAST: current\\:%3.1lf %s \\n", |
| 87 | | | "LINE2:txsec#808080:txsec", |
| 88 | | | "GPRINT:txsec:AVERAGE: avg\\:%3.1lf %s \\g", |
| 89 | | | "GPRINT:txsec:MIN: min\\:%3.1lf %s \\g", |
| 90 | | | "GPRINT:txsec:MAX: max\\:%3.1lf %s \\g", |
| 91 | | | "GPRINT:txsec:LAST: current\\:%3.1lf %s \\n", |
| 92 | | | "LINE2:rssi#0000FF:rssi", |
| 93 | | | "GPRINT:rssi:AVERAGE: avg\\:%3.1lf %s \\g", |
| 94 | | | "GPRINT:rssi:MIN: min\\:%3.1lf %s \\g", |
| 95 | | | "GPRINT:rssi:MAX: max\\:%3.1lf %s \\g", |
| 96 | | | "GPRINT:rssi:LAST: current\\:%3.1lf %s dB\\n", |
| 97 | | | "LINE2:rate#FF0000:rate", |
| 98 | | | "GPRINT:rate:AVERAGE: avg\\:%3.1lf %s \\g", |
| 99 | | | "GPRINT:rate:MIN: min\\:%3.1lf %s \\g", |
| 100 | | | "GPRINT:rate:MAX: max\\:%3.1lf %s \\g", |
| 101 | | | "GPRINT:rate:LAST: current\\:%3.1lf %s Gbps\\n", |
| 102 | | | "HRULE:0#000000"; |
| 103 | | | rename $TEMPNAME,$FILENAME; |
| 104 | | | printf " %-7s %d"."x%d %s\n",$descr,$xs,$ys,$FILENAME; |
| 105 | | | } |
| 106 | | | } |
| 107 | | | } |
| 108 | | | print "\n"; |
| 109 | | | exit 0; |
| 110 | | | |
| 111 | | | # if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},": unable to generate `$FILENAME': $ERROR\n"; } |
| 112 | | | #print "pred descr: $descr xs: $xs ys: $ys \n"; |
| 113 | | | |
| 114 | | | |
| 115 | | | |