1 | 16 | 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 | | | my ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b", "1024", |
63 | | | "-s","-$range", "-w",$CONFIG{"WIDTH"}, "-h",$CONFIG{"HEIGHT"}, "-a", uc($IMGFMT), |
64 | | | "-l 0", "--title", "Stats for AS$name - last $descr ($DATESTRING)", |
65 | | | "DEF:rate=rrd/$dev:rate:AVERAGE", |
66 | | | "DEF:quality=rrd/$dev:quality:AVERAGE", |
67 | | | "DEF:signal=rrd/$dev:signal:AVERAGE", |
68 | | | "DEF:noise=rrd/$dev:noise:AVERAGE", |
69 | | | "LINE2:rate#000080:Path length", |
70 | | | "LINE2:quality#800000:", |
71 | | | "LINE2:signal#008000:", |
72 | | | "LINE2:noise#808080:", |
73 | | | "HRULE:0#000000"; |
74 | | | rename $TEMPNAME,$FILENAME; |
75 | | | printf " %-7s %d"."x%d %s\n",$descr,$xs,$ys,$FILENAME; |
76 | | | } |
77 | | | } |
78 | | | } |
79 | | | print "\n"; |
80 | | | exit 0; |
81 | | | |
82 | | | |