| 1 | 32 | 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 | | | # print "$OUTDIR/$name-$file.$IMGFMT\n"; |
| 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:ber=rrd/$dev:ber:AVERAGE", |
| 67 | | | "DEF:temp=rrd/$dev:temp:AVERAGE", |
| 68 | | | "DEF:rx1=rrd/$dev:rx1:AVERAGE", |
| 69 | | | "DEF:snr1=rrd/$dev:snr1:AVERAGE", |
| 70 | | | "DEF:rx2=rrd/$dev:rx2:AVERAGE", |
| 71 | | | "DEF:snr2=rrd/$dev:snr2:AVERAGE", |
| 72 | | | "DEF:preber=rrd/$dev:preber:AVERAGE", |
| 73 | | | "DEF:isi1=rrd/$dev:isi1:AVERAGE", |
| 74 | | | "DEF:isi2=rrd/$dev:isi2:AVERAGE", |
| 75 | | | "LINE2:ber#000080:ber", |
| 76 | | | "GPRINT:ber:AVERAGE: avg\\:%3.1lf %s \\g", |
| 77 | | | "GPRINT:ber:MIN: min\\:%3.1lf %s \\g", |
| 78 | | | "GPRINT:ber:MAX: max\\:%3.1lf %s \\g", |
| 79 | | | "GPRINT:ber:LAST: current\\:%3.1lf %s x100\\n", |
| 80 | | | "LINE2:temp#800000:temp", |
| 81 | | | "GPRINT:temp:AVERAGE: avg\\:%3.1lf %s \\g", |
| 82 | | | "GPRINT:temp:MIN: min\\:%3.1lf %s \\g", |
| 83 | | | "GPRINT:temp:MAX: max\\:%3.1lf %s \\g", |
| 84 | | | "GPRINT:temp:LAST: current\\:%3.1lf %s C\\n", |
| 85 | | | "LINE2:rx1#008000:rx1", |
| 86 | | | "GPRINT:rx1:AVERAGE: avg\\:%3.1lf %s \\g", |
| 87 | | | "GPRINT:rx1:MIN: min\\:%3.1lf %s \\g", |
| 88 | | | "GPRINT:rx1:MAX: max\\:%3.1lf %s \\g", |
| 89 | | | "GPRINT:rx1:LAST: current\\:%3.1lf %s dB\\n", |
| 90 | | | "LINE2:snr1#808080:snr1", |
| 91 | | | "GPRINT:snr1:AVERAGE: avg\\:%3.1lf %s \\g", |
| 92 | | | "GPRINT:snr1:MIN: min\\:%3.1lf %s \\g", |
| 93 | | | "GPRINT:snr1:MAX: max\\:%3.1lf %s \\g", |
| 94 | | | "GPRINT:snr1:LAST: current\\:%3.1lf %s dB\\n", |
| 95 | | | "LINE2:rx2#0000FF:rx2", |
| 96 | | | "GPRINT:rx2:AVERAGE: avg\\:%3.1lf %s \\g", |
| 97 | | | "GPRINT:rx2:MIN: min\\:%3.1lf %s \\g", |
| 98 | | | "GPRINT:rx2:MAX: max\\:%3.1lf %s \\g", |
| 99 | | | "GPRINT:rx2:LAST: current\\:%3.1lf %s dB\\n", |
| 100 | | | "LINE2:snr2#FF0000:snr2", |
| 101 | | | "GPRINT:snr2:AVERAGE: avg\\:%3.1lf %s \\g", |
| 102 | | | "GPRINT:snr2:MIN: min\\:%3.1lf %s \\g", |
| 103 | | | "GPRINT:snr2:MAX: max\\:%3.1lf %s \\g", |
| 104 | | | "GPRINT:snr2:LAST: current\\:%3.1lf %s dB\\n", |
| 105 | | | "LINE2:preber#7050D0:preber", |
| 106 | | | "GPRINT:preber:AVERAGE: avg\\:%3.1lf %s \\g", |
| 107 | | | "GPRINT:preber:MIN: min\\:%3.1lf %s \\g", |
| 108 | | | "GPRINT:preber:MAX: max\\:%3.1lf %s \\g", |
| 109 | | | "GPRINT:preber:LAST: current\\:%3.1lf %s x100\\n", |
| 110 | | | "LINE2:isi1#FF9000:isi1", |
| 111 | | | "GPRINT:isi1:AVERAGE: avg\\:%3.1lf %s \\g", |
| 112 | | | "GPRINT:isi1:MIN: min\\:%3.1lf %s \\g", |
| 113 | | | "GPRINT:isi1:MAX: max\\:%3.1lf %s \\g", |
| 114 | | | "GPRINT:isi1:LAST: current\\:%3.1lf %s ps/nm x100\\n", |
| 115 | | | "LINE2:isi2#EF80EF:isi2", |
| 116 | | | "GPRINT:isi2:AVERAGE: avg\\:%3.1lf %s \\g", |
| 117 | | | "GPRINT:isi2:MIN: min\\:%3.1lf %s \\g", |
| 118 | | | "GPRINT:isi2:MAX: max\\:%3.1lf %s \\g", |
| 119 | | | "GPRINT:isi2:LAST: current\\:%3.1lf %s ps/nm x100\\n", |
| 120 | | | "HRULE:0#000000"; |
| 121 | | | # print "$TEMPNAME >> $FILENAME\n"; |
| 122 | | | rename $TEMPNAME,$FILENAME; |
| 123 | | | # $xs = 0; |
| 124 | | | # $ys = 0; |
| 125 | | | printf " %-7s %d"."x%d %s\n",$descr,$xs,$ys,$FILENAME; |
| 126 | | | } |
| 127 | | | } |
| 128 | | | } |
| 129 | | | print "\n"; |
| 130 | | | exit 0; |
| 131 | | | |
| 132 | | | # if ($ERROR = RRDs::error) { print time," ",$args{MODNAME},": unable to generate `$FILENAME': $ERROR\n"; } |
| 133 | | | #print "pred descr: $descr xs: $xs ys: $ys \n"; |
| 134 | | | |
| 135 | | | |
| 136 | | | |