From 16cc643cc2824472ce0751b16291c075daffae7a Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 6 May 2005 15:14:28 +0000 Subject: [PATCH] retrieve further info from graph and use it for display in web page --- include/classes/rrdstat.php-class | 134 +++++++++++++++++++++++++++--- 1 file changed, 124 insertions(+), 10 deletions(-) diff --git a/include/classes/rrdstat.php-class b/include/classes/rrdstat.php-class index 6888729..7313042 100644 --- a/include/classes/rrdstat.php-class +++ b/include/classes/rrdstat.php-class @@ -272,9 +272,13 @@ class rrdstat { $grow = array(); $grow['dType'] = isset($erow['dType'])?$erow['dType']:'DEF'; $grow['name'] = $erow['name'].(isset($erow['scale'])?'_tmp':''); - $grow['dsname'] = isset($erow['dsname'])?$erow['dsname']:$erow['name']; - $grow['cf'] = isset($erow['cf'])?$erow['cf']:'AVERAGE'; - if (isset($erow['rpn_expr'])) { $grow['rpn_expr'] = $erow['rpn_expr']; } + if ($grow['dType'] == 'DEF') { + $grow['dsname'] = isset($erow['dsname'])?$erow['dsname']:$erow['name']; + $grow['cf'] = isset($erow['cf'])?$erow['cf']:'AVERAGE'; + } + else { + $grow['rpn_expr'] = isset($erow['rpn_expr'])?$erow['rpn_expr']:'0'; + } if (isset($erow['scale'])) { $graphrows[] = $grow; $grow = array(); @@ -314,6 +318,42 @@ class rrdstat { } } + if (isset($gconf['special']) && count($gconf['special'])) { + foreach ($gconf['special'] as $crow) { + $srow = array(); + $srow['sType'] = isset($crow['sType'])?$crow['sType']:'COMMENT'; + if ($grow['sType'] != 'COMMENT') { + // XXX: use line below and remove cf var once we have rrdtol 1.2 + // $srow['name'] = $crow['name'].(isset($crow['cf'])?'_'.$crow['cf']:''); + $srow['name'] = $crow['name']; + $srow['cf'] = isset($crow['cf'])?$crow['cf']:'AVERAGE'; + if (isset($crow['cf'])) { + // XXX: use line below once we have rrdtol 1.2 + // $graphrows[] = array('dType'=>'VDEF', 'name'=>$srow['name'].'_'.$crow['cf'], 'rpn_expr'=>$srow['name'].','.$crow['cf']); + } + elseif (isset($crow['rpn_expr'])) { + // XXX: does only work with rrdtool 1.2 + $graphrows[] = array('dType'=>'VDEF', 'name'=>$srow['name'], 'rpn_expr'=>$crow['rpn_expr']); + } + } + $srow['text'] = isset($crow['text'])?$crow['text']:''; + $specialrows[] = $srow; + } + } + else { + foreach ($graphrows as $grow) { + if (isset($grow['gType']) && strlen($grow['gType'])) { + $textprefix = isset($grow['legend'])?$grow['legend']:$grow['name']; + // XXX: use lines below once we have rrdtol 1.2 + // $graphrows[] = array('dType'=>'VDEF', 'name'=>$grow['name'].'_last', 'rpn_expr'=>$grow['name'].',LAST'); + // $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'].'_last', 'text'=>'%3.2lf%s'); + $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'MAX', 'text'=>$textprefix.'|Maximum|%.2lf%s'); + $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'AVERAGE', 'text'=>$textprefix.'|Average|%.2lf%s'); + $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'LAST', 'text'=>$textprefix.'|Current|%.2lf%s'); + } + } + } + $endtime = isset($gconf['time_end'])?$gconf['time_end']:(is_numeric($this->last_update())?$this->last_update():time()); $gOpts = ' --start '.($endtime-$duration).' --end '.$endtime.' --step '.$slice; if (isset($gconf['label_top'])) { $gOpts .= ' --title '.$this->text_quote($gconf['label_top']); } @@ -345,21 +385,29 @@ class rrdstat { $gDefs .= ($grow['dType']=='DEF')?$this->rrd_file.':'.$grow['dsname'].':'.$grow['cf']:$grow['rpn_expr']; } if (isset($grow['gType']) && strlen($grow['gType'])) { - // XXX: current rrdtools version doesn't support STACK flag, only STACK type + // XXX: change from STACK type to STACK flag once we have rrdtool 1.2 if (isset($grow['stack']) && $grow['stack']) { $grow['gType'] = 'STACK'; } $gGraphs .= ' '.$grow['gType'].':'.$grow['name'].$grow['color']; if (isset($grow['legend'])) { $gGraphs .= ':'.$this->text_quote($grow['legend']); } - // XXX: when STACK flag is supported, remove above STACK if-command and uncomment the one below + // XXX: remove above STACK if-command and uncomment the one below once we have rrdtool 1.2 //if (isset($grow['stack']) && $grow['stack']) { $gGraphs .= ':STACK'; } } } + foreach ($specialrows as $srow) { + $addSpecial .= ' '.$srow['sType']; + // XXX: eliminate cf once we have rrdtool 1.2 + // $addSpecial .= ($grow['sType']!='COMMENT')?':'.$grow['name']:''); + $addSpecial .= (($srow['sType']!='COMMENT')?':'.$srow['name'].':'.$srow['cf']:''); + $addSpecial .= ':'.$this->text_quote($srow['text']); + } + $graph_cmd = 'rrdtool graph '.str_replace('*', '\*', $fname.$gOpts.$gDefs.$gGraphs.$addSpecial); $return = `$graph_cmd 2>&1`; if (strpos($return, 'ERROR') !== false) { trigger_error('rrd graph error: '.$return, E_USER_WARNING); -// $return = $graph_cmd."\n\n".$return; + $return = $graph_cmd."\n\n".$return; } return $return; } @@ -375,22 +423,88 @@ class rrdstat { else { $pconf = $page_extras; } } - $out = ''.$basename.' - RRD statistics'; + $ptitle = $basename.' - RRD statistics'; + $gtitle = array(); + $gtitle['day'] = 'Day overview (scaling 5 minutes)'; + $gtitle['week'] = 'Week overview (scaling 30 minutes)'; + $gtitle['month'] = 'Month overview (scaling 2 hours)'; + $gtitle['year'] = 'Year overview (scaling 1 day)'; - $out .= '

Last Update: '.date('Y-m-d H:i:s', $this->last_update()).'

'; + $out = ''; + $out .= ''.$ptitle.''; + $out .= ''; + $out .= ''; + $out .= ''; + + $out .= '

'.$ptitle.'

'; + $out .= '

Last Update: '.date('Y-m-d H:i:s', $this->last_update()).'

'; if (in_array($this->status, array('ok','readonly'))) { foreach (array('day','week','month','year') as $tframe) { $ret = $this->graph($tframe, null, $graph_extras); + if (strpos($ret, "\n\n") !== false) { $graph_cmd = substr($ret, 0, strpos($ret, "\n\n")); $ret = substr($ret, strpos($ret, "\n\n")+2); } + else { $graph_cmd = null; } + $grout = explode("\n",$ret); + $gmeta = array(); + foreach ($grout as $gline) { + if (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; + } + } + $out .= '
'; // $out .= '

'.nl2br($ret).'

'; - $out .= '

'; + $out .= '

'.$gtitle[$tframe].'

'; + $out .= ''; + if (isset($gmeta['data']) && count($gmeta['data'])) { + $out .= ''; + foreach ($gmeta['data'] as $field=>$gdata) { + $out .= ''; + foreach ($gdata as $gkey=>$gval) { + $out .= ''; + } + $out .= ''; + } + $out .= '
'.$field.''.$gkey.': '.$gval.'
'; + } + if (isset($gmeta['var']) && count($gmeta['var'])) { + foreach ($gmeta['var'] as $gkey=>$gval) { + $out .= '

'.$gkey.': '.$gval.'

'; + } + } + if (isset($gmeta['info']) && count($gmeta['info'])) { + foreach ($gmeta['info'] as $gval) { + $out .= '

'.$gval.'

'; + } + } } } else { $out .= 'RRD error: status is "'.$this->status.'"'; } + $out .= '
'; - $ou .= ''; + $out .= ''; return $out; } -- 2.43.0