make graph_url work correctly, add stats_url parameters to get index links more flexi...
[php-utility-classes.git] / include / classes / rrdstat.php-class
... / ...
CommitLineData
1<?php
2/* ***** BEGIN LICENSE BLOCK *****
3 *
4 * The contents of this file are subject to Austrian copyright reegulations
5 * ("Urheberrecht"); you may not use this file except in compliance with
6 * those laws.
7 * This contents and any derived work, if it gets distributed in any way,
8 * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
9 * either express or implied.
10 *
11 * The Original Code is KaiRo's RRD statistics class.
12 *
13 * The Initial Developer of the Original Code is
14 * KaiRo - Robert Kaiser.
15 * Portions created by the Initial Developer are Copyright (C) 2005
16 * the Initial Developer. All Rights Reserved.
17 *
18 * Contributor(s): Robert Kaiser <kairo@kairo.at>
19 *
20 * ***** END LICENSE BLOCK ***** */
21
22class rrdstat {
23 // rrdstat PHP class
24 // rrdtool statistics functions
25 //
26 // function rrdstat($rrdconfig, [$conf_id])
27 // CONSTRUCTOR
28 // if $conf_id is set, $rrdconfig is a total configuration set
29 // else it's the configuration for this one RRD
30 // currently only a config array is supported, XML config is planned
31 //
32 // var $rrd_file
33 // RRD file name
34 //
35 // var $basename
36 // base name for this RRD (usually file name without .rrd)
37 //
38 // var $basedir
39 // base directory for this RRD (with a trailing slash)
40 // note that $rrd_file usually includes that path as well, but graph directory gets based on this value
41 //
42 // var $config_all
43 // complete, raw configuration array set
44 //
45 // var $config_raw
46 // configuration array set for current RRD
47 //
48 // var $config_graph
49 // configuration array set for default graph in this RRD
50 //
51 // var $config_page
52 // configuration array set for default page in this RRD
53 //
54 // var $rrd_fields
55 // definition of this RRD's fields
56 //
57 // var $rra_base
58 // definition of this RRD's base RRAs
59 //
60 // var $rrd_step
61 // basic stepping of this RRD in seconds (default: 300)
62 //
63 // var $rra_add_max
64 // should RRAs for MAX be added for every base RRA? (bool, default: true)
65 //
66 // var $status
67 // status of the RRD (unused/ok/readonly/graphonly)
68 // note that most functions require certain status values
69 // (e.g. update only works if status is ok, graph for ok/readonly/graphonly)
70 //
71 // function set_def($rrdconfig, [$conf_id])
72 // set definitions based on given configuration
73 // [intended for internal use, called by the constructor]
74 //
75 // function create()
76 // create RRD file according to set config
77 //
78 // function update([$upArray])
79 // feed new data into RRD (either use given array of values or use auto-update info from config)
80 //
81 // function fetch([$cf] = 'AVERAGE', $resolution = null, $start = null, $end = null)
82 // fetch data from the defined RRD
83 // using given consolidation function [default is AVERAGE],
84 // resolution (seconds, default is the RRD's stepping),
85 // start and end times (unix epoch, defaults are the RRD's last update time)
86 //
87 // function last_update()
88 // fetch time of last update in this RRD file
89 //
90 // function graph([$timeframe], [$sub], [$extra])
91 // create a RRD graph (and return all meta info in a flat string)
92 // for given timeframe (day [default]/week/month/year),
93 // sub-graph ID (if given) and extra config options (if given)
94 //
95 // function graph_plus([$timeframe], [$sub], [$extra])
96 // create a RRD graph (see above) and return meta info as a ready-to-use array
97 //
98 // function page([$sub], [$page_extras], [$graph_extras])
99 // create a (HTML) page and return it in a string
100 // for given sub-page ID (if given, default is a simple HTML page)
101 // and extra page and graph config options (if given)
102 //
103 // function simple_html([$sub], [$page_extras], [$graph_extras])
104 // create a simple (MRTG-like) HTML page and return it in a string
105 // XXX: this is here temporarily for compat only, it's preferred to use page()!
106 //
107 // function page_index($pconf)
108 // create a bare, very simple index list HTML page and return it in a string
109 // using given page config options
110 // [intended for internal use, called by page()]
111 //
112 // function page_overview($pconf, [$graph_extras])
113 // create an overview HTML page (including graphs) and return it in a string
114 // using given page config options and extra graph options (if given)
115 // [intended for internal use, called by page()]
116 //
117 // function page_simple($pconf, [$graph_extras])
118 // create a simple (MRTG-like) HTML page and return it in a string
119 // using given page config options and extra graph options (if given)
120 // [intended for internal use, called by page()]
121 //
122 // function h_page_statsArray($pconf)
123 // return array of stats to list on a page, using given page config options
124 // [intended for internal use, called by page_*()]
125 //
126 // function h_page_footer()
127 // return generic page footer
128 // [intended for internal use, called by page_*()]
129 //
130 // function text_quote($text)
131 // return a quoted/escaped text for use in rrdtool commandline text fields
132
133 var $rrd_file = null;
134 var $basename = null;
135 var $basedir = null;
136
137 var $config_all = null;
138 var $config_raw = null;
139 var $config_graph = null;
140 var $config_page = null;
141
142 var $rrd_fields = array();
143 var $rra_base = array();
144 var $rrd_step = 300;
145 var $rra_add_max = true;
146
147 var $status = 'unused';
148
149 function rrdstat($rrdconfig, $conf_id = null) {
150 // ***** init RRD stat module *****
151 $this->set_def($rrdconfig, $conf_id);
152
153 if (($this->status == 'unused') && !is_null($this->rrd_file)) {
154 if (!is_writeable($this->rrd_file)) {
155 if (!file_exists($this->rrd_file)) {
156 if (@touch($this->rrd_file)) { $this->create(); }
157 else { trigger_error('RRD file can not be created', E_USER_WARNING); }
158 }
159 else {
160 if (is_readable($this->rrd_file)) { $this->status = 'readonly'; }
161 else { trigger_error('RRD file is not readable', E_USER_WARNING); }
162 }
163 }
164 else {
165 $this->status = 'ok';
166 }
167 }
168 }
169
170 function set_def($rrdconfig, $conf_id = null) {
171 if (is_array($rrdconfig)) {
172 // we have an array in the format we like to have
173 $complete_conf =& $rrdconfig;
174 }
175 else {
176 // we have something else (XML data?), try to generate the iinfo aray from it
177 $complete_conf =& $rrdconfig;
178 }
179
180 if (!is_null($conf_id)) {
181 $iinfo = isset($complete_conf[$conf_id])?$complete_conf[$conf_id]:array();
182 if (isset($complete_conf['*'])) {
183 $iinfo = (array)$iinfo + (array)$complete_conf['*'];
184 if (isset($complete_conf['*']['graph'])) { $iinfo['graph'] = (array)$iinfo['graph'] + (array)$complete_conf['*']['graph']; }
185 if (isset($complete_conf['*']['page'])) { $iinfo['page'] = (array)$iinfo['page'] + (array)$complete_conf['*']['page']; }
186 }
187 }
188 else {
189 $iinfo = $complete_conf;
190 }
191
192 if (isset($iinfo['path']) && strlen($iinfo['path'])) {
193 $this->basedir = $iinfo['path'];
194 if (substr($this->basedir, -1) != '/') { $this->basedir .= '/'; }
195 }
196
197 if (isset($iinfo['graph-only']) && $iinfo['graph-only'] && !is_null($conf_id)) {
198 $this->basename = $conf_id;
199 $this->status = 'graphonly';
200 }
201 elseif (isset($iinfo['file'])) {
202 $this->rrd_file = (($iinfo['file']{0} != '/')?$this->basedir:'').$iinfo['file'];
203 $this->basename = basename((substr($this->rrd_file, -4) == '.rrd')?substr($this->rrd_file, 0, -4):$this->rrd_file);
204 }
205 elseif (!is_null($conf_id) && file_exists($conf_id.'.rrd')) {
206 $this->rrd_file = (($iinfo['file']{0} != '/')?$this->basedir:'').$conf_id.'.rrd';
207 $this->basename = $conf_id;
208 }
209 else {
210 $this->basename = !is_null($conf_id)?$conf_id:'xxx.unknown';
211 }
212
213 if (!is_null($this->rrd_file)) {
214 // fields (data sources, DS)
215 // name - DS name
216 // type - one of COUNTER, GAUGE, DERIVE, ABSOLUTE
217 // heartbeat - if no sample recieved for that time, store UNKNOWN
218 // min - U (unconstrained) or minimum value
219 // max - U (unconstrained) or maximum value
220 // update - this string will be fed into eval() for updating this field
221 if (isset($iinfo['fields']) && is_array($iinfo['fields'])) {
222 $this->rrd_fields = $iinfo['fields'];
223 }
224 else {
225 $this->rrd_fields[] = array('name' => 'ds0', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
226 $this->rrd_fields[] = array('name' => 'ds1', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
227 }
228
229
230 // MRTG-style RRD "database", see http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/tut/rrdtutorial.en.html
231 //
232 // archives (RRAs):
233 // 600 samples of 5 minutes (2 days and 2 hours)
234 // 700 samples of 30 minutes (2 days and 2 hours, plus 12.5 days)
235 // 775 samples of 2 hours (above + 50 days)
236 // 797 samples of 1 day (above + 732 days, rounded up to 797)
237
238 $this->rrd_step = isset($iinfo['rrd_step'])?$iinfo['rrd_step']:300;
239
240 if (isset($iinfo['rra_base']) && is_array($iinfo['rra_base'])) {
241 $this->rra_base = $iinfo['rra_base'];
242 }
243 else {
244 $this->rra_base[] = array('step' => 1, 'rows' => 600);
245 $this->rra_base[] = array('step' => 6, 'rows' => 700);
246 $this->rra_base[] = array('step' => 24, 'rows' => 775);
247 $this->rra_base[] = array('step' => 288, 'rows' => 797);
248 }
249
250 $this->rra_add_max = isset($iinfo['rra_add_max'])?$iinfo['rra_add_max']:true;
251 }
252
253 if (isset($iinfo['graph'])) { $this->config_graph = $iinfo['graph']; }
254 if (isset($iinfo['page'])) { $this->config_page = $iinfo['page']; }
255 $this->config_raw = $iinfo;
256 $this->config_all = $complete_conf;
257 }
258
259 function create() {
260 // create RRD file
261
262 // compose create command
263 $create_cmd = 'rrdtool create '.$this->rrd_file.' --step '.$this->rrd_step;
264 foreach ($this->rrd_fields as $ds) {
265 if (!isset($ds['type'])) { $ds['type'] = 'COUNTER'; }
266 if (!isset($ds['heartbeat'])) { $ds['heartbeat'] = 2*$this->rrd_step; }
267 if (!isset($ds['min'])) { $ds['min'] = 'U'; }
268 if (!isset($ds['max'])) { $ds['max'] = 'U'; }
269 $create_cmd .= ' DS:'.$ds['name'].':'.$ds['type'].':'.$ds['heartbeat'].':'.$ds['min'].':'.$ds['max'];
270 }
271 foreach ($this->rra_base as $rra) {
272 if (!isset($rra['cf'])) { $rra['cf'] = 'AVERAGE'; }
273 if (!isset($rra['xff'])) { $rra['xff'] = 0.5; }
274 if (!isset($rra['step'])) { $rra['step'] = 1; }
275 if (!isset($rra['rows'])) { $rra['rows'] = 600; }
276 $create_cmd .= ' RRA:'.$rra['cf'].':'.$rra['xff'].':'.$rra['step'].':'.$rra['rows'];
277 }
278 if ($this->rra_add_max) {
279 foreach ($this->rra_base as $rra) {
280 if (!isset($rra['cf'])) {
281 // only rows that have no CF set will be looked at here
282 $rra['cf'] = 'MAX';
283 if (!isset($rra['xff'])) { $rra['xff'] = 0.5; }
284 if (!isset($rra['step'])) { $rra['step'] = 1; }
285 if (!isset($rra['rows'])) { $rra['rows'] = 600; }
286 $create_cmd .= ' RRA:'.$rra['cf'].':'.$rra['xff'].':'.$rra['step'].':'.$rra['rows'];
287 }
288 }
289 }
290 $return = `$create_cmd 2>&1`;
291 if (strpos($return, 'ERROR') !== false) {
292 trigger_error($this->rrd_file.' - rrd create error: '.$return, E_USER_WARNING);
293 }
294 else { $this->status = 'ok'; }
295 }
296
297 function update($upArray = null) {
298 // feed new data into RRD
299 if ($this->status != 'ok') { trigger_error('Cannot update non-writeable file', E_USER_WARNING); return false; }
300 $upvals = array();
301 if (isset($this->config_raw['update'])) {
302 if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $this->config_raw['update'], $regs)) {
303 $upfunc = create_function('', $regs[1]);
304 $upvals = $upfunc();
305 }
306 else {
307 $evalcode = $this->config_raw['update'];
308 if (!is_null($evalcode)) {
309 ob_start();
310 eval($evalcode);
311 $ret = ob_get_contents();
312 if (strlen($ret)) { $upvals = explode("\n", $ret); }
313 ob_end_clean();
314 }
315 }
316 }
317 else {
318 foreach ($this->rrd_fields as $ds) {
319 if (is_array($upArray) && isset($upArray[$ds['name']])) { $val = $upArray[$ds['name']]; }
320 elseif (isset($ds['update'])) {
321 $val = null; $evalcode = null;
322 if (substr($ds['update'], 0, 4) == 'val:') {
323 $evalcode = 'function { return trim('.substr($ds['update'], 4).')); }';
324 }
325 elseif (substr($ds['update'], 0, 8) == 'snmp-if:') {
326 $snmphost = 'localhost'; $snmpcomm = 'public';
327 list($nix, $ifname, $valtype) = explode(':', $ds['update'], 3);
328 $iflist = explode("\n", `snmpwalk -v2c -c $snmpcomm $snmphost interfaces.ifTable.ifEntry.ifDescr`);
329 $ifnr = null;
330 foreach ($iflist as $ifdesc) {
331 if (preg_match('/ifDescr\.(\d+) = STRING: '.$ifname.'/', $ifdesc, $regs)) { $ifnr = $regs[1]; }
332 }
333 $oid = null;
334 if ($valtype == 'in') { $oid = '1.3.6.1.2.1.2.2.1.10.'.$ifnr; }
335 elseif ($valtype == 'out') { $oid = '1.3.6.1.2.1.2.2.1.16.'.$ifnr; }
336 if (!is_null($ifnr) && !is_null($oid)) {
337 $evalcode = 'function { return trim(substr(strrchr(`snmpget -v2c -c '.$snmpcomm.' '.$snmphost.' '.$oid.'`,":"),1)); }';
338 }
339 }
340 else { $evalcode = $ds['update']; }
341 if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $evalcode, $regs)) {
342 $upfunc = create_function('', $regs[1]);
343 $val = $upfunc();
344 }
345 elseif (!is_null($evalcode)) {
346 ob_start();
347 eval($evalcode);
348 $val = ob_get_contents();
349 ob_end_clean();
350 }
351 }
352 else { $val = null; }
353 $upvals[$ds['name']] = $val;
354 }
355 }
356 $key_names = (!is_numeric(array_shift(array_keys($upvals))));
357 if (in_array('L', $upvals, true)) {
358 // for at least one value, we need to set the same as the last recorded value
359 $fvals = $this->fetch();
360 $rowids = array_shift($fvals);
361 $lastvals = array_shift($fvals);
362 foreach (array_keys($upvals, 'L') as $akey) {
363 $upvals[$akey] = $key_names?$lastvals[$akey]:$lastvals[$rowids[$akey]];
364 }
365 }
366 $walkfunc = create_function('&$val,$key', '$val = is_numeric(trim($val))?trim($val):"U";');
367 array_walk($upvals, $walkfunc);
368 $return = null;
369 if (count($upvals)) {
370 $update_cmd = 'rrdtool update '.$this->rrd_file.($key_names?' --template '.implode(':', array_keys($upvals)):'').' N:'.implode(':', $upvals);
371 $return = `$update_cmd 2>&1`;
372 }
373
374 if (strpos($return, 'ERROR') !== false) {
375 trigger_error($this->rrd_file.' - rrd update error: '.$return, E_USER_WARNING);
376 $success = false;
377 }
378 else { $success = true; }
379 return $success;
380 }
381
382 function fetch($cf = 'AVERAGE', $resolution = null, $start = null, $end = null) {
383 // fetch data from a RRD
384 if (!in_array($this->status, array('ok','readonly'))) { trigger_error('Error: rrd status is '.$this->status, E_USER_WARNING); return false; }
385
386 if (!in_array($cf, array('AVERAGE','MIN','MAX','LAST'))) { $cf = 'AVERAGE'; }
387 if (!is_numeric($resolution)) { $resolution = $this->rrd_step; }
388 if (!is_numeric($end)) { $end = $this->last_update(); }
389 elseif ($end < 0) { $end += $this->last_update(); }
390 $end = intval($end/$resolution)*$resolution;
391 if (!is_numeric($start)) { $start = $end; }
392 elseif ($start < 0) { $start += $end; }
393 $start = intval($start/$resolution)*$resolution;
394
395 $fetch_cmd = 'rrdtool fetch '.$this->rrd_file.' '.$cf.' --resolution '.$resolution.' --start '.$start.' --end '.$end;
396 $return = `$fetch_cmd 2>&1`;
397
398 if (strpos($return, 'ERROR') !== false) {
399 trigger_error($this->rrd_file.' - rrd fetch error: '.$return, E_USER_WARNING);
400 $fresult = false;
401 }
402 else {
403 $fresult = array();
404 $rows = explode("\n", $return);
405 $fields = preg_split('/\s+/', array_shift($rows));
406 if (array_shift($fields) == 'timestamp') {
407 $fresult[0] = $fields;
408 foreach ($rows as $row) {
409 if (strlen(trim($row))) {
410 $rvals = preg_split('/\s+/', $row);
411 $rtime = str_replace(':', '', array_shift($rvals));
412 $rv_array = array();
413 foreach ($rvals as $key=>$rval) {
414 $rv_array[$fields[$key]] = ($rval=='nan')?null:floatval($rval);
415 }
416 $fresult[$rtime] = $rv_array;
417 }
418 }
419 }
420 }
421 return $fresult;
422 }
423
424 function last_update() {
425 // fetch time of last update in this RRD file
426 static $last_update;
427 if (!isset($last_update) && in_array($this->status, array('ok','readonly'))) {
428 $last_cmd = 'rrdtool last '.$this->rrd_file;
429 $return = trim(`$last_cmd 2>&1`);
430 $last_update = is_numeric($return)?$return:null;
431 }
432 return isset($last_update)?$last_update:null;
433 }
434
435 function graph($timeframe = 'day', $sub = null, $extra = null) {
436 // create a RRD graph
437 static $gColors;
438 if (!isset($gColors)) {
439 $gColors = array('#00CC00','#0000FF','#000000','#FF0000','#00FF00','#FFFF00','#FF00FF','#00FFFF','#808080','#800000','#008000','#000080','#808000','#800080','#008080','#C0C0C0');
440 }
441
442 if (!in_array($this->status, array('ok','readonly','graphonly'))) { trigger_error('Error: rrd status is '.$this->status, E_USER_WARNING); return false; }
443
444 // assemble configuration
445 $gconf = (array)$extra;
446 if (!is_null($sub) && is_array($this->config_raw['graph.'.$sub])) {
447 $gconf = $gconf + $this->config_raw['graph.'.$sub];
448 }
449 $gconf = $gconf + (array)$this->config_graph;
450
451 if (isset($gconf['format']) && ($gconf['format'] == 'SVG')) {
452 $format = $gconf['format']; $fmt_ext = '.svg';
453 }
454 elseif (isset($gconf['format']) && ($gconf['format'] == 'EPS')) {
455 $format = $gconf['format']; $fmt_ext = '.eps';
456 }
457 elseif (isset($gconf['format']) && ($gconf['format'] == 'PDF')) {
458 $format = $gconf['format']; $fmt_ext = '.pdf';
459 }
460 else {
461 $format = 'PNG'; $fmt_ext = '.png';
462 }
463
464 if (isset($gconf['filename'])) { $fname = $gconf['filename']; }
465 else { $fname = $this->basename.(is_null($sub)?'':'-%s').'-%t%f'; }
466 $fname = str_replace('%s', strval($sub), $fname);
467 $fname = str_replace('%t', $timeframe, $fname);
468 $fname = str_replace('%f', $fmt_ext, $fname);
469 if (substr($fname, -strlen($fmt_ext)) != $fmt_ext) { $fname .= $fmt_ext; }
470 if (isset($gconf['path']) && ($fname{0} != '/')) { $fname = $gconf['path'].'/'.$fname; }
471 if ($fname{0} != '/') { $fname = $this->basedir.$fname; }
472 $fname = str_replace('//', '/', $fname);
473
474 $graphrows = array(); $specialrows = array(); $gC = 0;
475 $gDefs = ''; $gGraphs = ''; $addSpecial = '';
476
477 if ($timeframe == 'day') {
478 $duration = isset($gconf['duration'])?$gconf['duration']:30*3600; // 30 hours
479 $slice = isset($gconf['slice'])?$gconf['slice']:300; // 5 minutes
480 // vertical lines at day borders
481 $addSpecial .= ' VRULE:'.strtotime(date('Y-m-d')).'#FF0000';
482 $addSpecial .= ' VRULE:'.strtotime(date('Y-m-d').' -1 day').'#FF0000';
483 if (!isset($gconf['grid_x'])) { $gconf['grid_x'] = 'HOUR:1:HOUR:6:HOUR:2:0:%-H'; }
484 }
485 elseif ($timeframe == 'week') {
486 $duration = isset($gconf['duration'])?$gconf['duration']:8*86400; // 8 days
487 $slice = isset($gconf['slice'])?$gconf['slice']:1800; // 30 minutes
488 // vertical lines at week borders
489 $addSpecial .= ' VRULE:'.strtotime(date('Y-m-d').' '.(-date('w')+1).' day').'#FF0000';
490 $addSpecial .= ' VRULE:'.strtotime(date('Y-m-d').' '.(-date('w')-6).' day').'#FF0000';
491 }
492 elseif ($timeframe == 'month') {
493 $duration = isset($gconf['duration'])?$gconf['duration']:36*86400; // 36 days
494 $slice = isset($gconf['slice'])?$gconf['slice']:7200; // 2 hours
495 // vertical lines at month borders
496 $addSpecial .= ' VRULE:'.strtotime(date('Y-m-01')).'#FF0000';
497 $addSpecial .= ' VRULE:'.strtotime(date('Y-m-01').' -1 month').'#FF0000';
498 }
499 elseif ($timeframe == 'year') {
500 $duration = isset($gconf['duration'])?$gconf['duration']:396*86400; // 365+31 days
501 $slice = isset($gconf['slice'])?$gconf['slice']:86400; // 1 day
502 // vertical lines at month borders
503 $addSpecial .= ' VRULE:'.strtotime(date('Y-01-01 12:00:00')).'#FF0000';
504 $addSpecial .= ' VRULE:'.strtotime(date('Y-01-01 12:00:00').' -1 year').'#FF0000';
505 }
506 else {
507 $duration = isset($gconf['duration'])?$gconf['duration']:$this->rrd_step*500; // 500 steps
508 $slice = isset($gconf['slice'])?$gconf['slice']:$this->rrd_step; // whatever our step is
509 }
510
511 if (isset($gconf['rows']) && count($gconf['rows'])) {
512 foreach ($gconf['rows'] as $erow) {
513 if (isset($erow['name']) && strlen($erow['name'])) {
514 if (!isset($erow['scale']) && isset($gconf['scale'])) { $erow['scale'] = $gconf['scale']; }
515 $grow = array();
516 $grow['dType'] = isset($erow['dType'])?$erow['dType']:'DEF';
517 $grow['name'] = $erow['name'].(isset($erow['scale'])?'_tmp':'');
518 if ($grow['dType'] == 'DEF') {
519 $grow['dsname'] = isset($erow['dsname'])?$erow['dsname']:$erow['name'];
520 if (isset($erow['dsfile'])) { $grow['dsfile'] = $erow['dsfile']; }
521 $grow['cf'] = isset($erow['cf'])?$erow['cf']:'AVERAGE';
522 }
523 else {
524 $grow['rpn_expr'] = isset($erow['rpn_expr'])?$erow['rpn_expr']:'0';
525 }
526 if (isset($erow['scale'])) {
527 $graphrows[] = $grow;
528 $grow = array();
529 $grow['dType'] = 'CDEF';
530 $grow['name'] = $erow['name'];
531 $grow['rpn_expr'] = $erow['name'].'_tmp,'.$erow['scale'].',*';
532 }
533 $grow['gType'] = isset($erow['gType'])?$erow['gType']:'LINE1';
534 $grow['color'] = isset($erow['color'])?$erow['color']:$gColors[$gC++];
535 if ($gC >= count($gColors)) { $gC = 0; }
536 if (isset($erow['legend'])) {
537 $grow['legend'] = $erow['legend'];
538 if (!isset($gconf['show_legend'])) { $gconf['show_legend'] = true; }
539 }
540 if (isset($erow['stack'])) { $grow['stack'] = ($erow['stack'] == true); }
541 if (isset($erow['desc'])) { $grow['desc'] = $erow['desc']; }
542 $graphrows[] = $grow;
543 }
544 }
545 }
546 else {
547 foreach ($this->rrd_fields as $key=>$ds) {
548 $grow = array();
549 $grow['dType'] = 'DEF';
550 $grow['name'] = $ds['name'].(isset($gconf['scale'])?'_tmp':'');
551 $grow['dsname'] = $ds['name'];
552 $grow['cf'] = 'AVERAGE';
553 if (isset($gconf['scale'])) {
554 $graphrows[] = $grow;
555 $grow = array();
556 $grow['dType'] = 'CDEF';
557 $grow['name'] = $ds['name'];
558 $grow['rpn_expr'] = $ds['name'].'_tmp,'.$gconf['scale'].',*';
559 }
560 $grow['gType'] = ((count($this->rrd_fields)==2) && ($key==0))?'AREA':'LINE1';
561 $grow['color'] = $gColors[$gC++]; if ($gC >= count($gColors)) { $gC = 0; }
562 if (isset($ds['legend'])) {
563 $grow['legend'] = $ds['legend'];
564 if (!isset($gconf['show_legend'])) { $gconf['show_legend'] = true; }
565 }
566 if (isset($ds['desc'])) { $grow['desc'] = $ds['desc']; }
567 $graphrows[] = $grow;
568 }
569 }
570
571 if (isset($gconf['special']) && count($gconf['special'])) {
572 foreach ($gconf['special'] as $crow) {
573 $srow = array();
574 $srow['sType'] = isset($crow['sType'])?$crow['sType']:'COMMENT';
575 if ($grow['sType'] != 'COMMENT') {
576 // XXX: use line below and remove cf var once we have rrdtol 1.2
577 // $srow['name'] = $crow['name'].(isset($crow['cf'])?'_'.$crow['cf']:'');
578 $srow['name'] = $crow['name'];
579 $srow['cf'] = isset($crow['cf'])?$crow['cf']:'AVERAGE';
580 if (isset($crow['cf'])) {
581 // XXX: use line below once we have rrdtol 1.2
582 // $graphrows[] = array('dType'=>'VDEF', 'name'=>$srow['name'].'_'.$crow['cf'], 'rpn_expr'=>$srow['name'].','.$crow['cf']);
583 }
584 elseif (isset($crow['rpn_expr'])) {
585 // XXX: does only work with rrdtool 1.2
586 $graphrows[] = array('dType'=>'VDEF', 'name'=>$srow['name'], 'rpn_expr'=>$crow['rpn_expr']);
587 }
588 }
589 $srow['text'] = isset($crow['text'])?$crow['text']:'';
590 $specialrows[] = $srow;
591 }
592 }
593 else {
594 foreach ($graphrows as $grow) {
595 if (isset($grow['gType']) && strlen($grow['gType'])) {
596 $textprefix = isset($grow['desc'])?$grow['desc']:(isset($grow['legend'])?$grow['legend']:$grow['name']);
597 // XXX: use lines below once we have rrdtol 1.2
598 // $graphrows[] = array('dType'=>'VDEF', 'name'=>$grow['name'].'_last', 'rpn_expr'=>$grow['name'].',LAST');
599 // $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'].'_last', 'text'=>'%3.2lf%s');
600 $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'MAX', 'text'=>$textprefix.'|Maximum|%.2lf%s');
601 $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'AVERAGE', 'text'=>$textprefix.'|Average|%.2lf%s');
602 $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'LAST', 'text'=>$textprefix.'|Current|%.2lf%s');
603 }
604 }
605 }
606
607 $endtime = isset($gconf['time_end'])?$gconf['time_end']:(is_numeric($this->last_update())?$this->last_update():time());
608 $gOpts = ' --start '.($endtime-$duration).' --end '.$endtime.' --step '.$slice;
609 if (isset($gconf['label_top'])) { $gOpts .= ' --title '.$this->text_quote($gconf['label_top']); }
610 if (isset($gconf['label_y'])) { $gOpts .= ' --vertical-label '.$this->text_quote($gconf['label_y']); }
611 if (isset($gconf['width'])) { $gOpts .= ' --width '.$gconf['width']; }
612 if (isset($gconf['height'])) { $gOpts .= ' --height '.$gconf['height'];
613 if (($gconf['height'] <= 32) && isset($gconf['thumb']) && ($gconf['thumb'])) { $gOpts .= ' --only-graph'; }
614 }
615 if (!isset($gconf['show_legend']) || (!$gconf['show_legend'])) { $gOpts .= ' --no-legend'; }
616 if (isset($gconf['min_y'])) { $gOpts .= ' --lower-limit '.$gconf['min_y']; }
617 if (isset($gconf['max_y'])) { $gOpts .= ' --upper-limit '.$gconf['max_y']; }
618 if (isset($gconf['fix_scale_y']) && $gconf['fix_scale_y']) { $gOpts .= ' --rigid'; }
619 if (isset($gconf['grid_x'])) { $gOpts .= ' --x-grid '.$gconf['grid_x']; }
620 if (isset($gconf['grid_y'])) { $gOpts .= ' --y-grid '.$gconf['grid_y']; }
621 if (isset($gconf['units_exponent'])) { $gOpts .= ' --units-exponent '.$gconf['units_exponent']; }
622 if (isset($gconf['units_length'])) { $gOpts .= ' --units-length '.$gconf['units_length']; }
623 if (!isset($gconf['force_recreate']) || (!$gconf['force_recreate'])) { $gOpts .= ' --lazy'; }
624 if (isset($gconf['force_color']) && is_array($gconf['force_color'])) {
625 foreach ($gconf['force_color'] as $ctag=>$cval) { $gOpts .= ' --color '.$ctag.$cval; }
626 }
627 if (isset($gconf['force_font']) && is_array($gconf['force_font'])) {
628 foreach ($gconf['force_font'] as $ctag=>$cval) { $gOpts .= ' --font '.$ctag.$cval; }
629 }
630 if (isset($gconf['units_binary']) && $gconf['units_binary']) { $gOpts .= ' --base 1024'; }
631
632 foreach ($graphrows as $grow) {
633 if (isset($grow['dType']) && strlen($grow['dType'])) {
634 $gDefs .= ' '.$grow['dType'].':'.$grow['name'].'=';
635 if ($grow['dType'] == 'DEF') {
636 $gDefs .= isset($grow['dsfile'])?$grow['dsfile']:$this->rrd_file;
637 $gDefs .= ':'.$grow['dsname'].':'.$grow['cf'];
638 }
639 else { $gDefs .= $grow['rpn_expr']; }
640 }
641 if (isset($grow['gType']) && strlen($grow['gType'])) {
642 // XXX: change from STACK type to STACK flag once we have rrdtool 1.2
643 if (isset($grow['stack']) && $grow['stack']) { $grow['gType'] = 'STACK'; }
644 $gGraphs .= ' '.$grow['gType'].':'.$grow['name'].$grow['color'];
645 if (isset($grow['legend'])) { $gGraphs .= ':'.$this->text_quote($grow['legend']); }
646 // XXX: remove above STACK if-command and uncomment the one below once we have rrdtool 1.2
647 //if (isset($grow['stack']) && $grow['stack']) { $gGraphs .= ':STACK'; }
648 }
649 }
650
651 foreach ($specialrows as $srow) {
652 $addSpecial .= ' '.$srow['sType'];
653 // XXX: eliminate cf once we have rrdtool 1.2
654 // $addSpecial .= ($grow['sType']!='COMMENT')?':'.$grow['name']:'');
655 $addSpecial .= (($srow['sType']!='COMMENT')?':'.$srow['name'].':'.$srow['cf']:'');
656 $addSpecial .= ':'.$this->text_quote($srow['text']);
657 }
658
659 $graph_cmd = 'rrdtool graph '.str_replace('*', '\*', $fname.$gOpts.$gDefs.$gGraphs.$addSpecial);
660 $return = `$graph_cmd 2>&1`;
661
662 if (strpos($return, 'ERROR') !== false) {
663 trigger_error($this->rrd_file.' - rrd graph error: '.$return, E_USER_WARNING);
664 $return = $graph_cmd."\n\n".$return;
665 }
666 $return = 'file:'.$fname."\n".$return;
667 return $return;
668 }
669
670 function graph_plus($timeframe = 'day', $sub = null, $extra = null) {
671 // create a RRD graph and return meta info as a ready-to-use array
672 $gmeta = array('filename'=>null);
673 $ret = $this->graph($timeframe, $sub, $extra);
674 if (strpos($ret, "\n\n") !== false) { $gmeta['graph_cmd'] = substr($ret, 0, strpos($ret, "\n\n")); $ret = substr($ret, strpos($ret, "\n\n")+2); }
675 else { $gmeta['graph_cmd'] = null; }
676 $grout = explode("\n", $ret);
677 foreach ($grout as $gline) {
678 if (preg_match('/^file:(.+)$/', $gline, $regs)) {
679 $gmeta['filename'] = $regs[1];
680 }
681 elseif (preg_match('/^(\d+)x(\d+)$/', $gline, $regs)) {
682 $gmeta['width'] = $regs[1]; $gmeta['height'] = $regs[2];
683 }
684 elseif (preg_match('/^([^\|]+)\|([^|]+)\|([^\|]*)$/', $gline, $regs)) {
685 $gmeta['data'][$regs[1]][$regs[2]] = $regs[3];
686 }
687 elseif (preg_match('/^([^\|]+)\|([^\|]*)$/', $gline, $regs)) {
688 $gmeta['var'][$regs[1]] = $regs[2];
689 }
690 elseif (strlen(trim($gline))) {
691 $gmeta['info'][] = $gline;
692 }
693 }
694 if (is_null($gmeta['filename'])) {
695 $gmeta['filename'] = $this->basename.(!is_null($sub)?'-'.$sub:'').'-'.$timeframe.'.png';
696 }
697 return $gmeta;
698 }
699
700 function page($sub = null, $page_extras = null, $graph_extras = null) {
701 // create a (HTML) page and return it in a string
702
703 // assemble configuration
704 $pconf = (array)$page_extras;
705 if (!is_null($sub) && is_array($this->config_raw['page.'.$sub])) {
706 $pconf = $pconf + $this->config_raw['page.'.$sub];
707 }
708 $pconf = $pconf + (array)$this->config_page;
709
710 $return = null;
711 switch (@$pconf['type']) {
712 case 'index':
713 $return = $this->page_index($pconf);
714 break;
715 case 'overview':
716 $return = $this->page_overview($pconf, $graph_extras);
717 break;
718 case 'simple':
719 default:
720 $return = $this->page_simple($pconf, $graph_extras);
721 break;
722 }
723 return $return;
724 }
725
726 function simple_html($sub = null, $page_extras = null, $graph_extras = null) {
727 // create a simple (MRTG-like) HTML page and return it in a string
728 // XXX: this is here temporarily for compat only, it's preferred to use page()!
729
730 // assemble configuration
731 $pconf = (array)$page_extras;
732 if (!is_null($sub) && is_array($this->config_raw['page.'.$sub])) {
733 $pconf = $pconf + $this->config_raw['page.'.$sub];
734 }
735 $pconf = $pconf + (array)$this->config_page;
736
737 return $this->page_simple($pconf, $graph_extras);
738 }
739
740 function page_index($pconf) {
741 // create a bare, very simple index list HTML page and return it in a string
742
743 $ptitle = isset($pconf['title_page'])?$pconf['title_page']:'RRD statistics index';
744
745 $out = '<html><head>';
746 $out .= '<title>'.$ptitle.'</title>';
747 $out .= '<style>';
748 if (isset($pconf['style_base'])) { $out .= $pconf['style_base']; }
749 else {
750 $out .= 'h1 { font-weight: bold; font-size: 1.5em; }';
751 $out .= '.footer { font-size: 0.75em; margin: 0.5em 0; }';
752 $out .= 'li.scanfile { font-style: italic; }';
753 }
754 if (isset($pconf['style'])) { $out .= $pconf['style']; }
755 $out .= '</style>';
756 $out .= '</head>';
757 $out .= '<body>';
758
759 $out .= '<h1>'.$ptitle.'</h1>';
760 if (isset($pconf['text_intro']) && strlen($pconf['text_intro'])) {
761 $out .= '<p class="intro">'.$pconf['text_intro'].'</p>';
762 }
763 elseif (!isset($pconf['text_intro'])) {
764 $out .= '<p class="intro">The following RRD stats are available:</p>';
765 }
766
767 $stats = $this->h_page_statsArray($pconf);
768
769 if (isset($pconf['stats_url'])) { $sURL_base = $pconf['stats_url']; }
770 else { $sURL_base = '?stat=%i%a'; }
771
772 if (isset($pconf['stats_url_add'])) { $sURL_add = $pconf['stats_url_add']; }
773 else { $sURL_add = '&sub=%s'; }
774
775 $out .= '<ul class="indexlist">';
776 foreach ($stats as $stat) {
777 $out .= '<li'.(isset($stat['class'])?' class="'.$stat['class'].'"':'').'>';
778 $sURL = str_replace('%i', $stat['name'], $sURL_base);
779 $sURL = str_replace('%a', '', $sURL);
780 $sURL = str_replace('%s', '', $sURL);
781 $out .= '<a href="'.$sURL.'">'.$stat['name'].'</a>';
782 if (isset($stat['sub']) && count($stat['sub'])) {
783 $sprt = array();
784 foreach ($stat['sub'] as $ssub) {
785 $sURL = str_replace('%i', $stat['name'], $sURL_base);
786 $sURL = str_replace('%a', $sURL_add, $sURL);
787 $sURL = str_replace('%s', $ssub, $sURL);
788 $sprt[] = '<a href="'.$sURL.'">'.$ssub.'</a>';
789 }
790 $out .= ' <span="subs">('.implode(', ', $sprt).')</span>';
791 }
792 $out .= '</li>';
793 }
794 $out .= '</ul>';
795
796 $out .= $this->h_page_footer();
797 $out .= '</body></html>';
798 return $out;
799 }
800
801 function page_overview($pconf, $graph_extras = null) {
802 // create an overview HTML page (including graphs) and return it in a string
803
804 $ptitle = isset($pconf['title_page'])?$pconf['title_page']:'RRD statistics overview';
805
806 $out = '<html><head>';
807 $out .= '<title>'.$ptitle.'</title>';
808 $out .= '<style>';
809 if (isset($pconf['style_base'])) { $out .= $pconf['style_base']; }
810 else {
811 $out .= 'h1 { font-weight: bold; font-size: 1.5em; }';
812 $out .= 'h2 { font-weight: bold; font-size: 1em; margin: 0.5em 0; }';
813 $out .= '.footer { font-size: 0.75em; margin: 0.5em 0; }';
814 $out .= 'img.rrdgraph { border: none; }';
815 }
816 if (isset($pconf['style'])) { $out .= $pconf['style']; }
817 $out .= '</style>';
818 $out .= '</head>';
819 $out .= '<body>';
820
821 $out .= '<h1>'.$ptitle.'</h1>';
822 if (isset($pconf['text_intro'])) { $out .= '<p class="intro">'.$pconf['text_intro'].'</p>'; }
823
824 $stats = $this->h_page_statsArray($pconf);
825
826 $num_rows = is_numeric($pconf['num_rows'])?$pconf['num_rows']:2;
827 $num_cols = ceil(count($stats)/$num_rows);
828
829 $out .= '<table class="overview">';
830 for ($col = 0; $col < $num_cols; $col++) {
831 $out .= '<tr>';
832 for ($row = 0; $row < $num_rows; $row++) {
833 $idx = $col * $num_rows + $row;
834 $out .= '<td>';
835 if ($idx < count($stats)) {
836 list($sname, $s_psub) = explode('|', $stats[$idx]['name'], 2);
837 $s_psname = 'page'.(isset($s_psub)?'.'.$s_psub:'');
838 $g_sub = $this->config_all[$sname][$s_psname]['graph_sub'];
839
840 if (isset($this->config_all[$sname][$s_psname]['title_page'])) {
841 $s_ptitle = $this->config_all[$sname][$s_psname]['title_page'];
842 }
843 elseif (isset($this->config_all[$sname]['page']['title_page'])) {
844 $s_ptitle = $this->config_all[$sname]['page']['title_page'];
845 }
846 else {
847 $s_ptitle = $sname.(isset($s_psub)?' ('.$s_psub.')':'').' statistics';
848 }
849 if (!isset($pconf['hide_titles']) || !$pconf['hide_titles']) {
850 $out .= '<h2>'.$s_ptitle.'</h2>';
851 }
852
853 $s_rrd = new rrdstat($this->config_all, $sname);
854 if (in_array($s_rrd->status, array('ok','readonly','graphonly'))) {
855 $tframe = isset($pconf['graph_timeframe'])?$pconf['graph_timeframe']:'day';
856 $gmeta = $s_rrd->graph_plus($tframe, $g_sub);
857 if (isset($pconf['graph_url'])) {
858 $gURL = $pconf['graph_url'];
859 $fname = str_replace('%f', basename($gmeta['filename']), $gURL);
860 $fname = str_replace('%p', $gmeta['filename'], $gURL);
861 if (substr($gURL, -1) == '/') { $gURL .= $gmeta['filename']; }
862 }
863 else {
864 $gURL = $gmeta['filename'];
865 }
866 $out .= '<a href="?stat='.$sname.(isset($s_psub)?'&sub='.$s_psub:'').'"';
867 $out .= '<img src="'.$gURL.'"';
868 $out .= ' alt="'.$s_rrd->basename.(!is_null($g_sub)?' - '.$g_sub:'').' - '.$tframe.'" class="rrdgraph"';
869 $out .= ' style="width:'.$gmeta['width'].'px;height:'.$gmeta['height'].'px;">';
870 $out .= '</a>';
871 }
872 else {
873 $out .= 'RRD error: status is "'.$s_rrd->status.'"';
874 }
875 }
876 else {
877 $out .= '&nbsp;';
878 }
879 $out .= '</td>';
880 }
881 $out .= '</tr>';
882 }
883 $out .= '</table>';
884
885 $out .= $this->h_page_footer();
886 $out .= '</body></html>';
887 return $out;
888 }
889
890 function page_simple($pconf, $graph_extras = null) {
891 // create a simple (MRTG-like) HTML page and return it in a string
892
893 $ptitle = isset($pconf['title_page'])?$pconf['title_page']:$this->basename.' - RRD statistics';
894 $gtitle = array();
895 $gtitle['day'] = isset($pconf['title_day'])?$pconf['title_day']:'Day overview (scaling 5 minutes)';
896 $gtitle['week'] = isset($pconf['title_week'])?$pconf['title_week']:'Week overview (scaling 30 minutes)';
897 $gtitle['month'] = isset($pconf['title_month'])?$pconf['title_month']:'Month overview (scaling 2 hours)';
898 $gtitle['year'] = isset($pconf['title_year'])?$pconf['title_year']:'Year overview (scaling 1 day)';
899
900 $out = '<html><head>';
901 $out .= '<title>'.$ptitle.'</title>';
902 $out .= '<style>';
903 if (isset($pconf['style_base'])) { $out .= $pconf['style_base']; }
904 else {
905 $out .= 'h1 { font-weight: bold; font-size: 1.5em; }';
906 $out .= 'h2 { font-weight: bold; font-size: 1em; }';
907 $out .= '.gdata, .gvar, .ginfo { font-size: 0.75em; margin: 0.5em 0; }';
908 $out .= 'table.gdata { border: 1px solid gray; border-collapse: collapse; }';
909 $out .= 'table.gdata td, table.gdata th { border: 1px solid gray; padding: 0.1em 0.2em; }';
910 $out .= '.footer { font-size: 0.75em; margin: 0.5em 0; }';
911 }
912 if (isset($pconf['style'])) { $out .= $pconf['style']; }
913 $out .= '</style>';
914 $out .= '</head>';
915 $out .= '<body>';
916
917 $out .= '<h1>'.$ptitle.'</h1>';
918 if (!isset($pconf['show_update']) || $pconf['show_update']) {
919 $out .= '<p class="last_up">Last Update: '.(is_null($this->last_update())?'unknown':date('Y-m-d H:i:s', $this->last_update())).'</p>';
920 }
921
922 $g_sub = isset($pconf['graph_sub'])?$pconf['graph_sub']:null;
923 if (in_array($this->status, array('ok','readonly','graphonly'))) {
924 foreach (array('day','week','month','year') as $tframe) {
925 $gmeta = $this->graph_plus($tframe, $g_sub, $graph_extras);
926 if (isset($pconf['graph_url'])) {
927 $gURL = $pconf['graph_url'];
928 $gURL = str_replace('%f', basename($gmeta['filename']), $gURL);
929 $gURL = str_replace('%p', $gmeta['filename'], $gURL);
930 if (substr($gURL, -1) == '/') { $gURL .= $gmeta['filename']; }
931 }
932 else {
933 $gURL = $gmeta['filename'];
934 }
935 $out .= '<div class="'.$tframe.'">';
936// $out .= '<p>'.nl2br($ret).'</p>';
937 $out .= '<h2>'.$gtitle[$tframe].'</h2>';
938 $out .= '<img src="'.$gURL.'"';
939 $out .= ' alt="'.$this->basename.(!is_null($g_sub)?' - '.$g_sub:'').' - '.$tframe.'" class="rrdgraph"';
940 if (isset($gmeta['width']) && isset($gmeta['height'])) { $out .= ' style="width:'.$gmeta['width'].'px;height:'.$gmeta['height'].'px;"'; }
941 $out .= '>';
942 if (isset($gmeta['data']) && count($gmeta['data'])) {
943 $out .= '<table class="gdata">';
944 foreach ($gmeta['data'] as $field=>$gdata) {
945 $out .= '<tr><th>'.$field.'</th>';
946 foreach ($gdata as $gkey=>$gval) {
947 $out .= '<td><span class="gkey">'.$gkey.': </span>'.$gval.'</td>';
948 }
949 $out .= '</tr>';
950 }
951 $out .= '</table>';
952 }
953 if (isset($gmeta['var']) && count($gmeta['var'])) {
954 foreach ($gmeta['var'] as $gkey=>$gval) {
955 $out .= '<p class="gvar"><span class="gkey">'.$gkey.': </span>'.$gval.'</p>';
956 }
957 }
958 if (isset($gmeta['info']) && count($gmeta['info'])) {
959 foreach ($gmeta['info'] as $gval) {
960 $out .= '<p class="ginfo">'.$gval.'</p>';
961 }
962 }
963 $out .= '</div>';
964 }
965 }
966 else {
967 $out .= 'RRD error: status is "'.$this->status.'"';
968 }
969
970 $out .= $this->h_page_footer();
971 $out .= '</body></html>';
972 return $out;
973 }
974
975 function h_page_statsArray($pconf) {
976 // return array of stats to list on a page
977 $stats = array();
978 $snames = array(); $s_exclude = array(); $sfiles = array();
979 if (isset($pconf['index_ids'])) {
980 foreach (explode(',', $pconf['index_ids']) as $iid) {
981 if ($iid{0} == '-') { $s_exclude[] = substr($iid, 1); }
982 else { $snames[] = $iid; }
983 }
984 }
985 if (!isset($pconf['scan_config']) || $pconf['scan_config']) {
986 foreach ($this->config_all as $iname=>$rinfo) {
987 if (($iname != '*') && !(isset($rinfo['hidden']) && $rinfo['hidden']) &&
988 !(in_array($iname, $snames)) && !(in_array($iname, $s_exclude))) {
989 $snames[] = $iname;
990 }
991 }
992 }
993 foreach ($snames as $iname) {
994 $newstat = array('name'=>$iname);
995 $sfiles[] = isset($this->config_all[$iname]['file'])?$this->config_all[$iname]['file']:$iname.'.rrd';
996 if (is_array($this->config_all[$iname])) {
997 foreach ($this->config_all[$iname] as $key=>$val) {
998 if (substr($key, 0, 5) == 'page.') { $newstat['sub'][] = substr($key, 5); }
999 }
1000 }
1001 $stats[] = $newstat;
1002 }
1003 if (isset($pconf['scan_files']) && $pconf['scan_files']) {
1004 $rrdfiles = glob('*.rrd');
1005 foreach ($rrdfiles as $rrdfile) {
1006 $iname = (substr($rrdfile, -4) == '.rrd')?substr($rrdfile, 0, -4):$rrdfile;
1007 if (!in_array($rrdfile, $sfiles) && !(in_array($iname, $s_exclude))) {
1008 $stats[] = array('name'=>$iname, 'class'=>'scanfile');
1009 }
1010 }
1011 }
1012 return $stats;
1013 }
1014
1015 function h_page_footer() {
1016 // return generic page footer
1017 $out = '<p class="footer">';
1018 $out .= 'Statistics created by <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/">RRDtool</a>';
1019 $out .= ' using a library created by <a href="http://www.kairo.at/">KaiRo.at</a>.';
1020 $out .= '</p>';
1021 return $out;
1022 }
1023
1024 function text_quote($text) { return '"'.str_replace('"', '\"', str_replace(':', '\:', $text)).'"'; }
1025}
1026?>