jablonka.czprosek.czf

hotsanic

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

Compare with Previous - Blame - Download


#!/usr/bin/env perl

# $Id: diagrams.pl,v 1.33 2004/09/19 10:07:58 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.33 $') =~ s/.*(\d+\.\d+).*/$1/;
(my $IDENTIFIER = '$Id: diagrams.pl,v 1.33 2004/09/19 10:07:58 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 ($name,$range,$descr);

my @OPTIONS=();

foreach my $section (split /\s+/,uc $MODULECONFIG{SECTIONS}) {

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

  $MODULECONFIG{GRAPH_MIN}=$MODULECONFIG{"GRAPH_MIN.$section"} || 0;
  $MODULECONFIG{GRAPH_MAX}=$MODULECONFIG{"GRAPH_MAX.$section"} || 10;
  $MODULECONFIG{GRAPH_MIN_LOG}=$MODULECONFIG{"GRAPH_MIN_LOG.$section"} || 0.01;
  $MODULECONFIG{GRAPH_RIGID}=$MODULECONFIG{"GRAPH_RIGID.$section"} || 0;
  $MODULECONFIG{GRAPH_STYLE}=$MODULECONFIG{"GRAPH_STYLE.$section"} || "lin";
  $MODULECONFIG{GRAPH_UNIT}=$MODULECONFIG{"GRAPH_UNIT.$section"} || 1000;
  $MODULECONFIG{GRAPH_BASE}=$MODULECONFIG{"GRAPH_BASE.$section"} || "";

  @OPTIONS=HotSaNICdiagram::get_common_options(%MODULECONFIG,%CONFIG);
  push @OPTIONS,"--alt-autoscale-max";   # alternate scaling

  if ($section eq "LOAD")   { plot_load(); }
  if ($section eq "PROC")   { plot_proc(); }
  if ($section eq "CPU")    { plot_cpu(); }
  if ($section eq "MEM")    { plot_mem(); }
  if ($section eq "SWAP")   { plot_swap(); }
  if ($section eq "USERS")  { plot_user(); }
  if ($section eq "IRQ")    { plot_irq(); }
  if ($section eq "UPTIME") { plot_uptime(); }
  }
 
exit 0;


sub plot_load {

  print "creating images for loadavg...\n";

  opendir(DIR,"./rrd");
  my @files=readdir(DIR);
  closedir(DIR);
  my @results=grep /load.*\.rrd/,@files;
  foreach (@results) { s/\.rrd//g; }

  # if database exists, create images...
  if (@results) {
    my $LEGEND="load";
    foreach my $dev (@results) {
      my $DB_FILE="./rrd/$dev.rrd";
      print "  $dev:\n";
      foreach $range ("1h","6h","1day","1week","1month","1year") {
        my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
        my @EXTOPTIONS=("-s","-$range", "-v", $LEGEND, "--title", "system-load - last $descr ($DATESTRING)");
        my @COMMANDS=();

        if ($range eq "1h") {
          @COMMANDS=(
            "DEF:ld1=$DB_FILE:load1:AVERAGE",
            "DEF:ld2=$DB_FILE:load5:AVERAGE",
            "DEF:ld3=$DB_FILE:load15:AVERAGE",
            HotSaNICdiagram::insert_data("AREA","ld1",$MODULECONFIG{COLOR_LOAD_1}," 1 min avg","min max cur"),
            HotSaNICdiagram::insert_data("LINE2","ld2",$MODULECONFIG{COLOR_LOAD_5}," 5 min avg","min max"),
            HotSaNICdiagram::insert_data("LINE2","ld3",$MODULECONFIG{COLOR_LOAD_15},"15 min avg","min max"),
            HotSaNICdiagram::insert_lines(%MODULECONFIG));
          }
        else {
          @COMMANDS=(
            HotSaNICdiagram::insert_vars($DB_FILE,"load1","load","MIN AVERAGE MAX"),
            "DEF:avg5=$DB_FILE:load5:AVERAGE",
            "DEF:avg15=$DB_FILE:load15:AVERAGE",
            HotSaNICdiagram::insert_minmax("load_min load_max",$MODULECONFIG{COLOR_LOAD_AREA_MINMAX},$MODULECONFIG{COLOR_LOAD_BORDER},"min/max","",0),
            "LINE1:load_avg#".$MODULECONFIG{COLOR_LOAD_1}.":avg (1 min)",
            "LINE1:avg5#".$MODULECONFIG{COLOR_LOAD_5}.":avg (5 min)",
            "LINE1:avg15#".$MODULECONFIG{COLOR_LOAD_15}.":avg (15 min)",
            HotSaNICdiagram::insert_lines(%MODULECONFIG));
          }

        my %CONF=(RANGE=>$descr,FILENAME=>"$OUTDIR/$dev-$file",FORMAT=>$IMGFMT,INTERVAL=>$build,FORCE=>$FORCE,OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],DEBUGLEVEL=>$DEBUGLEVEL,MODNAME=>$MODNAME);
        HotSaNICdiagram::graph(%CONF);

        }
      }
    }
  else { print "  No database found\n  Please check if the daemon is running.\n"; }
  print "\n";
  }


sub plot_proc {

  print "creating images for processes...\n";

  opendir(DIR,"./rrd");
  my @files=readdir(DIR);
  closedir(DIR);
  my @results=grep /proc.*\.rrd/,@files;
  foreach (@results) { s/\.rrd//g; }

  # if database exists, create images...
  if (@results) {
    my $LEGEND="processes";
    foreach my $dev (@results) {
      my $DB_FILE="./rrd/$dev.rrd";
      print "  $dev:\n";
      foreach $range ("1h","6h","1day","1week","1month","1year") {
        my $legends="min avg max";
        if($range eq "1h") { $legends="min avg max cur"; }
        my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
        my @EXTOPTIONS=("-s","-$range", "-v", $LEGEND, "--title", "processes - last $descr ($DATESTRING)");
        my @COMMANDS=(
          HotSaNICdiagram::insert_vars($DB_FILE,"procslp","slp","MIN AVERAGE MAX"),
          HotSaNICdiagram::insert_vars($DB_FILE,"procrun","run","MIN AVERAGE MAX"),
          HotSaNICdiagram::insert_vars($DB_FILE,"proczmb","zmb","MIN AVERAGE MAX"),
          HotSaNICdiagram::insert_vars($DB_FILE,"procstp","stp","MIN AVERAGE MAX"),
          HotSaNICdiagram::insert_vars($DB_FILE,"procdsc","dsk","MIN AVERAGE MAX"),
          HotSaNICdiagram::insert_data("AREA" ,"slp_avg slp_min slp_avg slp_max slp_max",$MODULECONFIG{COLOR_PROC_SLEEP} ,"sleeping",$legends,$LEGEND),
          HotSaNICdiagram::insert_data("STACK","dsk_avg dsk_min dsk_avg dsk_max dsk_max",$MODULECONFIG{COLOR_PROC_DISC}  ,"disc    ",$legends,$LEGEND),
          HotSaNICdiagram::insert_data("STACK","run_avg run_min run_avg run_max run_max",$MODULECONFIG{COLOR_PROC_RUN}   ,"running ",$legends,$LEGEND),
          HotSaNICdiagram::insert_data("STACK","zmb_avg zmb_min zmb_avg zmb_max zmb_max",$MODULECONFIG{COLOR_PROC_ZOMBIE},"zombie  ",$legends,$LEGEND),
          HotSaNICdiagram::insert_data("STACK","stp_avg stp_min stp_avg stp_max stp_max",$MODULECONFIG{COLOR_PROC_STOP}  ,"stopped ",$legends,$LEGEND),
          HotSaNICdiagram::insert_lines(%MODULECONFIG));

        my %CONF=(RANGE=>$descr,FILENAME=>"$OUTDIR/$dev-$file",FORMAT=>$IMGFMT,INTERVAL=>$build,FORCE=>$FORCE,OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],DEBUGLEVEL=>$DEBUGLEVEL,MODNAME=>$MODNAME);
        HotSaNICdiagram::graph(%CONF);

        }
      }
    }
  else { print "  No database found\n  Please check if the daemon is running.\n"; }
  print "\n";
  }


sub plot_cpu {
  print "creating images for CPU-usage...\n";

  my $NUMCPU=$MODULECONFIG{NUMCPU} || 1;
  if ($NUMCPU < 1) { $NUMCPU=1; }

  my ($PERCENT,$SIGN,$SIGN1);

  my $LEGEND="usage";

  if ( ($MODULECONFIG{GRAPH_BASE} eq "percent" ) or ($MODULECONFIG{GRAPH_BASE} eq "%" ) ) { $PERCENT="100"; $SIGN=" (%)"; $SIGN1=" %% "; }
  else { $PERCENT="1";   $SIGN="";     $SIGN1=""; }

  opendir(DIR,"./rrd");
  my @files=readdir(DIR);
  closedir(DIR);
  my @results=grep /cpu.*\.rrd/,@files;
  foreach (@results) { s/\.rrd//g; }

  # if database exists, create images...
  if (@results) {
    foreach my $dev (sort @results) {
      my $DB_FILE="./rrd/$dev.rrd";
      print "  $dev:\n";
      foreach $range ("1h","6h","1day","1week","1month","1year") {
        my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
        my $FILENAME="$OUTDIR/$dev-$file.$IMGFMT";
  
        # for multicpu: plot range 0..1 for cpu0, cpu1, ... else range 0...$NUMCPU
        #
        my $NUM=$NUMCPU;
        if ( $dev =~ /[0-9]/ ) { $NUM=1; }

        my @EXTOPTIONS=("-s","-$range", "-v", $LEGEND, "-u", ($NUMCPU*$PERCENT), "--title", "CPU usage - last $descr ($DATESTRING)");
        my @COMMANDS=();

        my $legends="min avg max";
        if ($range eq "1h") { $legends="min avg max cur"; }

        if ( ($^O eq "linux") || ($^O eq "solaris") ) {
          @COMMANDS=(
            "DEF:usrdat=$DB_FILE:cpuusr:AVERAGE",
            "DEF:nicdat=$DB_FILE:cpunic:AVERAGE",
            "DEF:sysdat=$DB_FILE:cpusys:AVERAGE",
            "DEF:idldat=$DB_FILE:cpuidl:AVERAGE",
            "CDEF:usravg=usrdat,$NUM,$PERCENT,*,*",
            "CDEF:nicavg=nicdat,$NUM,$PERCENT,*,*",
            "CDEF:sysavg=sysdat,$NUM,$PERCENT,*,*",
            "CDEF:idlavg=idldat,$NUM,$PERCENT,*,*",
            HotSaNICdiagram::insert_data("AREA" ,"sysavg",$MODULECONFIG{COLOR_CPU_SYSTEM},"system",$legends,$SIGN1),
            HotSaNICdiagram::insert_data("STACK","usravg",$MODULECONFIG{COLOR_CPU_USER}  ,"user  ",$legends,$SIGN1),
            HotSaNICdiagram::insert_data("STACK","nicavg",$MODULECONFIG{COLOR_CPU_NICE}  ,"nice  ",$legends,$SIGN1),
            HotSaNICdiagram::insert_data("STACK","idlavg",$MODULECONFIG{COLOR_CPU_IDLE}  ,"idle  ",$legends,$SIGN1));
          }
        elsif ( ($^O eq "freebsd") || ($^O eq "netbsd")) {
          @COMMANDS=(
            "DEF:usravg=$DB_FILE:cpuusr:AVERAGE",
            "DEF:nicavg=$DB_FILE:cpunic:AVERAGE",
            "DEF:sysavg=$DB_FILE:cpusys:AVERAGE",
            "DEF:idlavg=$DB_FILE:cpuidl:AVERAGE",
            "DEF:intavg=$DB_FILE:cpuint:AVERAGE",
            HotSaNICdiagram::insert_data("AREA" ,"sysavg",$MODULECONFIG{COLOR_CPU_SYSTEM}   ,"system   ",$legends,$SIGN1),
            HotSaNICdiagram::insert_data("STACK","intavg",$MODULECONFIG{COLOR_CPU_INTERRUPT},"interrupt",$legends,$SIGN1),
            HotSaNICdiagram::insert_data("STACK","usravg",$MODULECONFIG{COLOR_CPU_USER}     ,"user     ",$legends,$SIGN1),
            HotSaNICdiagram::insert_data("STACK","nicavg",$MODULECONFIG{COLOR_CPU_NICE}     ,"nice     ",$legends,$SIGN1),
            HotSaNICdiagram::insert_data("STACK","idlavg",$MODULECONFIG{COLOR_CPU_IDLE}     ,"idle     ",$legends,$SIGN1));
          }
        if ( ($fullrange > 600800) and ($MODULECONFIG{CPU_SHOW_MAX} == 1) ) {
          push @COMMANDS,(
            "DEF:usrdx=$DB_FILE:cpuusr:MAX",
            "DEF:nicdx=$DB_FILE:cpunic:MAX",
            "DEF:sysdx=$DB_FILE:cpusys:MAX",
            "CDEF:usrmax=usrdx,$NUM,$PERCENT,*,*",
            "CDEF:nicmax=nicdx,$NUM,$PERCENT,*,*",
            "CDEF:sysmax=sysdx,$NUM,$PERCENT,*,*",
            "LINE1:sysmax#".$MODULECONFIG{COLOR_CPU_SYSTEM_MAX}.":",
            "LINE1:usrmax#".$MODULECONFIG{COLOR_CPU_USER_MAX}.":",
            "LINE1:nicmax#".$MODULECONFIG{COLOR_CPU_NICE_MAX}.":");
          }
        push @COMMANDS,HotSaNICdiagram::insert_lines(%MODULECONFIG);

        my %CONF=(RANGE=>$descr,FILENAME=>"$OUTDIR/$dev-$file",FORMAT=>$IMGFMT,INTERVAL=>$build,FORCE=>$FORCE,OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],DEBUGLEVEL=>$DEBUGLEVEL,MODNAME=>$MODNAME);
        HotSaNICdiagram::graph(%CONF);
        }
      }
    }
  else { print "  No database found\n  Please check if the daemon is running.\n"; }
  print "\n";
  }


sub plot_mem {

  print "creating images for memory-usage...\n";

  opendir(DIR,"./rrd");
  my @files=readdir(DIR);
  closedir(DIR);
  my @results=grep /mem.*\.rrd/,@files;
  foreach (@results) { s/\.rrd//g; }

  # if database exists, create images...
  if (@results) {
    my $LEGEND="bytes";
    foreach my $dev (@results) {
      my $DB_FILE="./rrd/$dev.rrd";
      print "  mem:\n";
      foreach $range ("1h","6h","1day","1week","1month","1year") {
        my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
        my @EXTOPTIONS=("-s","-$range", "-v", $LEGEND, "--title", "memory usage - last $descr ($DATESTRING)");
        my @COMMANDS=();

        my $legends="min avg max";
        if ($range eq "1h") { $legends="min avg max cur"; }
          if ($^O eq "linux") {
            @COMMANDS=(
              "DEF:memfre=$DB_FILE:memfre:AVERAGE",
              "DEF:memshr=$DB_FILE:memshr:AVERAGE",
              "DEF:membuf=$DB_FILE:membuf:AVERAGE",
              "DEF:memcac=$DB_FILE:memcac:AVERAGE",
              HotSaNICdiagram::insert_data("AREA" ,"memcac",$MODULECONFIG{COLOR_MEM_CACHED}  ,"cached  ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memshr",$MODULECONFIG{COLOR_MEM_SHARED}  ,"shared  ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","membuf",$MODULECONFIG{COLOR_MEM_BUFFERED},"buffered",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memfre",$MODULECONFIG{COLOR_MEM_FREE}    ,"free    ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_lines(%MODULECONFIG));
            }
          if ($^O eq "solaris") {
            @COMMANDS=(
              "DEF:memfre=$DB_FILE:memfre:AVERAGE",
              "DEF:memshr=$DB_FILE:memshr:AVERAGE",
              HotSaNICdiagram::insert_data("AREA" ,"memshr",$MODULECONFIG{COLOR_MEM_USED},"used",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memfre",$MODULECONFIG{COLOR_MEM_FREE},"free",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_lines(%MODULECONFIG));
            }
          elsif ($^O eq "freebsd") {
            @COMMANDS=(
              "DEF:memfree=$DB_FILE:memfree:AVERAGE",
              "DEF:memwire=$DB_FILE:memwire:AVERAGE",
              "DEF:memactv=$DB_FILE:memactv:AVERAGE",
              "DEF:meminac=$DB_FILE:meminac:AVERAGE",
              "DEF:memcach=$DB_FILE:memcach:AVERAGE",
              HotSaNICdiagram::insert_data("AREA" ,"memwire",$MODULECONFIG{COLOR_MEM_WIRED}   ,"wired   ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memactv",$MODULECONFIG{COLOR_MEM_ACTIVE}  ,"active  ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memcach",$MODULECONFIG{COLOR_MEM_CACHED}  ,"cached  ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","meminac",$MODULECONFIG{COLOR_MEM_INACTIVE},"inactive",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memfree",$MODULECONFIG{COLOR_MEM_FREE}    ,"free    ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_lines(%MODULECONFIG));
            }
          elsif ($^O eq "netbsd") {
            @COMMANDS=(
              "DEF:memfree=$DB_FILE:memfree:AVERAGE",
              "DEF:meminac=$DB_FILE:meminac:AVERAGE",
              "DEF:memactv=$DB_FILE:memactv:AVERAGE",
              "DEF:memwire=$DB_FILE:memwire:AVERAGE",
              "DEF:memcach=$DB_FILE:memcach:AVERAGE",
              HotSaNICdiagram::insert_data("AREA" ,"memcach",$MODULECONFIG{COLOR_MEM_NBSD_CACHED}  ,"cached  ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memwire",$MODULECONFIG{COLOR_MEM_NBSD_WIRED}   ,"wired   ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memactv",$MODULECONFIG{COLOR_MEM_ACTIVE}       ,"active  ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","meminac",$MODULECONFIG{COLOR_MEM_NBSD_INACTIVE},"inactive",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memfree",$MODULECONFIG{COLOR_MEM_NBSD_FREE}    ,"free    ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_lines(%MODULECONFIG));
            }
          elsif ($^O eq "darwin") {
            @COMMANDS=(
              "DEF:memfree=$DB_FILE:memfree:AVERAGE",
              "DEF:memwire=$DB_FILE:memwire:AVERAGE",
              "DEF:memactv=$DB_FILE:memactv:AVERAGE",
              "DEF:meminac=$DB_FILE:meminac:AVERAGE",
              HotSaNICdiagram::insert_data("AREA" ,"memwire",$MODULECONFIG{COLOR_MEM_WIRED}   ,"wired   ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memactv",$MODULECONFIG{COLOR_MEM_ACTIVE}  ,"active  ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","meminac",$MODULECONFIG{COLOR_MEM_INACTIVE},"inactive",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_data("STACK","memfree",$MODULECONFIG{COLOR_MEM_FREE}    ,"free    ",$legends,$LEGEND,1),
              HotSaNICdiagram::insert_lines(%MODULECONFIG));
            }

        my %CONF=(RANGE=>$descr,FILENAME=>"$OUTDIR/$dev-$file",FORMAT=>$IMGFMT,INTERVAL=>$build,FORCE=>$FORCE,OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],DEBUGLEVEL=>$DEBUGLEVEL,MODNAME=>$MODNAME);
        HotSaNICdiagram::graph(%CONF);

        }
      }
    }
  else { print "  No database found\n  Please check if the daemon is running.\n"; }
  print "\n";
  }


sub plot_swap {

  print "creating images for swapfile-usage...\n";

  opendir(DIR,"./rrd");
  my @files=readdir(DIR);
  closedir(DIR);
  my @results=grep /mem.*\.rrd/,@files;
  foreach (@results) { s/\.rrd//g; }

  my $LEGEND="bytes";

  # if database exists, create images...
  if (@results) {
    foreach my $dev (@results) {
      my $DB_FILE="./rrd/$dev.rrd";
      print "  swap:\n";
      foreach $range ("1h","6h","1day","1week","1month","1year") {
        my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
        (my $dev1=$dev) =~ s/^mem/swap/g;

        my $legends="min avg max";
        if ($range eq "1h") { $legends="min avg max cur"; }

        my @EXTOPTIONS=("-s","-$range", "-v", $LEGEND, "--title", "swapfile usage - last $descr ($DATESTRING)");
        my @COMMANDS=(
          "DEF:swpfre=$DB_FILE:swpfre:AVERAGE",
          "DEF:swpuse=$DB_FILE:swpuse:AVERAGE",
          "DEF:maxswpuse=$DB_FILE:swpuse:MAX",
          HotSaNICdiagram::insert_data("AREA" ,"swpuse"   ,$MODULECONFIG{COLOR_SWAP_USED}    ,"used    ",$legends,$LEGEND,1),
          HotSaNICdiagram::insert_data("STACK","swpfre"   ,$MODULECONFIG{COLOR_SWAP_FREE}    ,"free    ",$legends,$LEGEND,1),
          HotSaNICdiagram::insert_data("LINE1","maxswpuse",$MODULECONFIG{COLOR_SWAP_USED_MAX},"max used",$legends,$LEGEND,1),
          HotSaNICdiagram::insert_lines(%MODULECONFIG));

        my %CONF=(RANGE=>$descr,FILENAME=>"$OUTDIR/$dev1-$file",FORMAT=>$IMGFMT,INTERVAL=>$build,FORCE=>$FORCE,OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],DEBUGLEVEL=>$DEBUGLEVEL,MODNAME=>$MODNAME);
        HotSaNICdiagram::graph(%CONF);

        }
      }
    }
  else { print "  No database found\n  Please check if the daemon is running.\n"; }
  print "\n";
  }


sub plot_user {

  print "creating images for user-stats...\n";

  opendir(DIR,"./rrd");
  my @files=readdir(DIR);
  closedir(DIR);
  my @results=grep /users.*\.rrd/,@files;
  foreach (@results) { s/\.rrd//g; }

  # if database exists, create images...
  if (@results) {
    my $LEGEND="users";
    foreach my $dev (@results) {
      my $DB_FILE="./rrd/$dev.rrd";
      print "  $dev:\n";
      foreach $range ("1h","6h","1day","1week","1month","1year") {
        my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
  
        my $legends="min avg max";
        if($range eq "1h") { $legends="min avg max cur"; }

        my @EXTOPTIONS=("-s","-$range", "-v", $LEGEND, "--title", "users - last $descr ($DATESTRING)");
        my @COMMANDS=(
          HotSaNICdiagram::insert_vars($DB_FILE,"tty","tty","MIN AVERAGE MAX"),
          HotSaNICdiagram::insert_vars($DB_FILE,"pty","pty","MIN AVERAGE MAX"),
          HotSaNICdiagram::insert_vars($DB_FILE,"pts","pts","MIN AVERAGE MAX"),
          HotSaNICdiagram::insert_data("AREA" ,"tty_avg tty_min tty_avg tty_max",$MODULECONFIG{COLOR_USERS_TTY},"tty users",$legends,$LEGEND,1),
          HotSaNICdiagram::insert_data("STACK","pty_avg pty_min pty_avg pty_max",$MODULECONFIG{COLOR_USERS_PTY},"pty users",$legends,$LEGEND,1),
          HotSaNICdiagram::insert_data("STACK","pts_avg pts_min pts_avg pts_max",$MODULECONFIG{COLOR_USERS_PTS},"pts users",$legends,$LEGEND,1));
        if ($MODULECONFIG{USERS_SHOW_TOTAL} == 1) {
          push @COMMANDS,("CDEF:tot_avg=tty_avg,pty_avg,pts_avg,+,+",
            "CDEF:tot_max=tty_max,pty_max,pts_max,+,+",
            HotSaNICdiagram::insert_data("LINE1","tot_max",$MODULECONFIG{COLOR_USERS_TOTAL_MAX},"total max",$legends,$LEGEND,1),
            HotSaNICdiagram::insert_data("LINE1","tot_avg",$MODULECONFIG{COLOR_USERS_TOTAL}    ,"total avg",$legends,$LEGEND,1));
          }
        push @COMMANDS,HotSaNICdiagram::insert_lines(%MODULECONFIG);

        my %CONF=(RANGE=>$descr,FILENAME=>"$OUTDIR/$dev-$file",FORMAT=>$IMGFMT,INTERVAL=>$build,FORCE=>$FORCE,OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],DEBUGLEVEL=>$DEBUGLEVEL,MODNAME=>$MODNAME);
        HotSaNICdiagram::graph(%CONF);


        }
      }
    }
  else { print "  No database found\n  Please check if the daemon is running.\n"; }
  print "\n";
  }


sub plot_irq {

  print "creating images for interrupts...\n";

  my @ITEMS=("(?)","(?)","(?)","(?)","(?)","(?)","(?)","(?)","(?)","(?)","(?)","(?)","(?)","(?)","(?)","(?)");

  foreach (@{$MODULECONFIG{IRQ}}) {
    my ($num,$descr)=split /,/;
    if ( (!defined $descr) or ($descr eq "") ) { $descr="(?)"; }
    else { $ITEMS[$num]=substr("(".substr($descr,0,5).")          ",0,7); }
    }

  my $dev="irq";
  my $LEGEND="$dev/s";
  my $DB_FILE="./rrd/$dev.rrd";

  # if database exists, create images...
  if ( -e $DB_FILE) {
    foreach $range ("1h","6h","1day","1week","1month","1year") {
      my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
      my $legends="min avg max";
      if($range eq "1h") { $legends="min avg max cur"; }
      my @EXTOPTIONS=("-s","-$range", "-v", $LEGEND, "--title", "total IRQ/s - last $descr ($DATESTRING)");
      my @COMMANDS=(
        HotSaNICdiagram::insert_vars($DB_FILE,"irqall","irqall","MIN AVERAGE MAX"),
        "DEF:irqa00=$DB_FILE:irq00:AVERAGE",
        "DEF:irqa01=$DB_FILE:irq01:AVERAGE",
        "DEF:irqa02=$DB_FILE:irq02:AVERAGE",
        "DEF:irqa03=$DB_FILE:irq03:AVERAGE",
        "DEF:irqa04=$DB_FILE:irq04:AVERAGE",
        "DEF:irqa05=$DB_FILE:irq05:AVERAGE",
        "DEF:irqa06=$DB_FILE:irq06:AVERAGE",
        "DEF:irqa07=$DB_FILE:irq07:AVERAGE",
        "DEF:irqa08=$DB_FILE:irq08:AVERAGE",
        "DEF:irqa09=$DB_FILE:irq09:AVERAGE",
        "DEF:irqa10=$DB_FILE:irq10:AVERAGE",
        "DEF:irqa11=$DB_FILE:irq11:AVERAGE",
        "DEF:irqa12=$DB_FILE:irq12:AVERAGE",
        "DEF:irqa13=$DB_FILE:irq13:AVERAGE",
        "DEF:irqa14=$DB_FILE:irq14:AVERAGE",
        "DEF:irqa15=$DB_FILE:irq15:AVERAGE",
        HotSaNICdiagram::insert_data("AREA","irqall_max irqall_min irqall_avg irqall_max",$MODULECONFIG{COLOR_INT_AREA},"total",$legends,$LEGEND,1),
        "AREA:irqall_min#ffffff:\\g",
        "LINE1:irqall_max#".$MODULECONFIG{COLOR_INT_ALL_MAX}.":",
        "LINE1:irqall_min#".$MODULECONFIG{COLOR_INT_ALL_MIN}.":",
        "LINE1:irqall_avg#".$MODULECONFIG{COLOR_INT_ALL_AVG}.":",
        "COMMENT:Averages (min/max):\\n");
      for (my $int=0;$int<16;$int++) {
        my $intnum=$int;
        if ($int<10) { $intnum="0$int"; }
        
        push @COMMANDS,("LINE2:irqa$intnum#".$MODULECONFIG{"COLOR_INT_$intnum"}.":$intnum".$ITEMS[$int],
          "GPRINT:irqa$intnum:MIN:%5.1lf%s/\\g",
          "GPRINT:irqa$intnum:MAX:%5.1lf%s");
        }
      push @COMMANDS,HotSaNICdiagram::insert_lines(%MODULECONFIG);
        
      my %CONF=(RANGE=>$descr,FILENAME=>"$OUTDIR/$dev-$file",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";
  }

sub plot_uptime {

  print "creating images for uptime...\n";

  opendir(DIR,"./rrd");
  my @files=readdir(DIR);
  closedir(DIR);
  my @results=grep /uptime.*\.rrd/,@files;
  foreach (@results) { s/\.rrd//g; }

  # if database exists, create images...
  if (@results) {
    my $LEGEND="days";
    foreach my $dev (@results) {
      my $DB_FILE="./rrd/$dev.rrd";
      print "  $dev:\n";
      foreach $range ("1h", "6h", "1day","1week","1month","1year") {
        my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
        my @EXTOPTIONS=("-s","-$range", "-v", $LEGEND, "--title", "system-uptime - last $descr ($DATESTRING)");
        my @COMMANDS=(
          "DEF:up=$DB_FILE:up:AVERAGE",
          "DEF:idle=$DB_FILE:idle:AVERAGE",
          "AREA:up#".$MODULECONFIG{COLOR_UPTIME}.":uptime",
          "GPRINT:up:MAX:(%1.2lf $LEGEND)\\n",
          "AREA:idle#".$MODULECONFIG{COLOR_UPTIME_IDLE}.":idle time",
          "GPRINT:idle:MAX:(%1.2lf $LEGEND)\\n",
          HotSaNICdiagram::insert_lines(%MODULECONFIG));

        my %CONF=(RANGE=>$descr,FILENAME=>"$OUTDIR/$dev-$file",FORMAT=>$IMGFMT,INTERVAL=>$build,FORCE=>$FORCE,OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],DEBUGLEVEL=>$DEBUGLEVEL,MODNAME=>$MODNAME);
        HotSaNICdiagram::graph(%CONF);
        }
      }
    }
  else { print "  No database found\n  Please check if the daemon is running.\n"; }
  print "\n";
  }

Powered by WebSVN 2.2.1