Adrian Andreias

Aug 05, 2014

Feb 08, 2013

make python-rrdtool graph return image bytes

The rrdtool.graph function from the Python library either outputs graph to stdout or saves it to a file. There are many cases when you don't want these, you want to get the returned image in a variable holding the bytes instead. And writing a temporary image to disk and then read it is a hack that makes unnecessarily disk operations which you might not afford in some scenarios.

After spending a few hours on this and asking about it on mailing list and IRC channel I was almost ready to give up and do all sorts of stdout redirecting tricks when I found a note from the author on a Debian bug report. I wish the python rrdtool library actually had some kind of documentation, beyond the command line documentation.

Anyhow: use python functions graphv instead of graph to get the image in the returned variable instead of printing the image.

Jan 10, 2013