RRDTool-OO
view release on metacpan or search on metacpan
name => "in95precent",
vdef => "firstdraw,95,PERCENT"
},
print => {
draw => 'in95percent',
format => "95 Percent Result = %3.2lf",
},
# ...
captures the print data internally. To get access to a reference to the
array containing the different pieces of data written in this way, call
my $array_ref = $rrd->print_results();
If no print output is available, the array referenced by $array_ref is
empty.
If the "graphv" function is used instead of "graph", the return value of
print_results is a hashref containing the same information in the
"print" keys, along with additional keys containing detailed information
on the graph. See "rrdtool" documentation for more detail. Here is an
example:
use Data::Dumper;
$rrd -> graphv (
image => "-",
start => $start_time,
# ...
my $hash_ref = $rrd->print_results();
print Dumper $hash_ref;
$VAR1 = {
'print[2]' => '1600.00',
'value_min' => '200',
'image_height' => 64,
'graph_height' => 10,
'print[1]' => '3010.18',
'graph_end' => 1249391462,
'print[3]' => '1600.00',
'graph_left' => 51,
'print[4]' => '2337.29',
'print[0]' => '305.13',
'value_max' => '10000',
'graph_width' => 10,
'image_width' => 91,
'graph_top' => 22,
'image' => '#PNG
[...lots of binary rubbish your terminal won't like...]
',
'graph_start' => 1217855462
};
In this case, the option (image => "-") has been used to create the hash
key with the same name, the value of which actually contains the BLOB of
the image itself. This is useful when image needs to be passed to other
modules (e.g. Image::Magick), instead of writing it to disk. Be aware
that rrdtool 1.3 is required for "graphv" to work.
Error Handling
By default, "RRDTool::OO"'s methods will throw fatal errors (as in:
they're calling "die") if the underlying "RRDs::*" commands indicate
failure.
This behaviour can be overridden by calling the constructor with the
"raise_error" flag set to false:
my $rrd = RRDTool::OO->new(
file => "myrrdfile.rrd",
raise_error => 0,
);
In this mode, RRDTool's methods will just pass back values returned from
the underlying "RRDs" functions if an error happens (usually 1 if
successful and "undef" if an error occurs).
Debugging
"RRDTool::OO" is "Log::Log4perl" enabled, so if you want to know what's
going on under the hood, just turn it on:
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init({
level => $DEBUG
});
If you're interested particularly in *rrdtool* commands issued by
"RRDTool::OO" while you're operating it, just enable the category
"rrdtool":
Log::Log4perl->easy_init({
level => $INFO,
category => 'rrdtool',
layout => '%m%n',
});
This will display all "rrdtool" commands that "RRDTool::OO" submits to
the shared library. Let's turn it on for the code snippet in the
SYNOPSIS section of this manual page and watch the output:
rrdtool create myrrdfile.rrd --step 1 \
DS:mydatasource:GAUGE:2:U:U RRA:MAX:0.5:1:5
rrdtool update myrrdfile.rrd N:1
rrdtool update myrrdfile.rrd N:2
rrdtool update myrrdfile.rrd N:3
rrdtool fetch myrrdfile.rrd MAX
Often handy for cut-and-paste.
Allow New rrdtool Parameters
"RRDTool::OO" tracks rrdtool's progress loosely, so it might happen that
at a given point in time, rrdtool introduces a new option that
"RRDTool::OO" doesn't know about yet.
This might lead to problems, since default, "RRDTool::OO" has its
"strict" mode enabled, rejecting all unknown options. This mode is
usually helpful, because it catches typos (like "verical_label"), but if
( run in 1.471 second using v1.01-cache-2.11-cpan-5837b0d9d2c )