Code

Initial revision
[rrdtool-all.git] / contrib / php4 / examples / rrd_fetch.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_fetch() command
11  ##
15   $opts = array ( "AVERAGE", "--start", "-1h" );
17   $ret = rrd_fetch("/dir/router-port2.rrd", $opts, count($opts));
18  
19   ##
20   ## if $ret is an array, rrd_fetch() succeeded
21   ## 
22   if ( is_array($ret) )
23   {
24       echo "Start time    (epoch): $ret[start]\n";
25       echo "End time      (epoch): $ret[end]\n";
26       echo "Step interval (epoch): $ret[step]\n";
28       ##
29       ## names of the DS's (data sources) will be 
30       ## contained in the array $ret[ds_namv][..]
31       ##
32       for($i = 0; $i < count($ret[ds_namv]); $i++)
33       {
34           $tmp = $ret[ds_namv][$i];
35           echo "$tmp \n";
36       }
38       ##
39       ## all data will be packed into the
40       ## $ret[data][..]  array
41       ##
42       for($i = 0; $i < count($ret[data]); $i++)
43       {
44           $tmp = $ret[data][$i];
45           echo "$hi\n";
46       }
47   }
48   else
49   {
50       $err = rrd_error();
51       echo "fetch() ERROR: $err\n";
52   }
55 ?>