jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [apcusv/] [diagrams.pl] - Blame information for rev 36

 

Line No. Rev Author Line
110simandl#!/usr/bin/env perl
2use strict;
3use warnings;
4use diagnostics;
5 
6use lib "../../lib";
7use HotSaNICparser;
8use HotSaNICdiagram;
9use RRDs;
10 
11# read global settings
12#
13my $MODNAME=HotSaNICparser::get_module_name();
14my %CONFIG=HotSaNICparser::get_config("../..");
15 
16my $IMGFMT=lc $CONFIG{"IMAGEFORMAT"};
17 
18my $OUTDIR=$CONFIG{"WEBDIR"}."/".lc $MODNAME;
19if ( ! -e $OUTDIR ) { mkdir $OUTDIR,0755; }
20my $TEMPNAME="$OUTDIR/temp.$IMGFMT";
21 
22my $FORCE=@ARGV;
23 
24# generate diagrams
25#
26 
27my $name="usv";
28 
29# if database exists, create images...
30 if ( -e "./rrd/$name.rrd") {
31 
32 foreach my $DEV ("loadpct","battpct","outv","battv","timeleft","temp") {
33 
34 my $title;
35 my $LEGEND;
36 
37 if ( $DEV eq "loadpct" ) { $title="USV load"; $LEGEND="%"; }
38 if ( $DEV eq "battpct" ) { $title="battery charge"; $LEGEND="%"; }
39 if ( $DEV eq "outv" ) { $title="output voltage"; $LEGEND="Volts"; }
40 if ( $DEV eq "battv" ) { $title="battery voltage"; $LEGEND="Volts"; }
41 if ( $DEV eq "timeleft" ) { $title="time left"; $LEGEND="minutes"; }
42 if ( $DEV eq "temp" ) { $title="temperature"; $LEGEND="°C"; }
43 
44 my $unit=$LEGEND;
45 if ($unit eq "%") { $unit="%%"; }
46 
47 print "creating images for $name ($title) ...\n";
48 
49 foreach my $range ("1h","6h","1day","1week","1month","1year") {
50 my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
51 
52 my $FILENAME="$OUTDIR/$DEV-$file.$IMGFMT";
53 
54 my $make=$FORCE;
55 if ($range eq "1h") { $make++; }
56 elsif (! -e "$FILENAME") { $make++; }
57 else {
58 my (undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime,undef,undef,undef) = stat( "$FILENAME" );
59 if (time > ($mtime+$build)) { $make++; }
60 }
61 
62 if ($make>0) {
63 
64 my ($prints,$xs,$ys);
65 
66 ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b","1024",
67 "-v", $LEGEND, "-s","-$fullrange", "-w",$CONFIG{WIDTH},
68 "-h", $CONFIG{HEIGHT}, "-a", uc($IMGFMT), "-l 0",
69 "--alt-autoscale-max", "--title", "$title - last $descr ($DATESTRING)",
70 "DEF:onbatt=rrd/$name.rrd:onbatt:AVERAGE",
71 "DEF:replacebatt=rrd/$name.rrd:replacebatt:AVERAGE",
72 "DEF:valmin=rrd/$name.rrd:$DEV:MIN",
73 "DEF:valavg=rrd/$name.rrd:$DEV:AVERAGE",
74 "DEF:valmax=rrd/$name.rrd:$DEV:MAX",
75 "CDEF:obinf=onbatt,0,GT,inf,0,IF",
76 "CDEF:obmin=onbatt,0,GT,valmin,0,IF",
77 "CDEF:rbinf=replacebatt,0,GT,inf,0,IF",
78 "CDEF:rbmin=replacebatt,0,GT,valmin,0,IF",
79 "CDEF:or=onbatt,replacebatt,+,10,*",
80 "CDEF:orinf=or,1,GT,inf,0,IF",
81 "CDEF:ormin=or,1,GT,valmin,0,IF",
82 "AREA:obinf#c0c0ff:on battery\\n",
83 "AREA:rbinf#ff8080:battery needs replacement\\n",
84 "AREA:orinf#ff80e0:both (overlapping)\\n",
85 "AREA:valmax#d0ffd0:min/max",
86 "LINE1:valmax#c0c0c0:",
87 "AREA:valmin#ffffff:",
88 "AREA:obmin#c0c0ff:",
89 "AREA:rbmin#ff8080:",
90 "AREA:ormin#ff80e0:",
91 "LINE1:valmin#c0c0c0:",
92 "LINE2:valavg#00a000:avg",
93 "GPRINT:valmin:MIN: min\\:%7.2lf %s",
94 "GPRINT:valavg:AVERAGE: avg\\:%7.2lf %s",
95 "GPRINT:valmax:MAX: max\\:%7.2lf %s ($unit)\\n",
96 "HRULE:0#000000";
97 
98 rename $TEMPNAME,$FILENAME;
99 printf " %-7s %d"."x%d %s\n",$descr,$xs,$ys,$FILENAME;
100 
101 }
102 }
103 }
104 print "\n";
105 }
106 else { print " No database found\n Please check if the daemon is running.\n"; }
107 
108exit 0;
109 

Powered by WebSVN 2.2.1