1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | |
3 | | | # $Id: diagrams.pl,v 1.17 2004/05/26 18:21:13 bernisys Exp $ |
4 | | | |
5 | | | # include PERL libraries |
6 | | | use strict; |
7 | | | use warnings; |
8 | | | use diagnostics; |
9 | | | |
10 | | | # include HotSaNIC libraries |
11 | | | use lib "../../lib"; |
12 | | | use lib "./platform"; |
13 | | | use HotSaNICparser; |
14 | | | use HotSaNICdiagram; |
15 | | | use common; |
16 | | | |
17 | | | (my $VERSION = '$Revision: 1.17 $') =~ s/.*(\d+\.\d+).*/$1/; |
18 | | | (my $IDENTIFIER = '$Id: diagrams.pl,v 1.17 2004/05/26 18:21:13 bernisys Exp $') =~ s/.*,v (.*) \$/$1/; |
19 | | | |
20 | | | # read all settings |
21 | | | # |
22 | | | my $MODNAME=HotSaNICparser::get_module_name(); |
23 | | | my %CONFIG=HotSaNICparser::get_config("../.."); |
24 | | | my %MODULECONFIG=HotSaNICmod::common::configure(); |
25 | | | |
26 | | | my $IMGFMT=lc $CONFIG{"IMAGEFORMAT"}; |
27 | | | |
28 | | | my $OUTDIR=$CONFIG{"WEBDIR"}."/".lc $MODNAME; |
29 | | | if ( ! -e $OUTDIR ) { mkdir $OUTDIR,0755; } |
30 | | | |
31 | | | my ($FORCE,$DEBUGLEVEL,%PLOT)=HotSaNICdiagram::check_args(@ARGV); |
32 | | | my @OPTIONS=HotSaNICdiagram::get_common_options(%MODULECONFIG,%CONFIG); |
33 | | | |
34 | | | # handle module-specific stuff |
35 | | | # |
36 | | | my $LEGEND=$MODULECONFIG{GRAPH_BASE}."/s"; |
37 | | | push @OPTIONS,( |
38 | | | "-v",$LEGEND, # Y-legend |
39 | | | "--alt-autoscale", # alternate scaling |
40 | | | "-a",uc($IMGFMT)); # image format |
41 | | | |
42 | | | # generate diagrams |
43 | | | # |
44 | | | foreach my $entry (@{$MODULECONFIG{DEV}}) { |
45 | | | my (undef,undef,$item,$DB_FILE,$name,$file,$description)=HotSaNICmod::common::get_names($entry); |
46 | | | |
47 | | | if (%PLOT) { next if ! defined $PLOT{$item}; } |
48 | | | |
49 | | | $DB_FILE="./rrd/$DB_FILE.rrd"; |
50 | | | |
51 | | | # if database exists, create images... |
52 | | | if ( -e $DB_FILE) { |
53 | | | |
54 | | | print "creating images for $name ($description) ...\n"; |
55 | | | foreach my $range ("1h","6h","1day","1week","1month","1year") { |
56 | | | my ($descr,$time,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range); |
57 | | | |
58 | | | my $MULT=1; |
59 | | | my $legends="min avg max"; |
60 | | | if ($range eq "1h") { $legends="min avg max cur"; } |
61 | | | my @EXTOPTIONS=("-s","-$range", "--title", "traffic to $name - last $descr ($DATESTRING)"); |
62 | | | my @COMMANDS=("DEF:dbtcpin=$DB_FILE:tcpin:AVERAGE", |
63 | | | "DEF:dbudpin=$DB_FILE:udpin:AVERAGE", |
64 | | | "DEF:dbicmpin=$DB_FILE:icmpin:AVERAGE", |
65 | | | "DEF:dbtcpout=$DB_FILE:tcpout:AVERAGE", |
66 | | | "DEF:dbudpout=$DB_FILE:udpout:AVERAGE", |
67 | | | "DEF:dbicmpout=$DB_FILE:icmpout:AVERAGE"); |
68 | | | if ($MODULECONFIG{GRAPH_BASE} eq "bits") { |
69 | | | push @COMMANDS,("CDEF:tcpin=dbtcpin,8,*", |
70 | | | "CDEF:udpin=dbudpin,8,*", |
71 | | | "CDEF:icmpin=dbicmpin,8,*", |
72 | | | "CDEF:tcpout=dbtcpout,8,*", |
73 | | | "CDEF:udpout=dbudpout,8,*", |
74 | | | "CDEF:icmpout=dbicmpout,8,*"); |
75 | | | } |
76 | | | else { |
77 | | | push @COMMANDS,("CDEF:tcpin=dbtcpin", |
78 | | | "CDEF:udpin=dbudpin", |
79 | | | "CDEF:icmpin=dbicmpin", |
80 | | | "CDEF:tcpout=dbtcpout", |
81 | | | "CDEF:udpout=dbudpout", |
82 | | | "CDEF:icmpout=dbicmpout"); |
83 | | | } |
84 | | | push @COMMANDS,("CDEF:allin=tcpin,udpin,icmpin,+,+", |
85 | | | "CDEF:spanin=allin,$fullrange,*", |
86 | | | "CDEF:tcpout_inv=0,tcpout,-", |
87 | | | "CDEF:udpout_inv=0,udpout,-", |
88 | | | "CDEF:icmpout_inv=0,icmpout,-", |
89 | | | "CDEF:allout=tcpout,udpout,icmpout,+,+", |
90 | | | "CDEF:spanout=allout,$fullrange,*", |
91 | | | HotSaNICdiagram::insert_data("AREA" ,"tcpin" ,$MODULECONFIG{COLOR_IN_TCP} ,"tcp in ",$legends,$LEGEND,1), |
92 | | | HotSaNICdiagram::insert_data("STACK","udpin" ,$MODULECONFIG{COLOR_IN_UDP} ,"udp in ",$legends,$LEGEND,1), |
93 | | | HotSaNICdiagram::insert_data("STACK","icmpin",$MODULECONFIG{COLOR_IN_ICMP},"icmp in ",$legends,$LEGEND,1), |
94 | | | "GPRINT:allin:AVERAGE: total average\\: %6.2lf %s $LEGEND", |
95 | | | "GPRINT:spanin:AVERAGE: - %6.2lf %s ".$MODULECONFIG{GRAPH_BASE}."/$descr\\n", |
96 | | | HotSaNICdiagram::insert_data("AREA" ,"tcpout_inv tcpout" ,$MODULECONFIG{COLOR_OUT_TCP} ,"tcp out",$legends,$LEGEND,1), |
97 | | | HotSaNICdiagram::insert_data("STACK","udpout_inv udpout" ,$MODULECONFIG{COLOR_OUT_UDP} ,"udp out",$legends,$LEGEND,1), |
98 | | | HotSaNICdiagram::insert_data("STACK","icmpout_inv icmpout",$MODULECONFIG{COLOR_OUT_ICMP},"icmp out",$legends,$LEGEND,1), |
99 | | | "GPRINT:allout:AVERAGE: total average\\: %6.2lf %s $LEGEND", |
100 | | | "GPRINT:spanout:AVERAGE: - %6.2lf %s ".$MODULECONFIG{GRAPH_BASE}."/$descr\\n", |
101 | | | HotSaNICdiagram::insert_lines(%MODULECONFIG)); |
102 | | | |
103 | | | my %CONF=(RANGE=>$time,FILENAME=>"$OUTDIR/$file-$time",FORMAT=>$IMGFMT,INTERVAL=>$build,FORCE=>$FORCE,OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],DEBUGLEVEL=>$DEBUGLEVEL,MODNAME=>$MODNAME); |
104 | | | HotSaNICdiagram::graph(%CONF); |
105 | | | } |
106 | | | } |
107 | | | else { print " No database \"$DB_FILE\" found\n Please check if the daemon is running.\n"; } |
108 | | | print "\n"; |
109 | | | } |
110 | | | exit 0; |
111 | | | |
112 | | | |