[rrd-users] Generate rrd graph in real time

William R. Lorenz wrl at express.org
Wed Jun 24 18:17:51 CEST 2009


On Wed, 24 Jun 2009, Robert Hagens wrote:

> I couldn't get php-rrdtool to work, it seems that support has stopped 
> for it. I could be wrong. I do all my work in php, and fire up rrdtool 
> as a separate process, and pipe commands to/from it from php.

> frankie wrote:

>>> Hi all, I want to generate the graph realtime when the web page is 
>>> visited by someone similar to cacti . Is php-rrdtool is the only way 
>>> to do it?

>> No. I do it at work with a bash script and rrdtool, but I suspect php 
>> or perl would be better as the bash script is not pretty !  See 
>> https://lists.oetiker.ch/pipermail/rrd-users/2009-January/015167.html

It is also possible to reference a PHP script for an image, i.e.:

   <img src="/rrd-image-script.php" />

In the top of that PHP script, you will need to add the following, BEFORE 
ANYTHING ELSE, to specify the document is a binary-encoded PNG image:

   header("Content-Type: image/png\n");
   header("Content-Transfer-Encoding: binary");

At that point, you can just call out to rrdtool to get the image data, 
using something akin to <?=system("rrdtool graph - OPTIONS")?> (of course, 
please the OPTIONS with your options).  The '-' prints to stdout, and thus 
returns the image data via the system call to the page for its transfer.

This is, in my opinion, the easiest method to produce dynamic PHP graphs. 
You can also call out to /rrd-image-script.php?name=mygraph&param1=val1 or 
specify other variables that should be passed in on the HTTP GET string, 
which will allow you to generate more than one graph from the same script.

Hope this helps,

William R. Lorenz

More information about the rrd-users mailing list