File: test_fetch.php

package info (click to toggle)
php4-rrdtool 1.04-11
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,168 kB
  • ctags: 85
  • sloc: sh: 9,365; ansic: 356; php: 102; makefile: 72; awk: 43
file content (75 lines) | stat: -rw-r--r-- 1,859 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?
#
#
# test_fetch.php
#
#      rrd_fetch with PHP binding
#
#      by Alex Lam ( ccalam@cityu.edu.hk )
#
# This sample code are provided as is for reference only
# It provide the calling sequence for using rrd_fetch under PHP binding

dl("rrdtool.so");

echo "<PRE>\n";

#$opts = array ( "AVERAGE", "--start", "971246700", "--end", "971249100");
$opts = array ( "AVERAGE", "--start", "-365d");

$ret = rrd_fetch("etc3p16.rrd", $opts, count($opts));

if ( is_array($ret) )
{
      echo "Start Time    (epoch): $ret[start] \n";
      echo "Start Time: " . date("d/m/Y H:i:s",$ret[start]) . "<P>";
      echo "End   Time    (epoch): $ret[end] \n";
      echo "End   Time: " . date("d/m/Y H:i:s",$ret[end]) . "<P>";
      echo "Step Interval (epoch): $ret[step] <P>";

      $column_no = count($ret[ds_namv]);
      $row_no    = count($ret[data]);
      echo "Columns $column_no   ";
      echo "Rows    $row_no <P>";
      echo "[data] ARRAY SIZE: " . count($ret[data]);


      print "<br>&nbsp;";
      print "<table BORDER COLS=9 WIDTH=\"100%\">";
      print "<tr>";
      echo "<td>Time Stamp</td>";
      for ($i = 0;  $i < count($ret[ds_namv]); $i++)
      {
          $name[$i] = $ret[ds_namv][$i];
          echo "<td>$name[$i]</td>";
      }
      echo "</tr>";
	echo "</table>\n";

      $cur_item = 0; 
      $cur_time = $ret[start];
      $interval = $ret[step];


      for ($i = 0; $i < $column_no; $i++)
      {
          print "<tr><td>$cur_time</td>";
          for ($ii = 0 ; $ii < $column_no; $ii++)
          {
               $cur_data = $ret[data][$cur_item];
               printf("<td>%3.3f</td>\n", $cur_data); 
               $cur_item++;
               $cur_time+=$interval;
          } 
          echo "</tr>";
      }
}
else
     {
          $err = rrd_error();
          echo "fetch() ERROR: $err\n";
     }

echo "</PRE>\n";

?>