hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/usr/bin/env perl
# $Id: diagrams.pl,v 1.14 2004/05/23 23:53:37 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.14 $') =~ s/.*(\d+\.\d+).*/$1/;
(my $IDENTIFIER = '$Id: diagrams.pl,v 1.14 2004/05/23 23:53:37 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
#
push @OPTIONS,("--alt-autoscale-max"); # alternate scaling
# generate diagrams
#
my $name="usv";
my $DB_FILE="./rrd/usv.rrd";
# if database exists, create images...
if ( -e $DB_FILE) {
foreach my $DEV ("loadpct","battpct","outv","battv","timeleft","temp") {
if (%PLOT) { next if ! defined $PLOT{$DEV}; }
my $title;
my $LEGEND;
if ( $DEV eq "loadpct" ) { $title="USV load"; $LEGEND="%"; }
if ( $DEV eq "battpct" ) { $title="battery charge"; $LEGEND="%"; }
if ( $DEV eq "outv" ) { $title="output voltage"; $LEGEND="Volts"; }
if ( $DEV eq "battv" ) { $title="battery voltage"; $LEGEND="Volts"; }
if ( $DEV eq "timeleft" ) { $title="time left"; $LEGEND="minutes"; }
if ( $DEV eq "temp" ) { $title="temperature"; $LEGEND="°C"; }
my $unit=$LEGEND;
if ($unit eq "%") { $unit="%%"; }
print "creating images for $DEV ($title) ...\n";
foreach my $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","-$fullrange", "-v", $LEGEND, "--title", "$title - last $descr ($DATESTRING)");
my @COMMANDS=("DEF:onbatt=$DB_FILE:onbatt:AVERAGE",
"DEF:replacebatt=$DB_FILE:replacebatt:AVERAGE",
"DEF:valmin=$DB_FILE:$DEV:MIN",
"DEF:valavg=$DB_FILE:$DEV:AVERAGE",
"DEF:valmax=$DB_FILE:$DEV:MAX",
"CDEF:obinf=onbatt,0,GT,inf,0,IF",
"CDEF:obmin=onbatt,0,GT,valmin,0,IF",
"CDEF:rbinf=replacebatt,0,GT,inf,0,IF",
"CDEF:rbmin=replacebatt,0,GT,valmin,0,IF",
"CDEF:or=onbatt,replacebatt,+,10,*",
"CDEF:orinf=or,1,GT,inf,0,IF",
"CDEF:ormin=or,1,GT,valmin,0,IF",
"AREA:obinf#".$MODULECONFIG{COLOR_STATUS_ONBATT}.":on battery\\n",
"AREA:rbinf#".$MODULECONFIG{COLOR_STATUS_REPLACEBATT}.":battery needs replacement\\n",
"AREA:orinf#".$MODULECONFIG{COLOR_STATUS_BOTH}.":both (overlapping)\\n",
"AREA:valmax#".$MODULECONFIG{COLOR_MINMAX}.":min/max",
"LINE1:valmax#".$MODULECONFIG{COLOR_BORDER}.":",
"AREA:valmin#ffffff:",
"AREA:obmin#".$MODULECONFIG{COLOR_STATUS_ONBATT}.":",
"AREA:rbmin#".$MODULECONFIG{COLOR_STATUS_REPLACEBATT}.":",
"AREA:ormin#".$MODULECONFIG{COLOR_STATUS_BOTH}.":",
"LINE1:valmin#".$MODULECONFIG{COLOR_BORDER}.":",
HotSaNICdiagram::insert_data("LINE2" ,"valavg valmin valavg valmax",$MODULECONFIG{COLOR_LINE} ,"avg",$legends,"($unit)",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);
}
print "\n";
}
} else { print " No database \"$DB_FILE\" found\n Please check if the daemon is running.\n\n"; }
exit 0;