jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [modules/] [traffic/] [diagrams.pl] - Rev 34 Go to most recent revision

Compare with Previous - Blame - Download


#!/usr/bin/env perl

# $Id: diagrams.pl,v 1.32 2004/06/06 08:39:51 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.32 $') =~ s/.*(\d+\.\d+).*/$1/;
(my $IDENTIFIER = '$Id: diagrams.pl,v 1.32 2004/06/06 08:39:51 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";

# generate diagrams
#
foreach my $entry (@{$MODULECONFIG{DEV}}) {
  my (undef,undef,undef,$DB_FILE,$name,$file,$description,$maxin,$maxout)=HotSaNICmod::common::get_names($entry);

  if (%PLOT) { next if ! defined $PLOT{$name}; }

  $DB_FILE="./rrd/$DB_FILE.rrd";

# if database exists, create images...
  if (-e $DB_FILE) {

    print "creating images for $name ($description) ...\n";
    if ((! defined $maxin) || ($maxin eq "") || ($maxin == 0)) {
      print "  Maximum input speed not set!\n  Please check settings-file!\n  setting speed to 100 MBit\n";
      $maxin=12500000;
      }
    if ((! defined $maxout) || ($maxout eq "") || ($maxout == 0)) {
      print "  Maximum output speed not set!\n  Please check settings-file!\n  setting speed to 100 MBit\n";
      $maxout=12500000;
      }
    if ($MODULECONFIG{GRAPH_BASE} eq "bits") {
      $maxin*=8;
      $maxout*=8;
      }

    foreach my $range ("1h","6h","1day","1week","1month","1year") {
      my ($timelong,$time,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);

# $name =~ s/:/\\:/g;

      my @EXTOPTIONS=("-s", "-$range", "-v","$LEGEND", "--title", "traffic on $name - last $timelong ($DATESTRING)");
      my @COMMANDS;
      if ($MODULECONFIG{GRAPH_BASE} eq "bits") {
        @COMMANDS=("DEF:dbminin=$DB_FILE:in:MIN",
          "DEF:dbmaxin=$DB_FILE:in:MAX",
          "DEF:dbavgin=$DB_FILE:in:AVERAGE",
          "DEF:dbminout=$DB_FILE:out:MIN",
          "DEF:dbmaxout=$DB_FILE:out:MAX",
          "DEF:dbavgout=$DB_FILE:out:AVERAGE",
          "CDEF:minin=dbminin,8,*",
          "CDEF:maxin=dbmaxin,8,*",
          "CDEF:avgin=dbavgin,8,*",
          "CDEF:minout=dbminout,8,*",
          "CDEF:maxout=dbmaxout,8,*",
          "CDEF:avgout=dbavgout,8,*");
        }
      else {
        @COMMANDS=("DEF:minin=$DB_FILE:in:MIN",
          "DEF:maxin=$DB_FILE:in:MAX",
          "DEF:avgin=$DB_FILE:in:AVERAGE",
          "DEF:minout=$DB_FILE:out:MIN",
          "DEF:maxout=$DB_FILE:out:MAX",
          "DEF:avgout=$DB_FILE:out:AVERAGE");
        }
      push @COMMANDS,("CDEF:totin=avgin,$fullrange,*",
        "CDEF:totout=avgout,$fullrange,*",
        "CDEF:pctin=avgin,100,*,$maxin,/",
        "CDEF:pctout=avgout,100,*,$maxout,/",
        HotSaNICdiagram::insert_unknown_area("maxin maxout",$MODULECONFIG{COLOR_WRONGDATA},"device may be down"));
      if ($MODULECONFIG{SWAPIO}==1) {
        push @COMMANDS,("CDEF:minin_draw=minin,-1,*",
          "CDEF:maxin_draw=maxin,-1,*",
          "CDEF:avgin_draw=avgin,-1,*",
          "CDEF:minout_draw=minout",
          "CDEF:maxout_draw=maxout",
          "CDEF:avgout_draw=avgout");
        }
      else {
        push @COMMANDS,("CDEF:minin_draw=minin",
          "CDEF:maxin_draw=maxin",
          "CDEF:avgin_draw=avgin",
          "CDEF:minout_draw=minout,-1,*",
          "CDEF:maxout_draw=maxout,-1,*",
          "CDEF:avgout_draw=avgout,-1,*");
        }
      if ($range eq "1h") {
        push @COMMANDS,(
          "AREA:avgin_draw#".$MODULECONFIG{COLOR_IN_AREA}.":",
          HotSaNICdiagram::insert_data("LINE1","avgin_draw minin avgin maxin"    ,$MODULECONFIG{COLOR_IN_LINE} ,"input ","min avg max cur",$LEGEND,1),
          "AREA:avgout_draw#".$MODULECONFIG{COLOR_OUT_AREA}.":",
          HotSaNICdiagram::insert_data("LINE1","avgout_draw minout avgout maxout",$MODULECONFIG{COLOR_OUT_LINE},"output","min avg max cur",$LEGEND,1),
          "HRULE:$maxin#".$MODULECONFIG{COLOR_MAXSPEED}.":Maximum transmission speed without compression (in\\: $maxin / out\\: $maxout $LEGEND)\\n",
          "HRULE:-$maxout#".$MODULECONFIG{COLOR_MAXSPEED},
          "GPRINT:totin:AVERAGE:  totals for last hour\\:%7.2lf %s ".$MODULECONFIG{GRAPH_BASE},
          "GPRINT:pctin:AVERAGE:(%5.2lf %%) input",
          "GPRINT:totout:AVERAGE: / %7.2lf %s ".$MODULECONFIG{GRAPH_BASE},
          "GPRINT:pctout:AVERAGE:(%5.2lf %%) output\\n"
          );
        }
      else {
        push @COMMANDS,(
          HotSaNICdiagram::insert_minmax("minin_draw maxin_draw minin maxin",$MODULECONFIG{COLOR_IN_MINMAX},$MODULECONFIG{COLOR_BORDER},"min/max in ",$LEGEND,1),
          HotSaNICdiagram::insert_data("LINE2","avgin_draw avgin"  ,$MODULECONFIG{COLOR_IN_LINE} ,"avg in     ","min avg max",$LEGEND,1),
          HotSaNICdiagram::insert_minmax("maxout_draw minout_draw minout maxout",$MODULECONFIG{COLOR_OUT_MINMAX},$MODULECONFIG{COLOR_BORDER},"min/max out",$LEGEND,1),
          HotSaNICdiagram::insert_data("LINE2","avgout_draw avgout",$MODULECONFIG{COLOR_OUT_LINE},"avg out    ","min avg max",$LEGEND,1),
          "HRULE:$maxin#".$MODULECONFIG{COLOR_MAXSPEED}.":Maximum transmission speed without compression (in\\: $maxin / out\\: $maxout $LEGEND)",
          "HRULE:-$maxout#".$MODULECONFIG{COLOR_MAXSPEED},
          "GPRINT:totin:AVERAGE:  totals for last $timelong\\:%7.2lf %s ".$MODULECONFIG{GRAPH_BASE},
          "GPRINT:pctin:AVERAGE:(%5.2lf %%) input",
          "GPRINT:totout:AVERAGE: / %7.2lf %s ".$MODULECONFIG{GRAPH_BASE},
          "GPRINT:pctout:AVERAGE:(%5.2lf %%) output\\n"
          );
        }
      push @COMMANDS,HotSaNICdiagram::insert_lines(%MODULECONFIG);

      my %CONF=(RANGE=>$timelong,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";
  }


Powered by WebSVN 2.2.1