Generate rrd graph in real time

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Generate rrd graph in real time

frankie
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?
THX
Reply | Threaded
Open this post in threaded view
|

Re: Generate rrd graph in real time

Mr Robert Conway
Frankie,
I am not a web guru and tried to get a few times to get php installed with
the library and failed.  I gave up and simply used a bash cgi script.  The
trick for me was to send the output to >dev/null as the rrd graph gives an
output of trend size which stuffed up sending the file back to the web page.
When I rebuild my server and upgrade rrdtools I shall again try a php
library.


Check out www.rjconway.homeip.net   the solution is very simply.  The web
page source will show how I assemble the cgi arguments and I have included
my cgi file below.

This page also demonstrates using ajax to retrieve data and display it as
gauges.  I have created these gauges from scratch however they could easily
be used for any type of application.  The gauges are driven by the ability
of raphaeljs, a fantastic SVG type library.  Send an email direct as I have
started a write-up on how the gauges work.




######################## CGI SCRIPT ON SERVER #####################
#!/bin/bash

## Strip HTML GET String into local variables ##
STIME=`echo "$QUERY_STRING" | sed -n 's/^.*stime=\([^&]*\).*$/\1/p' | sed
"s/%20/ /g"`
ETIME=`echo "$QUERY_STRING" | sed -n 's/^.*etime=\([^&]*\).*$/\1/p' | sed
"s/%20/ /g"`
HIGHSCALE=`echo "$QUERY_STRING" | sed -n 's/^.*highscale=\([^&]*\).*$/\1/p'
| sed "s/%20/ /g"`
LOWSCALE=`echo "$QUERY_STRING" | sed -n 's/^.*lowscale=\([^&]*\).*$/\1/p' |
sed "s/%20/ /g"`
WIDTH=`echo "$QUERY_STRING" | sed -n 's/^.*width=\([^&]*\).*$/\1/p' | sed
"s/%20/ /g"`
HEIGHT=`echo "$QUERY_STRING" | sed -n 's/^.*height=\([^&]*\).*$/\1/p' | sed
"s/%20/ /g"`
TRENDTYPE=`echo "$QUERY_STRING" | sed -n 's/^.*ttype=\([^&]*\).*$/\1/p' |
sed "s/%20/ /g"`

case "$TRENDTYPE" in
'ph')
## Aquarium PH GRAPH ##
rrdtool graph /var/www/aqua.png --start $STIME --end $ETIME \
--upper-limit $HIGHSCALE --lower-limit $LOWSCALE --slope-mode --units-length
2 \
--interlaced \
--rigid \
--width $WIDTH --height $HEIGHT \
--vertical-label "pH\n" \
--color CANVAS#000000 \
--title "Aquarium pH" \
DEF:phv=/var/www/rrd/aqua_ph.rrd:P1:AVERAGE  LINE1:phv#0000FF:"Ph=" \
VDEF:phlast=phv,LAST GPRINT:phlast:"%3.2lf%S" \
VDEF:phavg=phv,AVERAGE GPRINT:phavg:"avg=%3.2lf%spH      " \
--watermark "Aquarium PH Graph">/dev/null
;;

'orp')
## Aquarium ORP GRAPH ##
rrdtool graph /var/www/aqua.png --start $STIME --end $ETIME \
--upper-limit $HIGHSCALE --lower-limit $LOWSCALE --slope-mode --units-length
2 \
--interlaced \
--rigid \
--width $WIDTH --height $HEIGHT \
--title "Aquarium ORP" \
--vertical-label "mV" \
--color CANVAS#000000 \
DEF:orp=/var/www/rrd/aqua_orp.rrd:O1:AVERAGE \
LINE1:orp#FF3D0D:"Orp=" \
VDEF:orplast=orp,LAST GPRINT:orplast:"%4.0lf%smV" \
VDEF:orpavg=orp,AVERAGE GPRINT:orpavg:"avg=%4.0lf%smV" \
--watermark "Aquarium Orp / Conductivity Graph" >/dev/null
;;

esac

## Send output to web page ##
echo Content-type: image/png
echo
cat aqua.png







-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of frankie
Sent: Monday, June 22, 2009 11:33 PM
To: [hidden email]
Subject: [rrd-users] Generate rrd graph in real time


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?
THX
--
View this message in context:
http://n2.nabble.com/Generate-rrd-graph-in-real-time-tp3136242p3136242.html
Sent from the RRDtool Users Mailinglist mailing list archive at Nabble.com.

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.339 / Virus Database: 270.12.85/2193 - Release Date: 06/21/09
20:02:00

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: Generate rrd graph in real time

Pablo Sanchez
[ Comments below, in line ]

On Wednesday 24 June 2009 at 8:15 am, Rob Conway penned
about "Re: [rrd-users] Generate rrd graph in real time"

> Frankie,
> I am not a web guru and tried to get a few times to get php installed with
> the library and failed.  I gave up and simply used a bash cgi script.  The
> trick for me was to send the output to >dev/null as the rrd graph gives an
> output of trend size which stuffed up sending the file back to the web page.
> When I rebuild my server and upgrade rrdtools I shall again try a php
> library.

Hi,

To help with debugging, I send the output of my (sh) CGI to the caller
in the form of an HTML comment:

pablo@cinema-912-[bin]: ./rrd_weather graph_general_month_m
Content-type: text/html

<!-- Calling RRD
781x301
781x179
787x179
781x159
781x227
-->
--
Pablo Sanchez - Blueoak Database Engineering, Inc
Ph:    819.459.1926      Fax:   760.860.5225 (US)

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: Generate rrd graph in real time

Simon Hobson
In reply to this post by frankie
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

--
Simon Hobson

Visit http://www.magpiesnestpublishing.co.uk/ for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: Generate rrd graph in real time

Robert Hagens
Hi,
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.

Rob

 

Robert Hagens | Chief Technical Officer| Envysion, Inc.

950 Spruce Street | Louisville, CO 80027

303.590.2365 office | 303.590.2351 fax

[hidden email] | www.envysion.com | Visit our blog


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Simon Hobson
Sent: Wednesday, June 24, 2009 8:51 AM
To: [hidden email]
Subject: Re: [rrd-users] Generate rrd graph in real time

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

--
Simon Hobson

Visit http://www.magpiesnestpublishing.co.uk/ for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: Generate rrd graph in real time

William R. Lorenz
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&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

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Is php-rrdtool really necessary? -- was: Generate rrd graph in real time

Eduardo Bragatto
In reply to this post by Robert Hagens
On Jun 24, 2009, at 12:18 PM, Robert Hagens wrote:

> Hi,
> 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.

I've tried using it in the past and although I could get it compiled  
and running, it seemed to be unstable and failed to work correctly in  
certain situations -- it was a long time ago, don't ask for details.

However, because of that first bad experience and the fact that I  
haven't heard of any development on the php module, I gave up using it  
and I'm using system() calls to run rrdtool from a php script.

Does anyone know, if there's any _considerable_ performance  
degradation by using system() calls instead of having internal calls  
directly to the rrdtool functions?


- Eduardo Bragatto

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: Generate rrd graph in real time

David Thornton
In reply to this post by William R. Lorenz
you want rrdcgi

it's great I love it.

it's a cgi script that does exactly what you want (I think)

http://oss.oetiker.ch/rrdtool/doc/rrdcgi.en.html

David

On Wed, Jun 24, 2009 at 12:17 PM, William R. Lorenz<[hidden email]> wrote:

> 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&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
>
> _______________________________________________
> rrd-users mailing list
> [hidden email]
> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
>

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: Generate rrd graph in real time

frankie
In reply to this post by William R. Lorenz
Thank you All reply.
Finally, I use php-rrd to get my work done.
It seems that there are dependency problems when install rrdtool 1.3.x version in centos4.5. I have to try the version one by one and installed 1.2.7 eventually.