jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-jablonecka/] [modules/] [ping/] [diagrams.pl] - Blame information for rev 10

 

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 $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;
23my $TYPE;
24undef my @ITEMS;
25undef my @OPTIONS;
26 
27# read module-specific settings
28#
29my $LOWBORDER=0;
30my $UPPERBORDER=10;
31foreach (HotSaNICparser::read_settings(".")) {
32 my ($var,$value)=HotSaNICparser::parse_line($_);
33 if ($var eq "HOST") { push @ITEMS,$value; }
34 if ($var eq "SCALE") { if($value ne "lin") { push @OPTIONS,"-o"; $LOWBORDER=0.0001; } }
35 if ($var eq "TYPE") { $TYPE=$value; }
36 if ($var eq "UPPER") { $UPPERBORDER=$value; }
37 }
38 
39$UPPERBORDER/=1000;
40 
41my $LEGEND="sec.";
42 
43# generate diagrams
44#
45foreach (@ITEMS) {
46 my ($dev,$description)=split /,/;
47 
48 my $name=$dev;
49 
50# if database exists, create images...
51 if ( -e "./rrd/$name.rrd") {
52 print "creating images for $dev ($description) ...\n";
53 
54 foreach my $range ("1h","6h","1day","1week","1month","1year") {
55 my ($descr,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
56 
57 my $FILENAME="$OUTDIR/$name-$file.$IMGFMT";
58 
59 my $make=$FORCE;
60 if ($range eq "1h") { $make++; }
61 elsif (! -e "$FILENAME") { $make++; }
62 else {
63 my (undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime,undef,undef,undef) = stat( "$FILENAME" );
64 if (time > ($mtime+$build)) { $make++; }
65 }
66 
67 if ($make>0) {
68 
69 my ($prints,$xs,$ys);
70 
71 if ($range eq "1h") {
72 ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b","1000", "-v",$LEGEND,
73 "-s","-$fullrange", "-w",$CONFIG{WIDTH}, "-h",$CONFIG{HEIGHT}, @OPTIONS, "-a", uc($IMGFMT),
74 "-u $UPPERBORDER", "-l $LOWBORDER", "--title", "ping-times to $dev - last $descr ($DATESTRING)",
75 "DEF:min=rrd/$dev.rrd:min:AVERAGE",
76 "DEF:avg=rrd/$dev.rrd:avg:AVERAGE",
77 "DEF:max=rrd/$dev.rrd:max:AVERAGE",
78 "CDEF:wrong=max,0,EQ,INF,UNKN,IF",
79 "AREA:max#a0a0ff:min/max",
80 "GPRINT:min:MIN: (%6.2lf%s /\\g",
81 "GPRINT:max:MAX: %6.2lf%s $LEGEND)\\n",
82 "LINE1:max#c00000:max",
83 "GPRINT:max:MIN: (min\\:%6.2lf%s /\\g",
84 "GPRINT:max:AVERAGE: avg\\:%6.2lf%s /\\g",
85 "GPRINT:max:MAX: max\\:%6.2lf%s $LEGEND)\\n:",
86 "AREA:min#ffffff:",
87 "LINE1:avg#000000:avg",
88 "GPRINT:avg:MIN: (min\\:%6.2lf%s /\\g",
89 "GPRINT:avg:AVERAGE: avg\\:%6.2lf%s /\\g",
90 "GPRINT:avg:MAX: max\\:%6.2lf%s $LEGEND)\\n:",
91 "LINE1:min#00c000:min",
92 "GPRINT:min:MIN: (min\\:%6.2lf%s /\\g",
93 "GPRINT:min:AVERAGE: avg\\:%6.2lf%s /\\g",
94 "GPRINT:min:MAX: max\\:%6.2lf%s $LEGEND)\\n:",
95 "AREA:wrong#ffffa0:unreachable",
96 "HRULE:0#000000";
97 }
98 else {
99 if ($TYPE eq "simple") {
100 ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b","1000", "-v",$LEGEND,
101 "-s","-$fullrange", "-w",$CONFIG{WIDTH}, "-h",$CONFIG{HEIGHT}, @OPTIONS, "-a", uc($IMGFMT),
102 "-u $UPPERBORDER", "-l $LOWBORDER", "--title", "ping-times to $dev - last $descr ($DATESTRING)",
103 "DEF:mini=rrd/$dev.rrd:min:MIN",
104 "DEF:mina=rrd/$dev.rrd:min:AVERAGE",
105 "DEF:minx=rrd/$dev.rrd:min:MAX",
106 "DEF:avgi=rrd/$dev.rrd:avg:MIN",
107 "DEF:avga=rrd/$dev.rrd:avg:AVERAGE",
108 "DEF:avgx=rrd/$dev.rrd:avg:MAX",
109 "DEF:maxi=rrd/$dev.rrd:max:MIN",
110 "DEF:maxa=rrd/$dev.rrd:max:AVERAGE",
111 "DEF:maxx=rrd/$dev.rrd:max:MAX",
112 "CDEF:wrong=maxx,0,EQ,INF,UNKN,IF",
113 "AREA:maxx#c0c0ff:",
114 "AREA:mini#ffffff:",
115 "LINE1:maxx#c00000:max",
116 "GPRINT:maxi:MIN: (min\\:%6.2lf%s /\\g",
117 "GPRINT:maxa:AVERAGE: avg\\:%6.2lf%s /\\g",
118 "GPRINT:maxx:MAX: max\\:%6.2lf%s $LEGEND)\\n:",
119 "LINE1:avga#000000:avg",
120 "GPRINT:avgi:MIN: (min\\:%6.2lf%s /\\g",
121 "GPRINT:avga:AVERAGE: avg\\:%6.2lf%s /\\g",
122 "GPRINT:avgx:MAX: max\\:%6.2lf%s $LEGEND)\\n:",
123 "LINE1:mini#00c000:min",
124 "GPRINT:mini:MIN: (min\\:%6.2lf%s /\\g",
125 "GPRINT:mina:AVERAGE: avg\\:%6.2lf%s /\\g",
126 "GPRINT:minx:MAX: max\\:%6.2lf%s $LEGEND)\\n:",
127 "AREA:wrong#ffffa0:unreachable",
128 "HRULE:0#000000";
129 }
130 else {
131 ($prints,$xs,$ys)=RRDs::graph $TEMPNAME, "-i", "-b","1000", "-v",$LEGEND,
132 "-s","-$fullrange", "-w",$CONFIG{WIDTH}, "-h",$CONFIG{HEIGHT}, @OPTIONS, "-a", uc($IMGFMT),
133 "-u $UPPERBORDER", "-l $LOWBORDER", "--title", "ping-times to $dev - last $descr ($DATESTRING)",
134 "DEF:mini=rrd/$dev.rrd:min:MIN",
135 "DEF:mina=rrd/$dev.rrd:min:AVERAGE",
136 "DEF:minx=rrd/$dev.rrd:min:MAX",
137 "DEF:avgi=rrd/$dev.rrd:avg:MIN",
138 "DEF:avga=rrd/$dev.rrd:avg:AVERAGE",
139 "DEF:avgx=rrd/$dev.rrd:avg:MAX",
140 "DEF:maxi=rrd/$dev.rrd:max:MIN",
141 "DEF:maxa=rrd/$dev.rrd:max:AVERAGE",
142 "DEF:maxx=rrd/$dev.rrd:max:MAX",
143 "CDEF:wrong=maxx,0,EQ,INF,UNKN,IF",
144 "AREA:maxx#ffc0c0:max",
145 "GPRINT:maxi:MIN: (min\\:%6.2lf%s /\\g",
146 "GPRINT:maxa:AVERAGE: avg\\:%6.2lf%s /\\g",
147 "GPRINT:maxx:MAX: max\\:%6.2lf%s $LEGEND)\\n:",
148 "AREA:maxi#ffffff:",
149 "AREA:avgx#c0c0ff:avg",
150 "GPRINT:avgi:MIN: (min\\:%6.2lf%s /\\g",
151 "GPRINT:avga:AVERAGE: avg\\:%6.2lf%s /\\g",
152 "GPRINT:avgx:MAX: max\\:%6.2lf%s $LEGEND)\\n:",
153 "AREA:avgi#ffffff:",
154 "AREA:minx#c0ffc0:min",
155 "GPRINT:mini:MIN: (min\\:%6.2lf%s /\\g",
156 "GPRINT:mina:AVERAGE: avg\\:%6.2lf%s /\\g",
157 "GPRINT:minx:MAX: max\\:%6.2lf%s $LEGEND)\\n:",
158 "AREA:mini#ffffff:",
159 "LINE1:maxa#c00000:",
160 "LINE1:mina#00c000:",
161 "LINE1:avga#000000:",
162 "AREA:wrong#ffffa0:unreachable",
163 "HRULE:0#000000";
164 }
165 }
166 rename $TEMPNAME,$FILENAME;
167 printf " %-7s %d"."x%d %s\n",$descr,$xs,$ys,$FILENAME;
168 }
169 }
170 }
171 else { print " No database found\n Please check if the daemon is running.\n";next; }
172 print "\n";
173 }
174exit 0;
175 

Powered by WebSVN 2.2.1