« Return to Thread: Generate rrd graph in real time

Re: Generate rrd graph in real time

by William R. Lorenz :: Rate this Message:

Reply to Author | View in Thread

Hello,

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:

   <?php
   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¶m1=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

_______________________________________________
rrd-users mailing list
rrd-users@...
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users

 « Return to Thread: Generate rrd graph in real time