RRDTool-OO
view release on metacpan or search on metacpan
lib/RRDTool/OO.pm view on Meta::CPAN
draw => {
type => "hidden",
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 C<$array_ref>
is empty.
If the C<graphv> function is used instead of C<graph>, the return value of
print_results is a hashref containing the same information in the C<print> keys,
along with additional keys containing detailed information on the graph. See C<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 C<graphv> to work.
=head2 Error Handling
By default, C<RRDTool::OO>'s methods will throw fatal errors (as in:
they're calling C<die>) if the underlying C<RRDs::*> commands indicate
failure.
This behaviour can be overridden by calling the constructor with
the C<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 C<RRDs> functions if an error happens (usually
1 if successful and C<undef> if an error occurs).
=head2 Debugging
C<RRDTool::OO> is C<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 I<rrdtool> commands issued
by C<RRDTool::OO> while you're operating it, just enable the
category C<"rrdtool">:
Log::Log4perl->easy_init({
level => $INFO,
category => 'rrdtool',
layout => '%m%n',
});
This will display all C<rrdtool> commands that C<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.
=head2 Allow New rrdtool Parameters
C<RRDTool::OO> tracks rrdtool's progress loosely, so it might happen
that at a given point in time, rrdtool introduces a new option that
( run in 1.340 second using v1.01-cache-2.11-cpan-99c4e6809bf )