RRDTool-OO
view release on metacpan or search on metacpan
lib/RRDTool/OO.pm view on Meta::CPAN
package RRDTool::OO;
use 5.6.0;
use strict;
use warnings;
use Carp;
use RRDs;
use Storable;
use Data::Dumper;
use Log::Log4perl qw(:easy);
our $VERSION = '0.36';
# Define the mandatory and optional parameters for every method.
our $OPTIONS = {
new => { mandatory => ['file'],
optional => [qw(raise_error dry_run strict)],
},
create => { mandatory => [qw(data_source)],
optional => [qw(step start hwpredict archive)],
data_source => {
mandatory => [qw(name type)],
optional => [qw(min max heartbeat)],
},
archive => {
mandatory => [qw(rows)],
optional => [qw(cfunc cpoints xff)],
},
hwpredict => {
mandatory => [qw(rows)],
optional => [qw(
alpha beta gamma
seasonal_period
threshold window_length
)],
},
},
update => { mandatory => [qw()],
optional => [qw(time value values)],
},
graph => { mandatory => [qw(image)],
optional => [qw(vertical_label title start end x_grid
y_grid alt_y_grid no_minor alt_y_mrtg
alt_autoscale alt_autoscale_max base
units_exponent units_length width
height interlaced imginfo imgformat
overlay unit lazy upper_limit lower_limit
rigid
logarithmic color no_legend only_graph
force_rules_legend title step draw
line area shift tick
print gprint vrule hrule comment font
no_gridfit font_render_mode
font_smoothing_threshold slope_mode
tabwidth units watermark zoom
disable_rrdtool_tag
)],
draw => {
mandatory => [qw()],
optional => [qw(file dsname cfunc thickness
type color legend name cdef vdef
stack step start end
)],
},
color => {
mandatory => [qw()],
optional => [qw(back canvas shadea shadeb
grid mgrid font frame arrow)],
},
font => {
mandatory => [qw(name)],
optional => [qw(element size)],
},
print => {
mandatory => [qw()],
optional => [qw(draw format cfunc)],
},
gprint => {
mandatory => [qw(format)],
optional => [qw(draw cfunc)],
},
vrule => {
mandatory => [qw(time)],
optional => [qw(color legend)],
},
hrule => {
mandatory => [qw(value)],
optional => [qw(color legend)],
},
comment => {
mandatory => [],
optional => [],
},
line => {
mandatory => [qw(value)],
optional => [qw(width color legend stack)],
},
area => {
mandatory => [qw(value)],
optional => [qw(color legend stack)],
},
tick => {
mandatory => [qw()],
optional => [qw(draw color legend fraction)],
},
shift => {
mandatory => [qw(offset)],
lib/RRDTool/OO.pm view on Meta::CPAN
cfunc => 'AVERAGE'
},
);
If a C<file> parameter is specified per C<draw>, the defaults for C<dsname>
and C<cfunc> are fetched from this file, not from the file that's attached
to the C<RRDTool::OO> object C<$rrd> used.
Graphs may also consist of algebraic calculations of previously defined
graphs. In this case, graphs derived from real data sources need to be named,
so that subsequent C<cdef> definitions can refer to them and calculate
new graphs, based on the previously defined graph:
$rrd->graph(
image => $image_file_name,
vertical_label => 'Network Traffic',
draw => {
type => 'line',
color => 'FF0000', # red line
dsname => 'load',
name => 'firstgraph',
legend => 'Unmodified Load',
},
draw => {
type => 'line',
color => '00FF00', # green line
cdef => "firstgraph,2,*",
legend => 'Load Doubled Up',
},
);
Note that the second C<draw> doesn't refer to a datasource C<dsname>
(nor does it fall back to the default data source), but
defines a C<cdef>, performing calculations on a previously defined
draw named C<firstgraph>. The calculation is specified using
RRDTool's reverse polish notation, where instructions are separated by commas
(C<"firstgraph,2,*"> simply multiplies C<firstgraph>'s values by 2).
On a global level, in addition to the C<vertical_label> parameter shown
in the examples above, C<graph> offers a plethora of parameters:
C<vertical_label>,
C<title>,
C<start>,
C<end>,
C<x_grid>,
C<y_grid>,
C<alt_y_grid>,
C<no_minor>,
C<alt_y_mrtg>,
C<alt_autoscale>,
C<alt_autoscale_max>,
C<base>,
C<units_exponent>,
C<units_length>,
C<width>,
C<height>,
C<interlaced>,
C<imginfo>,
C<imgformat>,
C<overlay>,
C<unit>,
C<lazy>,
C<rigid>,
C<lower_limit>,
C<upper_limit>,
C<logarithmic>,
C<color>,
C<no_legend>,
C<only_graph>,
C<force_rules_legend>,
C<title>,
C<step>.
Some options (e.g. C<alt_y_grid>) don't expect values, they need to
be specified like
alt_y_grid => undef
in order to be passed properly to RRDTool.
The C<color> option expects a reference to a hash with various settings
for the different graph areas:
C<back> (background),
C<canvas>,
C<shadea> (left/top border),
C<shadeb> (right/bottom border),
C<grid>, C<mgrid> major grid,
C<font>,
C<frame> and C<arrow>:
$rrd->graph(
...
color => { back => '#0e0e0e',
arrow => '#ff0000',
canvas => '#eebbbb',
},
...
);
Fonts for various graph elements may be specified in C<font> blocks,
which must either name a TrueType font file or a PDF/Postscript font name.
You may optionally specify a size and element name (defaults to DEFAULT,
which to RRD means "use this font for everything). Example:
font => {
name => "/usr/openwin/lib/X11/fonts/TrueType/GillSans.ttf",
size => 16,
element => "title"
}
Please check the RRDTool documentation for a detailed description
on what each option is used for:
http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/manual/rrdgraph.html
Sometimes it's useful to print max, min or average values of
a given graph at the bottom of the chart or to STDOUT. That's what
C<gprint> and C<print> options are for. They are printing variables
which are defined as C<vdef>s somewhere else:
( run in 1.517 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )