jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [networks/] [diagrams.pl] - Blame information for rev 18

 

Line No. Rev Author Line
11simandl#!/usr/bin/env perl
2use strict;
3use warnings;
4use diagnostics;
5 
6use lib "../../lib";
7use HotSaNICparser;
8use HotSaNICdiagram;
9use RRDs;
10 
11# read global settings
12#
13my $MODNAME=HotSaNICparser::get_module_name();
14my %CONFIG=HotSaNICparser::get_config("../..");
15 
16my $OUTDIR=$CONFIG{"WEBDIR"}."/".lc $MODNAME;
17if ( ! -e $OUTDIR ) { mkdir $OUTDIR,0755; }
18 
19my $IMGFMT=lc $CONFIG{"IMAGEFORMAT"};
20my $TEMPNAME="$OUTDIR/temp.$IMGFMT";
21 
22my $FORCE=@ARGV;
23my @ITEMS;
24my $STYLE="bytes";
25my $MULT=1;
26 
27# read module-specific settings
28#
29foreach (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 
42my $LEGEND="$STYLE/s";
43 
44# generate diagrams
45#
46foreach (@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",
1016simandl "STACK:icmpin#007700:other in",
1021simandl "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",
1156simandl "STACK:icmpout_inv#770000:other out",
1161simandl "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 }
131exit 0;
132 
133 

Powered by WebSVN 2.2.1