1 | 1 | 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 $FORCE=@ARGV; |
23 | | | my @ITEMS; |
24 | | | my $STYLE="bytes"; |
25 | | | my $MULT=1; |
26 | | | |
27 | | | # read module-specific settings |
28 | | | # |
29 | | | foreach (HotSaNICparser::read_settings(".")) { |
30 | | | my ($var,$value)=HotSaNICparser::parse_line($_); |
31 | | | if ($var eq "STYLE") { |
32 | | | $STYLE=lc $value; |
33 | | | if ($STYLE eq "bits") { $MULT=8; } |
34 | | | } |
35 | | | if (index($var,"DEV") >= 0 ) { |
36 | | | $var = lc $var; |
37 | | | $var =~ s/dev//g; |
38 | | | push @ITEMS,"$var$value"; |
39 | | | } |
40 | | | } |
41 | | | |
42 | | | my $LEGEND="$STYLE/s"; |
43 | | | |
44 | | | # generate diagrams |
45 | | | # |
46 | | | foreach (@ITEMS) { |
47 | | | my ($dev,$devname)=split /,/; |
48 | | | (my $name=$dev)=~ s/\//_/g; |
49 | | | |
50 | | | # if database exists, create images... |
51 | | | if ( -e "./rrd/$name.rrd") { |
52 | | | print "creating images for $dev ($devname) ...\n"; |
53 | | | |
54 | | | foreach my $range ("1h","6h","1day","1week","1month","1year") { |
55 | | | my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range); |
56 | | | |
57 | | | my $FILENAME="$OUTDIR/$name-$file.$IMGFMT"; |
58 | | | |
59 | | | my $make=$FORCE; |
60 | | | if ($range eq "1h") { $make++; } |
61 | | | elsif (! -e "$FILENAME") { $make++; } |
62 | | | else { |
63 | | | my (undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime,undef,undef,undef) = stat( "$FILENAME" ); |
64 | | | if (time > ($mtime+$build)) { $make++; } |
65 | | | } |
66 | | | |
67 | | | if ($make>0) { |
68 | | | |
69 | | | my ($prints,$xs,$ys); |
70 | | | |
71 | | | ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b","1024", "-v", $LEGEND, |
72 | | | "-s","-$range", "-w",$CONFIG{"WIDTH"}, "-h",$CONFIG{"HEIGHT"}, "-a", uc($IMGFMT), |
73 | | | "-u 1000", "-l -1000", "--title", "traffic to $dev - last $descr ($DATESTRING)", |
74 | | | "DEF:dbtcpin=rrd/$name.rrd:tcpin:AVERAGE", |
75 | | | "DEF:dbudpin=rrd/$name.rrd:udpin:AVERAGE", |
76 | | | "DEF:dbicmpin=rrd/$name.rrd:icmpin:AVERAGE", |
77 | | | "DEF:dbtcpout=rrd/$name.rrd:tcpout:AVERAGE", |
78 | | | "DEF:dbudpout=rrd/$name.rrd:udpout:AVERAGE", |
79 | | | "DEF:dbicmpout=rrd/$name.rrd:icmpout:AVERAGE", |
80 | | | "CDEF:tcpin=dbtcpin,$MULT,*", |
81 | | | "CDEF:udpin=dbudpin,$MULT,*", |
82 | | | "CDEF:icmpin=dbicmpin,$MULT,*", |
83 | | | "CDEF:allin=tcpin,udpin,icmpin,+,+", |
84 | | | "CDEF:spanin=allin,$fullrange,*", |
85 | | | "CDEF:tcpout=dbtcpout,$MULT,*", |
86 | | | "CDEF:udpout=dbudpout,$MULT,*", |
87 | | | "CDEF:icmpout=dbicmpout,$MULT,*", |
88 | | | "CDEF:tcpout_inv=0,tcpout,-", |
89 | | | "CDEF:udpout_inv=0,udpout,-", |
90 | | | "CDEF:icmpout_inv=0,icmpout,-", |
91 | | | "CDEF:allout=tcpout,udpout,icmpout,+,+", |
92 | | | "CDEF:spanout=allout,$fullrange,*", |
93 | | | "AREA:tcpin#00ff00:tcp in", |
94 | | | "GPRINT:tcpin:MIN:(min\\: %6.2lf %s", |
95 | | | "GPRINT:tcpin:AVERAGE:avg\\: %6.2lf %s", |
96 | | | "GPRINT:tcpin:MAX:max\\: %6.2lf %s $LEGEND)\\n", |
97 | | | "STACK:udpin#00bb00:udp in", |
98 | | | "GPRINT:udpin:MIN:(min\\: %6.2lf %s", |
99 | | | "GPRINT:udpin:AVERAGE:avg\\: %6.2lf %s", |
100 | | | "GPRINT:udpin:MAX:max\\: %6.2lf %s $LEGEND)\\n", |
101 | 6 | simandl | "STACK:icmpin#007700:other in", |
102 | 1 | simandl | "GPRINT:icmpin:MIN:(min\\: %6.2lf %s", |
103 | | | "GPRINT:icmpin:AVERAGE:avg\\: %6.2lf %s", |
104 | | | "GPRINT:icmpin:MAX:max\\: %6.2lf %s $LEGEND)\\n", |
105 | | | "GPRINT:allin:AVERAGE: total average\\: %6.2lf %s $LEGEND", |
106 | | | "GPRINT:spanin:AVERAGE: - %6.2lf %s $STYLE/$descr\\n", |
107 | | | "AREA:tcpout_inv#ff0000:tcp out", |
108 | | | "GPRINT:tcpout:MIN:(min\\: %6.2lf %s", |
109 | | | "GPRINT:tcpout:AVERAGE:avg\\: %6.2lf %s", |
110 | | | "GPRINT:tcpout:MAX:max\\: %6.2lf %s $LEGEND)\\n", |
111 | | | "STACK:udpout_inv#bb0000:udp out", |
112 | | | "GPRINT:udpout:MIN:(min\\: %6.2lf %s", |
113 | | | "GPRINT:udpout:AVERAGE:avg\\: %6.2lf %s", |
114 | | | "GPRINT:udpout:MAX:max\\: %6.2lf %s $LEGEND)\\n", |
115 | 6 | simandl | "STACK:icmpout_inv#770000:other out", |
116 | 1 | simandl | "GPRINT:icmpout:MIN:(min\\: %6.2lf %s", |
117 | | | "GPRINT:icmpout:AVERAGE:avg\\: %6.2lf %s", |
118 | | | "GPRINT:icmpout:MAX:max\\: %6.2lf %s $LEGEND)\\n", |
119 | | | "GPRINT:allout:AVERAGE: total average\\: %6.2lf %s $LEGEND", |
120 | | | "GPRINT:spanout:AVERAGE: - %6.2lf %s $STYLE/$descr\\n", |
121 | | | "HRULE:0#000000"; |
122 | | | |
123 | | | rename $TEMPNAME,$FILENAME; |
124 | | | printf " %-7s %d"."x%d %s\n",$descr,$xs,$ys,$FILENAME; |
125 | | | } |
126 | | | } |
127 | | | } |
128 | | | else { print " No database found\n Please check if the daemon is running.\n";next; } |
129 | | | print "\n"; |
130 | | | } |
131 | | | exit 0; |
132 | | | |
133 | | | |