1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | |
3 | | | # $Id: diagrams.pl,v 1.14 2004/05/23 23:53:37 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.14 $') =~ s/.*(\d+\.\d+).*/$1/; |
18 | | | (my $IDENTIFIER = '$Id: diagrams.pl,v 1.14 2004/05/23 23:53:37 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 | | | push @OPTIONS,("--alt-autoscale-max"); # alternate scaling |
37 | | | |
38 | | | # generate diagrams |
39 | | | # |
40 | | | my $name="usv"; |
41 | | | |
42 | | | my $DB_FILE="./rrd/usv.rrd"; |
43 | | | |
44 | | | # if database exists, create images... |
45 | | | if ( -e $DB_FILE) { |
46 | | | |
47 | | | foreach my $DEV ("loadpct","battpct","outv","battv","timeleft","temp") { |
48 | | | |
49 | | | if (%PLOT) { next if ! defined $PLOT{$DEV}; } |
50 | | | |
51 | | | my $title; |
52 | | | my $LEGEND; |
53 | | | |
54 | | | if ( $DEV eq "loadpct" ) { $title="USV load"; $LEGEND="%"; } |
55 | | | if ( $DEV eq "battpct" ) { $title="battery charge"; $LEGEND="%"; } |
56 | | | if ( $DEV eq "outv" ) { $title="output voltage"; $LEGEND="Volts"; } |
57 | | | if ( $DEV eq "battv" ) { $title="battery voltage"; $LEGEND="Volts"; } |
58 | | | if ( $DEV eq "timeleft" ) { $title="time left"; $LEGEND="minutes"; } |
59 | | | if ( $DEV eq "temp" ) { $title="temperature"; $LEGEND="°C"; } |
60 | | | |
61 | | | my $unit=$LEGEND; |
62 | | | if ($unit eq "%") { $unit="%%"; } |
63 | | | |
64 | | | print "creating images for $DEV ($title) ...\n"; |
65 | | | |
66 | | | foreach my $range ("1h","6h","1day","1week","1month","1year") { |
67 | | | my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range); |
68 | | | |
69 | | | my $legends="min avg max"; |
70 | | | if ($range eq "1h") { $legends="min avg max cur"; } |
71 | | | my @EXTOPTIONS=("-s","-$fullrange", "-v", $LEGEND, "--title", "$title - last $descr ($DATESTRING)"); |
72 | | | my @COMMANDS=("DEF:onbatt=$DB_FILE:onbatt:AVERAGE", |
73 | | | "DEF:replacebatt=$DB_FILE:replacebatt:AVERAGE", |
74 | | | "DEF:valmin=$DB_FILE:$DEV:MIN", |
75 | | | "DEF:valavg=$DB_FILE:$DEV:AVERAGE", |
76 | | | "DEF:valmax=$DB_FILE:$DEV:MAX", |
77 | | | "CDEF:obinf=onbatt,0,GT,inf,0,IF", |
78 | | | "CDEF:obmin=onbatt,0,GT,valmin,0,IF", |
79 | | | "CDEF:rbinf=replacebatt,0,GT,inf,0,IF", |
80 | | | "CDEF:rbmin=replacebatt,0,GT,valmin,0,IF", |
81 | | | "CDEF:or=onbatt,replacebatt,+,10,*", |
82 | | | "CDEF:orinf=or,1,GT,inf,0,IF", |
83 | | | "CDEF:ormin=or,1,GT,valmin,0,IF", |
84 | | | "AREA:obinf#".$MODULECONFIG{COLOR_STATUS_ONBATT}.":on battery\\n", |
85 | | | "AREA:rbinf#".$MODULECONFIG{COLOR_STATUS_REPLACEBATT}.":battery needs replacement\\n", |
86 | | | "AREA:orinf#".$MODULECONFIG{COLOR_STATUS_BOTH}.":both (overlapping)\\n", |
87 | | | "AREA:valmax#".$MODULECONFIG{COLOR_MINMAX}.":min/max", |
88 | | | "LINE1:valmax#".$MODULECONFIG{COLOR_BORDER}.":", |
89 | | | "AREA:valmin#ffffff:", |
90 | | | "AREA:obmin#".$MODULECONFIG{COLOR_STATUS_ONBATT}.":", |
91 | | | "AREA:rbmin#".$MODULECONFIG{COLOR_STATUS_REPLACEBATT}.":", |
92 | | | "AREA:ormin#".$MODULECONFIG{COLOR_STATUS_BOTH}.":", |
93 | | | "LINE1:valmin#".$MODULECONFIG{COLOR_BORDER}.":", |
94 | | | HotSaNICdiagram::insert_data("LINE2" ,"valavg valmin valavg valmax",$MODULECONFIG{COLOR_LINE} ,"avg",$legends,"($unit)",1), |
95 | | | HotSaNICdiagram::insert_lines(%MODULECONFIG)); |
96 | | | |
97 | | | my %CONF=(RANGE=>$descr,FILENAME=>"$OUTDIR/$DEV-$file",FORMAT=>$IMGFMT,INTERVAL=>$build,FORCE=>$FORCE,OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],DEBUGLEVEL=>$DEBUGLEVEL,MODNAME=>$MODNAME); |
98 | | | HotSaNICdiagram::graph(%CONF); |
99 | | | } |
100 | | | print "\n"; |
101 | | | } |
102 | | | } else { print " No database \"$DB_FILE\" found\n Please check if the daemon is running.\n\n"; } |
103 | | | |
104 | | | exit 0; |
105 | | | |