jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [Documentation/] [module-howto/] [howto-diagrams.pl] - Blame information for rev 34

 

Line No. Rev Author Line
11simandlThe "diagrams.pl" file will be called to build all diagrams of this module. It imports some of HotSaNICs libraries to save some nasty fiddling with the settings files and rrdtool's "graph" function. The skeleton would always look like this:
2 
3---------- BEGIN CODE ----------
4#!/usr/bin/env perl
5 
6# include PERL libraries
7use strict;
8use warnings;
9use diagnostics;
10 
11# include HotSaNIC libraries
12use lib "../../lib";
13use HotSaNICparser;
14use HotSaNICdiagram;
15 
16# If you're going to check the file into CVS, please use this construct.
17# It makes sure that the CVS version numberes will be set correctly.
18#
19(my $VERSION = '$Revision: 1.2 $') =~ s/.*(\d+\.\d+).*/$1/;
20(my $IDENTIFIER = '$Id: howto-diagrams.pl,v 1.2 2004/05/23 12:11:33 bernisys Exp $') =~ s/.*,v (.*) \$/$1/;
21 
22# read all settings
23#
24my $MODNAME=HotSaNICparser::get_module_name();
25my %CONFIG=HotSaNICparser::get_config("../..");
26my %MODULECONFIG=HotSaNICparser::get_moduleconfig(".", %CONFIGURATION_HASH );
27#
28# %CONFIGURATION_HASH has to contain the names and types of each settings item used in this script.
29# It can be a static hash of the form: (ITEM=>"type", ...)
30# type may be: array, var, bool
31#
32# Example:
33# my %MODULECONFIG=HotSaNICparser::get_moduleconfig(".",(FOO=>"var",BAR=>"bool",HOST=>"array");
34#
35my $OUTDIR=$CONFIG{"WEBDIR"}."/".lc $MODNAME;
36if ( ! -e $OUTDIR ) { mkdir $OUTDIR,0755; }
37my $IMGFMT=lc $CONFIG{"IMAGEFORMAT"};
38 
39my ($FORCE,$DEBUGLEVEL,%PLOT)=HotSaNICdiagram::check_args(@ARGV);
40my @OPTIONS=HotSaNICdiagram::get_common_options(%MODULECONFIG,%CONFIG);
41 
42#
43# Now add all graph options which are common in EVERY DIAGRAM! to the @OPTIONS array
44#
45 
46# create diagrams
47#
48foreach ( <<array with diagram names>> ) {
49 my $name = ....
50 my $description = ....
51 my $DB_FILE="./rrd/<<filename>>.rrd";
52 if (%PLOT) { next if ! defined $PLOT{$name}; }
53 
54 print "creating images for $dev ($description) ...\n";
55 
56# if database exists, create images...
57 if ( -e $DB_FILE) {
58 
59 foreach my $range ("1h","6h","1day","1week","1month","1year") {
60 my ($range_plaintext,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
61 
62 my @EXTOPTIONS=("-s","-$fullrange", "--title", "TITLE_STRING - last $range_plaintext ($DATESTRING)");
63 my @COMMANDS;
64 
65#
66# now fill @COMMANDS array with valid rrdtool::graph commands
67#
68# HotSaNICdiagram.pm holds some functions that makes it easy to fill your diagram with graphs and legends.
69# These are documented in the library itself, as well as in the "howto-diagrams.pl" documentation file.
70#
71 
72 my %CONF=(RANGE=>$descr,
73 FILENAME=>"$OUTDIR/$name-$file",
74 FORMAT=>lc $MODULECONFIG{IMAGEFORMAT},
75 INTERVAL=>$build,
76 FORCE=>$FORCE,
77 OPTIONS=>[@OPTIONS,@EXTOPTIONS,@COMMANDS],
78 DEBUGLEVEL=>$DEBUGLEVEL,
79 MODNAME=>$MODNAME);
80 HotSaNICdiagram::graph(%CONF);
81 }
82 }
83 }
84 
85---------- END CODE ----------
86 
87 
88 
89 
90 
91---------- FUNCTION DESCRIPTIONS ----------
92 
93 
94---------- HotSaNICdiagram::get_diagram_properties ----------
95 
96USAGE:
97 ($range_plaintext,$file,$build,$fullrange,$DATESTRING)=HotSaNICdiagram::get_diagram_properties($range);
98 
99PARAMETERS:
100 $range the range of the desired diagram: "1h" "6h" "1day" "1week" "1month" "1year"
101 
102RETURN VALUES:
103 $range_plaintext will be "hour" "6 hours" "day" "week" "month" or "year" in dependency of $range
104 
105 $file filename-extension (same as $range_plaintext, except "6 hours" will be "6h")
106 
107 $build number of seconds after which a rebuild of the diagram should be done
108 
109 $fullrange number of seconds covered by the current diagram
110 This can be used to calculate for example the number of events over the diagram's timespan
111 
112 $DATESTRING the current time in human-readable format: "Day YYYY-MM-DD hh:mm"
113 
114 
115 
116 
117---------- HotSaNICdiagram::insert_data ----------
118 
119USAGE:
120 @array = HotSaNICdiagram::insert_data($type,$vars,$color,$name,$legends,$unit,$use_SI);
121 
122PARAMETERS:
123 $type one of the graph types defined in rrdtool: LINE[123] AREA STACK
124 
125 $vars string that contains one to five RRD-variables to be used for plotting and for the legend elements
126 if it contains less than five entries, the last entry will be copied to the remaining ones
127 
128 "var_plot var_min var_avg var_max var_current"
129 
130 var_plot variable that will be plotted as graph
131 this may be set to "0" to supporess the graph and only add the legend.
132 var_min variable to be used in legend as minimum
133 var_avg variable to be used in legend as average
134 var_max variable to be used in legend as maximum
135 var_current variable to be used in legend as current
136 
137 $name name of the graph
138 
139 $color valid color definition, hexadecimal: "RRGGBB"
140 
141 $legends string that contains a space separated list of legends to be built.
142 If the string is empty, no legend will be added.
143 Valid entries are:
144 
145 "min" minimum value of the 2nd item in $vars
146 "avg" average value of the 3rd item in $vars
147 "max" maximum value of the 4th item in $vars
148 "now" or "cur" last value of the 5th item in $vars
149 
150 $unit unit of the graph, a string that contains something like "bytes/s" or "sec." etc.
151 
152 $use_SI 1 => use SI units (... m for milli, k for kilo, M for mega ...) in legend
153 
154RETURN VALUES:
155 @array array that contains valid graph commands
156 
157EXAMPLE:
158 push @array,HotSaNICdiagram::insert_data("LINE1","var1 var2 var3","FF0000","test graph","min cur","bytes/s",1),
159 
160 plots a red line and adds a legend that looks like this:
161 
162 [#] test graph (min: 1.234 k current: 2.345 k bytes/s)
163 
164 ([#] is the red square that marks the legend)
165 
166 
167 
168---------- HotSaNICdiagram::insert_minmax ----------
169 
170USAGE:
171 @array = HotSaNICdiagram::insert_minmax($vars,$areacolor,$bordercolor,$name,$unit,$use_SI);
172 
173PARAMETERS:
174 $vars string that contains two RRD-variables to be used for plotting and for the legend elements.
175 the first element is the variable to be used for plotting the minimum, the second for the maximum.
176 this string may be prepended with a "0" to suppress the graph: "0 min max"
177 
178 $areacolor valid color definition for the area, hexadecimal: "RRGGBB"
179 
180 $bordercolor valid color definition for the area borders (thin lines), hexadecimal: "RRGGBB"
181 
182 $name name of the graph
183 
184 $unit unit of the graph, a string that contains something like "bytes/s" or "sec." etc.
185 
186 $use_SI 1 => use SI units (... m for milli, k for kilo, M for mega ...) in legend
187 
188 
189 
190---------- HotSaNICdiagram::insert_unknown_area ----------
191 
192USAGE:
193 @array = HotSaNICdiagram::insert_unknown_area($vars,$color,$description);
194 
195PARAMETERS:
196 
197 $vars space separated list of all variables to be taken into account.
198 If one of them is unknown, the area will be marked.
199 
200 $color valid color definition, hexadecimal: "RRGGBB"
201 
202 $description some additional legend that will (if defined) show up in brackets after the string "data unknown".
203 
204 

Powered by WebSVN 2.2.1