hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/usr/bin/env perl
# $Id: diagrams.pl,v 1.17 2004/05/26 18:21:13 bernisys Exp $
# include PERL libraries
use strict;
use warnings;
use diagnostics;
# include HotSaNIC libraries
use lib "../../lib";
use lib "./platform";
use HotSaNICparser;
use HotSaNICdiagram;
use common;
(my $VERSION = '$Revision: 1.17 $') =~ s/.*(\d+\.\d+).*/$1/;
(my $IDENTIFIER = '$Id: diagrams.pl,v 1.17 2004/05/26 18:21:13 bernisys Exp $') =~ s/.*,v (.*) \$/$1/;
# read all settings
#
my $MODNAME=HotSaNICparser::get_module_name();
my %CONFIG=HotSaNICparser::get_config("../..");
my %MODULECONFIG=HotSaNICmod::common::configure();
my $IMGFMT=lc $CONFIG{"IMAGEFORMAT"};
my $OUTDIR=$CONFIG{"WEBDIR"}."/".lc $MODNAME;
if ( ! -e $OUTDIR ) { mkdir $OUTDIR,0755; }
my ($FORCE,$DEBUGLEVEL,%PLOT)=HotSaNICdiagram::check_args(@ARGV);
my @OPTIONS=HotSaNICdiagram::get_common_options(%MODULECONFIG,%CONFIG);
# handle module-specific stuff
#
my $LEGEND=$MODULECONFIG{GRAPH_BASE}."/s";
push @OPTIONS,(
"-v",$LEGEND, # Y-legend
"--alt-autoscale", # alternate scaling
"-a",uc($IMGFMT)); # image format
# generate diagrams
#
foreach my $entry (@{$MODULECONFIG{DEV}}) {
my (undef,undef,$item,$DB_FILE,$name,$file,$description)=HotSaNICmod::common::get_names($entry);
if (%PLOT) { next if ! defined $PLOT{$item}; }
$DB_FILE="./rrd/$DB_FILE.rrd";
# if database exists, create images...
if ( -e $DB_FILE) {
print "creating images for $name ($description) ...\n";
foreach my $range ("1h","6h","1day","1week","1month","1year") {
my ($descr,$time,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
my $MULT=1;
my $legends="min avg max";
if ($range eq "1h") { $legends="min avg max cur"; }
my @EXTOPTIONS=("-s","-$range", "--title", "traffic to $name - last $descr ($DATESTRING)");
my @COMMANDS=("DEF:dbtcpin=$DB_FILE:tcpin:AVERAGE",
"DEF:dbudpin=$DB_FILE:udpin:AVERAGE",
"DEF:dbicmpin=$DB_FILE:icmpin:AVERAGE",
"DEF:dbtcpout=$DB_FILE:tcpout:AVERAGE",
"DEF:dbudpout=$DB_FILE:udpout:AVERAGE",
"DEF:dbicmpout=$DB_FILE:icmpout:AVERAGE");
if ($MODULECONFIG{GRAPH_BASE} eq "bits") {
push @COMMANDS,("CDEF:tcpin=dbtcpin,8,*",
"CDEF:udpin=dbudpin,8,*",
"CDEF:icmpin=dbicmpin,8,*",
"CDEF:tcpout=dbtcpout,8,*",
"CDEF:udpout=dbudpout,8,*",
"CDEF:icmpout=dbicmpout,8,*");
}
else {
push @COMMANDS,("CDEF:tcpin=dbtcpin",
"CDEF:udpin=dbudpin",
"CDEF:icmpin=dbicmpin",
"CDEF:tcpout=dbtcpout",
"CDEF:udpout=dbudpout",
"CDEF:icmpout=dbicmpout");
}
push @COMMANDS,("CDEF:allin=tcpin,udpin,icmpin,+,+",
"CDEF:spanin=allin,$fullrange,*",
"CDEF:tcpout_inv=0,tcpout,-",
"CDEF:udpout_inv=0,udpout,-",
"CDEF:icmpout_inv=0,icmpout,-",
"CDEF:allout=tcpout,udpout,icmpout,+,+",
"CDEF:spanout=allout,$fullrange,*",
HotSaNICdiagram::insert_data("AREA" ,"tcpin" ,$MODULECONFIG{COLOR_IN_TCP} ,"tcp in ",$legends,$LEGEND,1),
HotSaNICdiagram::insert_data("STACK","udpin" ,$MODULECONFIG{COLOR_IN_UDP} ,"udp in ",$legends,$LEGEND,1),
HotSaNICdiagram::insert_data("STACK","icmpin",$MODULECONFIG{COLOR_IN_ICMP},"icmp in ",$legends,$LEGEND,1),
"GPRINT:allin:AVERAGE: total average\\: %6.2lf %s $LEGEND",
"GPRINT:spanin:AVERAGE: - %6.2lf %s ".$MODULECONFIG{GRAPH_BASE}."/$descr\\n",
HotSaNICdiagram::insert_data("AREA" ,"tcpout_inv tcpout" ,$MODULECONFIG{COLOR_OUT_TCP} ,"tcp out",$legends,$LEGEND,1),
HotSaNICdiagram::insert_data("STACK","udpout_inv udpout" ,$MODULECONFIG{COLOR_OUT_UDP} ,"udp out",$legends,$LEGEND,1),
HotSaNICdiagram::insert_data("STACK","icmpout_inv icmpout",$MODULECONFIG{COLOR_OUT_ICMP},"icmp out",$legends,$LEGEND,1),
"GPRINT:allout:AVERAGE: total average\\: %6.2lf %s $LEGEND",
"GPRINT:spanout:AVERAGE: - %6.2lf %s ".$MODULECONFIG{GRAPH_BASE}."/$descr\\n",
HotSaNICdiagram::insert_lines(%MODULECONFIG));
my %CONF=(RANGE=>$time,FILENAME=>"$OUTDIR/$file-$time",FORMAT=>$IMGFMT,INTERVAL=>$build,FORCE=>$FORCE,OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],DEBUGLEVEL=>$DEBUGLEVEL,MODNAME=>$MODNAME);
HotSaNICdiagram::graph(%CONF);
}
}
else { print " No database \"$DB_FILE\" found\n Please check if the daemon is running.\n"; }
print "\n";
}
exit 0;