OK, I found out that there is not a way to create a COMPUTE resource out of the box in RRDTool::OO, but it is possible to workaround this lack of functionality by using the dry run mode. Here is how.
First, you need to create an RRDTool::OO object in dry run mode. Then you prepare all the "standard" data sources in the usual way, and call create. It won't actually execute the call, but now you can retrieve a reference to the function that it would have called, along with a reference to the function arguments. You can now fiddle with the arguments and call the function when you are ready.
This is how I did it:
# Creation of a COMPUTE data source is not contemplated in the
# documentation, nor it is in the code. That's why we use an
# object in dry-run mode: we'll get a reference to the function
# and arguments that were about to be called, and add our
# resource. Finally, we run the call.
# Pretty bad it didn't have the function already...
my $dsdef =
q{DS:aggregate:COMPUTE:}.
join(",",@dsources).",ADDNAN"x$#dsources ;
$rrdbuilder->create(@rrd_parms) ;
# Get references to the RRD function and arguments
# Push the COMPUTE data source in it
# Run the create command, see what happens
my ($subref,$args) = $rrdbuilder->get_exec_env();
push @$args,$dsdef ;
eval {
$subref->(@$args) ;
} ;
Ciao! --bronto
In theory, there is no difference between theory and practice. In practice, there is.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|