[rrd-users] RRD::CGI::Image-0.01 released
Joshua Keroes
joshua at keroes.com
Tue Aug 5 10:17:32 CEST 2008
There are currently two ways to create an RRD graph:
1. On the command-line using "rrdtool graph ..."
2. Using the API through a module like RRDs.pm (or another language's library)
This module adds a third way to create a graph:
3. Via CGI params.
e.g. http://example.com/rrd.png.cgi?--start=07/01/2008;--end=now;--title=Example+graph;DEF:ds0=path/to/directory/file.rrd:ds0:MAX;LINE1:ds0%230000ff:ds0
The CGI program above, rrd.png.cgi, is a simple wrapper that sets sane
defaults and calls the library. The library processes the params,
ensures there's no funny business, decodes the CGI params and passes
them off to RRDs.pm, which sends the PNG directly back to the web
browser. Without temp files.
Why would you want to do this? Well, the example code in the module
lets you create dynamically-updating AJAXy graphics on your webpage
with the DateSlider control from
http://ajaxorized.com/dateslider/slider.html . Goodbye webpages with
day, week, month, and year graphs - now you can offer just one graph
and let the user decide which time-span the graph should display. On
the fly.
Example code is provided in the module. It will need a few tweaks to
get it to work with your RRDs.
You can install the module and its prerequisites by typing:
$ sudo cpan
Password: *****
cpan> install RRD::CGI::Image
When done, if you'd like to try the AJAX example:
cpan> look RRD::CGI::Image
# mkdir path/to/your/webroot/dateslider
# cp -R binhtml/* path/to/your/webroot/dateslider
adjust permissions, ownership, and then read the readme.txt file in
the dateslider/ dir.
---
A few things:
1. This code is written in Perl but it enables a CGI. If you know how
to install Perl modules with 'sudo cpan' there's no reason you can't
combine your Python, Ruby, or um Erlang code with rrd.png.cgi
2. I am not a Javascript programmer. If you improve the Javscript
example provided with the code, drop me a line, and I'll include your
code in future releases
3. Dear core developers: I don't have a simple way to return errors to
the user. I'd like to offer the option to get a PNG with an error
message. That would be very simple if RRDs::graph( ... ) would
generate an image if given just a COMMENT. No DEFs, no LINE3s; just a
COMMENT and possibly --title. Since COMMENTs can be handled by Pango,
I could format them nicely. That would be awesome.
Cheers,
Joshua
PS It's recommended that you use 'sudo cpan' to install the module.
That said, if you just want to look at the code, here you go:
http://search.cpan.org/~joshua/RRD-CGI-Image-0.01/
More information about the rrd-users
mailing list