jablonka.czprosek.czf

hotsanic

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

 

Line No. Rev Author Line
11simandl#!/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 $OUTDIR=$CONFIG{"WEBDIR"}."/".lc $MODNAME;
17if ( ! -e $OUTDIR ) { mkdir $OUTDIR,0755; }
18 
19my $IMGFMT=lc $CONFIG{"IMAGEFORMAT"};
20my $TEMPNAME="$OUTDIR/temp.$IMGFMT";
21 
22my (@ITEMS,$name,$range,$descr);
23 
24my $FORCE=@ARGV;
25 
26# read module-specific settings
27#
28foreach (HotSaNICparser::read_settings(".")) {
29 my ($var,$value)=HotSaNICparser::parse_line($_);
30 if ($var eq "SENSOR") { push @ITEMS,$value; }
31 }
32 
33# generate diagrams
34#
35foreach (@ITEMS) {
36 my (undef,$dev,$description,undef,undef,undef,$LEGEND)=split /,/;
37 my $name=$dev;
38 
39# if database exists, create images...
40 if ( -e "./rrd/$dev.rrd") {
41 print "creating images for $description...\n";
42 
43 foreach $range ("1h","6h","1day","1week","1month","1year") {
44 my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
45 
46 my $FILENAME="$OUTDIR/$name-$file.$IMGFMT";
47 
48 my $make=$FORCE;
49 if ($range eq "1h") { $make++; }
50 elsif (! -e "$FILENAME") { $make++; }
51 else {
52 my (undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime,undef,undef,undef) = stat( "$FILENAME" );
53 if (time > ($mtime+$build)) { $make++; }
54 }
55 
56 if ($make>0) {
57 
58 my ($prints,$xs,$ys);
59 
60 if ($range eq "1h") {
61 ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b","1024", "-v",$LEGEND,
62 "-s","-$range", "-w",$CONFIG{"WIDTH"}, "-h",$CONFIG{"HEIGHT"}, "-a", uc($IMGFMT),
63 "-l 0", "--alt-autoscale-max", "--title", "$description - last $descr ($DATESTRING)",
64 "DEF:avg=rrd/$dev.rrd:data:AVERAGE",
65 "AREA:avg#d0d0d0:",
66 "LINE1:avg#00a000: ",
67 "GPRINT:avg:AVERAGE:avg\\:%1.2lf %s $LEGEND",
68 "GPRINT:avg:MAX:max\\:%1.2lf %s $LEGEND\\n",
69 "HRULE:0#000000";
70 }
71 else {
72 ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b","1024", "-v",$LEGEND,
73 "-s","-$range", "-w",$CONFIG{"WIDTH"}, "-h",$CONFIG{"HEIGHT"}, "-a", uc($IMGFMT),
74 "--alt-autoscale", "--alt-y-grid", "--title", "$description - last $descr ($DATESTRING)",
75 "DEF:avg=rrd/$dev.rrd:data:AVERAGE",
76 "DEF:max=rrd/$dev.rrd:data:MAX",
77 "DEF:min=rrd/$dev.rrd:data:MIN",
78 "AREA:max#c0ffc0:min/max",
79 "LINE1:max#a0a0a0:",
80 "AREA:min#ffffff:",
81 "LINE1:min#a0a0a0:",
82 "GPRINT:min:MIN:(min\\:%1.2lf %s",
83 "GPRINT:max:MAX:max\\:%1.2lf %s $LEGEND)",
84 "LINE2:avg#00a000:avg",
85 "GPRINT:avg:MIN:(min\\:%1.2lf %s",
86 "GPRINT:avg:AVERAGE:avg\\:%1.2lf %s",
87 "GPRINT:avg:MAX:max\\:%1.2lf %s $LEGEND)\\n",
88 "HRULE:0#000000";
89 }
90 
91 rename $TEMPNAME,$FILENAME;
92 printf " %-7s %d"."x%d %s\n",$descr,$xs,$ys,$FILENAME;
93 }
94 }
95 }
96 else { print " No database found\n Please check if the daemon is running.\n";next; }
97 print "\n";
98 }
99exit 0;
100 
101 

Powered by WebSVN 2.2.1