Code

Initial revision
[rrdtool-all.git] / contrib / php4 / examples / rrd_graph.php
1 <?
3  ## the following line is only needed if built as a self-contained
4  ## extension.  If you build the rrdtool module as an embedded
5  ## extension, the rrd_* functions will always be available, so you
6  ## do not need the dl() call.
7  dl("rrdtool.so");
9  ##
10  ## demonstration of the rrd_graph() command
11  ##
13    $opts = array( "--start", "-4d", 
14                   "DEF:in=/dir/router-port2.rrd:input:AVERAGE",
15                   "DEF:out=/dir/router-port2.rrd:output:AVERAGE",
16                   "LINE2:in#0000ff:Incoming Traffic Avg.",
17                   "PRINT:in:AVERAGE:incoming\: %1.2lf b/s",
18                   "PRINT:in:AVERAGE:incoming2\: %1.2lf b/s"
19                 );
22    $ret = rrd_graph("/some-dir/router-port2.gif", $opts, count($opts));
24    ##
25    ## if $ret is an array, then rrd_graph was successful
26    ##
27    if ( is_array($ret) )
28    {
29        echo "Image size:  $ret[xsize] x $ret[ysize]\n";
30        
32        ##
33        ## all results from any PRINT commands will be
34        ## in the array $ret[calcpr][..]
35        ##
36        echo "rrd_graph1 print results: \n";
38        for ($i = 0; $i < count($ret[calcpr]); $i++)
39            echo $ret[calcpr][$i] . "\n";
40    }
41    else
42    {
43        $err = rrd_error();
44        echo "rrd_graph() ERROR: $err\n";
45    }
47 ?>