From f5e899dff253a61864949d7596252b2163920c2c Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 18 May 2005 20:52:37 +0000 Subject: [PATCH] support overview pages, outsource some common page elements into seperate shared functions, support a graph_plus command that returns an array of info instead of a flat string --- include/classes/rrdstat.php-class | 274 +++++++++++++++++++++--------- 1 file changed, 189 insertions(+), 85 deletions(-) diff --git a/include/classes/rrdstat.php-class b/include/classes/rrdstat.php-class index 6b241c7..2fc1de1 100644 --- a/include/classes/rrdstat.php-class +++ b/include/classes/rrdstat.php-class @@ -263,6 +263,17 @@ class rrdstat { return $fresult; } + function last_update() { + // fetch time of last update in this RRD file + static $last_update; + if (!isset($last_update) && in_array($this->status, array('ok','readonly'))) { + $last_cmd = 'rrdtool last '.$this->rrd_file; + $return = trim(`$last_cmd 2>&1`); + $last_update = is_numeric($return)?$return:null; + } + return isset($last_update)?$last_update:null; + } + function graph($timeframe = 'day', $sub = null, $extra = null) { // create a RRD graph static $gColors; @@ -492,6 +503,36 @@ class rrdstat { return $return; } + function graph_plus($timeframe = 'day', $sub = null, $extra = null) { + // create a RRD graph and return meta info as a ready-to-use array + $gmeta = array('filename'=>null); + $ret = $this->graph($timeframe, $sub, $extra); + if (strpos($ret, "\n\n") !== false) { $gmeta['graph_cmd'] = substr($ret, 0, strpos($ret, "\n\n")); $ret = substr($ret, strpos($ret, "\n\n")+2); } + else { $gmeta['graph_cmd'] = null; } + $grout = explode("\n", $ret); + foreach ($grout as $gline) { + if (preg_match('/^file:(.+)$/', $gline, $regs)) { + $gmeta['filename'] = $regs[1]; + } + elseif (preg_match('/^(\d+)x(\d+)$/', $gline, $regs)) { + $gmeta['width'] = $regs[1]; $gmeta['height'] = $regs[2]; + } + elseif (preg_match('/^([^\|]+)\|([^|]+)\|([^\|]*)$/', $gline, $regs)) { + $gmeta['data'][$regs[1]][$regs[2]] = $regs[3]; + } + elseif (preg_match('/^([^\|]+)\|([^\|]*)$/', $gline, $regs)) { + $gmeta['var'][$regs[1]] = $regs[2]; + } + elseif (strlen(trim($gline))) { + $gmeta['info'][] = $gline; + } + } + if (is_null($gmeta['filename'])) { + $gmeta['filename'] = $this->basename.(!is_null($sub)?'-'.$sub:'').'-'.$timeframe.'.png'; + } + return $gmeta; + } + function page($sub = null, $page_extras = null, $graph_extras = null) { // create a (HTML) page and return it in a string @@ -535,7 +576,7 @@ class rrdstat { function page_index($pconf) { // create a bare, very simple index list HTML page and return it in a string - $ptitle = isset($pconf['title_page'])?$pconf['title_page']:'Index - RRD statistics'; + $ptitle = isset($pconf['title_page'])?$pconf['title_page']:'RRD statistics index'; $out = ''; $out .= ''.$ptitle.''; @@ -552,42 +593,16 @@ class rrdstat { $out .= ''; $out .= '

'.$ptitle.'

'; - $out .= '

The following RRD stats are available:

'; - - $out .= '