| 1 | 31 | 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 (@ITEMS,$name,$range,$descr); |
| 23 | | | my $IOMIN=500; |
| 24 | | | |
| 25 | | | my $FORCE=@ARGV; |
| 26 | | | |
| 27 | | | my $COLOR_READ_LINE="00a000"; |
| 28 | | | my $COLOR_READ_AREA="a0ffa0"; |
| 29 | | | my $COLOR_WRITE_LINE="a00000"; |
| 30 | | | my $COLOR_WRITE_AREA="ffa0a0"; |
| 31 | | | my $COLOR_BETWEEN="c0c0c0"; |
| 32 | | | my $COLOR_WRONGDATA="ffffa0"; |
| 33 | | | |
| 34 | | | # read module-specific settings |
| 35 | | | # |
| 36 | | | foreach (HotSaNICparser::read_settings(".")) { |
| 37 | | | my ($var,$value)=HotSaNICparser::parse_line($_); |
| 38 | | | if ($var eq "DEV") { |
| 39 | | | push @ITEMS,$value; |
| 40 | | | } |
| 41 | | | } |
| 42 | | | |
| 43 | | | my $LEGEND="bytes/s"; |
| 44 | | | |
| 45 | | | # generate diagrams |
| 46 | | | # |
| 47 | | | foreach (@ITEMS) { |
| 48 | | | my ($dev,$description)=split /,/; |
| 49 | | | ($name=$description)=~ s/.*\///g; |
| 50 | | | |
| 51 | | | # if database exists, create images... |
| 52 | | | if ( -e "./rrd/$dev.rrd") { |
| 53 | | | print "creating images for $description...\n"; |
| 54 | | | |
| 55 | | | foreach $range ("1h","6h","1day","1week","1month","1year") { |
| 56 | | | my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range); |
| 57 | | | |
| 58 | | | my $FILENAME="$OUTDIR/$name-$file.$IMGFMT"; |
| 59 | | | |
| 60 | | | my $make=$FORCE; |
| 61 | | | if ($range eq "1h") { $make++; } |
| 62 | | | elsif (! -e "$FILENAME") { $make++; } |
| 63 | | | else { |
| 64 | | | my (undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime,undef,undef,undef) = stat( "$FILENAME" ); |
| 65 | | | if (time > ($mtime+$build)) { $make++; } |
| 66 | | | } |
| 67 | | | |
| 68 | | | if ($make>0) { |
| 69 | | | |
| 70 | | | my ($prints,$xs,$ys); |
| 71 | | | |
| 72 | | | if ($^O =~ /linux/) { |
| 73 | | | ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b","1024", "-v", $LEGEND, |
| 74 | | | "-s","-$range", "-w",$CONFIG{"WIDTH"}, "-h",$CONFIG{"HEIGHT"}, "-a", uc($IMGFMT), |
| 75 | | | "-u",$IOMIN, "-l",(-$IOMIN), "--title", "I/O rates on $name - last $descr ($DATESTRING)", |
| 76 | | | "DEF:iracc=rrd/$dev.rrd:racc:MIN", |
| 77 | | | "DEF:iwacc=rrd/$dev.rrd:wacc:MIN", |
| 78 | | | "DEF:irbyt=rrd/$dev.rrd:rbyt:MIN", |
| 79 | | | "DEF:iwbyt=rrd/$dev.rrd:wbyt:MIN", |
| 80 | | | "DEF:aracc=rrd/$dev.rrd:racc:AVERAGE", |
| 81 | | | "DEF:awacc=rrd/$dev.rrd:wacc:AVERAGE", |
| 82 | | | "DEF:arbyt=rrd/$dev.rrd:rbyt:AVERAGE", |
| 83 | | | "DEF:awbyt=rrd/$dev.rrd:wbyt:AVERAGE", |
| 84 | | | "DEF:xracc=rrd/$dev.rrd:racc:MAX", |
| 85 | | | "DEF:xwacc=rrd/$dev.rrd:wacc:MAX", |
| 86 | | | "DEF:xrbyt=rrd/$dev.rrd:rbyt:MAX", |
| 87 | | | "DEF:xwbyt=rrd/$dev.rrd:wbyt:MAX", |
| 88 | | | "CDEF:iwbyt_inv=0,iwbyt,-", |
| 89 | | | "CDEF:awbyt_inv=0,awbyt,-", |
| 90 | | | "CDEF:xwbyt_inv=0,xwbyt,-", |
| 91 | | | "AREA:xrbyt#$COLOR_READ_AREA:", |
| 92 | | | "AREA:irbyt#$COLOR_BETWEEN:", |
| 93 | | | "LINE1:arbyt#$COLOR_READ_LINE:read\\g", |
| 94 | | | "GPRINT:irbyt:MIN: min\\:%7.2lf %s", |
| 95 | | | "GPRINT:arbyt:AVERAGE: avg\\:%7.2lf %s", |
| 96 | | | "GPRINT:xrbyt:MAX: max\\:%7.2lf %s $LEGEND\\n", |
| 97 | | | "GPRINT:iracc:MIN: (min\\:%7.2lf %s", |
| 98 | | | "GPRINT:aracc:AVERAGE: avg\\:%7.2lf %s", |
| 99 | | | "GPRINT:xracc:MAX: max\\:%7.2lf %s accesses/s)\\n", |
| 100 | | | "COMMENT:\\s", |
| 101 | | | "AREA:xwbyt_inv#$COLOR_WRITE_AREA:", |
| 102 | | | "AREA:iwbyt_inv#$COLOR_BETWEEN:", |
| 103 | | | "LINE1:awbyt_inv#$COLOR_WRITE_LINE:write\\g", |
| 104 | | | "GPRINT:iwbyt:MIN: min\\:%7.2lf %s", |
| 105 | | | "GPRINT:awbyt:AVERAGE: avg\\:%7.2lf %s", |
| 106 | | | "GPRINT:xwbyt:MAX: max\\:%7.2lf %s $LEGEND\\n", |
| 107 | | | "GPRINT:iwacc:MIN: (min\\:%7.2lf %s", |
| 108 | | | "GPRINT:awacc:AVERAGE: avg\\:%7.2lf %s", |
| 109 | | | "GPRINT:xwacc:MAX: max\\:%7.2lf %s accesses/s)\\n", |
| 110 | | | "HRULE:0#000000"; |
| 111 | | | } |
| 112 | | | elsif ($^O =~ /bsd/) { |
| 113 | | | ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b","1024", "-v", $LEGEND, |
| 114 | | | "-s","-$range", "-w",$CONFIG{"WIDTH"}, "-h",$CONFIG{"HEIGHT"}, "-a", uc($IMGFMT), |
| 115 | | | "-u",$IOMIN, "-l",(-$IOMIN), "--title", "I/O rates on $name - last $descr ($DATESTRING)", |
| 116 | | | "DEF:ikbt=rrd/$dev.rrd:kbt:MIN", |
| 117 | | | "DEF:akbt=rrd/$dev.rrd:kbt:AVERAGE", |
| 118 | | | "DEF:xkbt=rrd/$dev.rrd:kbt:MAX", |
| 119 | | | "DEF:ixfr=rrd/$dev.rrd:xfr:MIN", |
| 120 | | | "DEF:axfr=rrd/$dev.rrd:xfr:AVERAGE", |
| 121 | | | "DEF:xxfr=rrd/$dev.rrd:xfr:MAX", |
| 122 | | | "DEF:itime=rrd/$dev.rrd:time:MIN", |
| 123 | | | "DEF:atime=rrd/$dev.rrd:time:AVERAGE", |
| 124 | | | "DEF:xtime=rrd/$dev.rrd:time:MAX", |
| 125 | | | "DEF:imb=rrd/$dev.rrd:mb:MIN", |
| 126 | | | "DEF:amb=rrd/$dev.rrd:mb:AVERAGE", |
| 127 | | | "DEF:xmb=rrd/$dev.rrd:mb:MAX", |
| 128 | | | "AREA:amb#FF4040:Disk Transfer\\g", |
| 129 | | | "GPRINT:imb:MIN: min\\:%7.2lf %s", |
| 130 | | | "GPRINT:amb:AVERAGE: avg\\:%7.2lf %s", |
| 131 | | | "GPRINT:xmb:MAX: max\\:%7.2lf %s bytes/s\\n", |
| 132 | | | "COMMENT:\\s", |
| 133 | | | "HRULE:0#000000"; |
| 134 | | | } |
| 135 | | | |
| 136 | | | rename $TEMPNAME,$FILENAME; |
| 137 | | | printf " %-7s %d"."x%d %s\n",$descr,$xs,$ys,$FILENAME; |
| 138 | | | |
| 139 | | | } |
| 140 | | | } |
| 141 | | | } |
| 142 | | | else { print " No database found\n Please check if the daemon is running.\n";next; } |
| 143 | | | print "\n"; |
| 144 | | | } |
| 145 | | | exit 0; |
| 146 | | | |
| 147 | | | |