[rrd-users] Proposed new librrd function to provide image data in memory buffer

Henrik Størner henrik-rrdusers at hswn.dk
Mon Feb 17 15:51:48 CET 2014


Hi,

I would like to propose an extension to the librrd API with a new 
function similar to rrd_graph(), but instead of writing the generated 
image data to stdout it will return it in a memory buffer back to the 
caller.

My reason for this is two-fold:


1) I am using librrd to generate graphs via a web CGI program. This 
really has to be done like:

    - Output the HTTP headers, including a "Content-type: image/png"
    - call rrd_graph() to generate the image

If the rrd_graph() invocation fails for some reason, then it is not 
possible to provide an error message to the user since the content type 
is already fixed as a PNG image. So unless I can compose an error 
message in a PNG image (a bit difficult), then the webpage just shows up 
with a broken image.


2) I would like to use the FastCGI interface for speeding up web image 
generation, but this requires that all output goes through the FastCGI 
output routines. Since rrd_graph() simply does an fwrite() to stdout, it 
cannot be combined with FastCGI.


Looking at the rrd_graph() and rrd_graph_v() code, I can see that the 
generated image data is already contained in an "unsigned char" buffer. 
So the amount of change needed to just return this buffer back to the 
caller is minimal.

To avoid an API change that breaks existing code, I think the best way 
is to provide a new function - e.g. "rrd_graph_buffer()" - that returns 
the graph data in a buffer, and keep the current rrd_graph() API unchanged.

I have attached a patch against version 1.4.8 implementing this. The 
patch implements the rrd_graph_buffer() via the C API; I am not sure of 
how to do the various other language bindings, so those are not included.

I hope this patch - or something with similar functionality - can be 
included in a future rrdtool release.


Best regards,
Henrik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rrd_graph_buffer.diff
Type: text/x-diff
Size: 3054 bytes
Desc: not available
Url : http://lists.oetiker.ch/pipermail/rrd-users/attachments/20140217/b244d430/attachment.diff 


More information about the rrd-users mailing list