X-Git-Url: https://git-public.kairo.at/?a=blobdiff_plain;ds=inline;f=include%2Fclasses%2Frrdstat.php-class;h=a87ea9c10cbca6c1571df71a3d0440908743c6eb;hb=586031cebd8083680f2422f75fd513d2a234a324;hp=590fc3c98de8b302e3f52d5a71307b5b7eb549b1;hpb=437e1c9114e07ddabd7fb59fb5d793488fa696cd;p=php-utility-classes.git diff --git a/include/classes/rrdstat.php-class b/include/classes/rrdstat.php-class index 590fc3c..a87ea9c 100644 --- a/include/classes/rrdstat.php-class +++ b/include/classes/rrdstat.php-class @@ -75,6 +75,9 @@ class rrdstat { // set definitions based on given configuration // [intended for internal use, called by the constructor] // + // function rrd_version() { + // get RRDtool version string + // // function create() // create RRD file according to set config // @@ -267,6 +270,26 @@ class rrdstat { $this->config_all = $complete_conf; } + function rrd_version() { + // return RRDtool version + static $version; + if (!isset($version)) { + $create_cmd = 'rrdtool --version'; + $return = `$create_cmd 2>&1`; + if (strpos($return, 'ERROR') !== false) { + trigger_error($this->rrd_file.' - rrd version error: '.$return, E_USER_WARNING); + } + + if (preg_match('/^\s*RRDtool ([\d\.]+)\s+/', $return, $regs)) { + $version = $regs[1]; + } + else { + $version = '0.0'; + } + } + return $version; + } + function create() { // create RRD file @@ -605,16 +628,22 @@ class rrdstat { $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 ($this->rrd_version() >= '1.2') { + $srow['name'] = $crow['name'].(isset($crow['cf'])?'_'.$crow['cf']:''); + } + else { + $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']); + if ($this->rrd_version() >= '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']); + if ($this->rrd_version() >= '1.2') { + $graphrows[] = array('dType'=>'VDEF', 'name'=>$srow['name'], 'rpn_expr'=>$crow['rpn_expr']); + } } } $srow['text'] = isset($crow['text'])?$crow['text']:''; @@ -626,12 +655,19 @@ class rrdstat { foreach ($graphrows as $grow) { if (isset($grow['gType']) && strlen($grow['gType'])) { $textprefix = isset($grow['desc'])?$grow['desc']:(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.'|'.dgettext($td, 'Maximum').'|%.2lf%s'); - $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'AVERAGE', 'text'=>$textprefix.'|'.dgettext($td, 'Average').'|%.2lf%s'); - $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'LAST', 'text'=>$textprefix.'|'.dgettext($td, 'Current').'|%.2lf%s'); + if ($this->rrd_version() >= '1.2') { + $graphrows[] = array('dType'=>'VDEF', 'name'=>$grow['name'].'_max', 'rpn_expr'=>$grow['name'].',MAXIMUM'); + $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'].'_max', 'text'=>$textprefix.'|'.dgettext($td, 'Maximum').'|%.2lf%s'); + $graphrows[] = array('dType'=>'VDEF', 'name'=>$grow['name'].'_avg', 'rpn_expr'=>$grow['name'].',AVERAGE'); + $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'].'_avg', 'text'=>$textprefix.'|'.dgettext($td, 'Average').'|%.2lf%s'); + $graphrows[] = array('dType'=>'VDEF', 'name'=>$grow['name'].'_last', 'rpn_expr'=>$grow['name'].',LAST'); + $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'].'_last', 'text'=>$textprefix.'|'.dgettext($td, 'Current').'|%.2lf%s'); + } + else { + $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'MAX', 'text'=>$textprefix.'|'.dgettext($td, 'Maximum').'|%.2lf%s'); + $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'AVERAGE', 'text'=>$textprefix.'|'.dgettext($td, 'Average').'|%.2lf%s'); + $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'LAST', 'text'=>$textprefix.'|'.dgettext($td, 'Current').'|%.2lf%s'); + } } } } @@ -676,19 +712,27 @@ class rrdstat { } if (isset($grow['gType']) && strlen($grow['gType'])) { // XXX: change from STACK type to STACK flag once we have rrdtool 1.2 - if (isset($grow['stack']) && $grow['stack']) { $grow['gType'] = 'STACK'; } + if ($this->rrd_version() < '1.2') { + // rrdtool 1.0 only know STACK type + 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: remove above STACK if-command and uncomment the one below once we have rrdtool 1.2 - //if (isset($grow['stack']) && $grow['stack']) { $gGraphs .= ':STACK'; } + if ($this->rrd_version() >= '1.2') { + // rrdtool 1.2 and above have STACK flag + 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']:''); + if ($this->rrd_version() >= '1.2') { + $addSpecial .= (($srow['sType']!='COMMENT')?':'.$srow['name']:''); + } + else { + $addSpecial .= (($srow['sType']!='COMMENT')?':'.$srow['name'].':'.$srow['cf']:''); + } $addSpecial .= ':'.$this->text_quote($srow['text']); } @@ -697,7 +741,11 @@ class rrdstat { if (strpos($return, 'ERROR') !== false) { trigger_error($this->rrd_file.' - rrd graph error: '.$return, E_USER_WARNING); - $return = $graph_cmd."\n\n".$return; + $return = 'command:'.$graph_cmd."\n\n".$return; + } + if (0) { + // debug output + $return = 'command:'.$graph_cmd."\n\n".$return; } $legendlines = ''; foreach ($graphrows as $grow) { @@ -715,11 +763,18 @@ class rrdstat { // create a RRD graph and return meta info as a ready-to-use array $gmeta = array('filename'=>null,'legends_long'=>false,'default_colorize'=>false); $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; } + if (0) { + // debug output + $gmeta['ret'] = $ret; + } +// if (preg_match('/\ncommand:(.*?)\n\n/', $ret, $regs)) { $gmeta['graph_cmd'] = $regs[1]; $ret = str_replace($regs[0], "\n",$ret); } +// else { $gmeta['graph_cmd'] = null; } $grout = explode("\n", $ret); foreach ($grout as $gline) { - if (preg_match('/^file:(.+)$/', $gline, $regs)) { + if (preg_match('/^command:(.+)$/', $gline, $regs)) { + $gmeta['graph_cmd'] = $regs[1]; + } + elseif (preg_match('/^file:(.+)$/', $gline, $regs)) { $gmeta['filename'] = $regs[1]; } elseif (preg_match('/^legend:([^\|]+)\|([^|]*)\|([^\|]*)\|(.*)$/', $gline, $regs)) { @@ -791,26 +846,26 @@ class rrdstat { $td = $this->mod_textdomain; $ptitle = isset($pconf['title_page'])?$pconf['title_page']:dgettext($td, 'RRD statistics index'); - $out = '
'; - $out .= ''.$pconf['text_intro'].'
'; + $out .= ''.$pconf['text_intro'].'
'."\n"; } elseif (!isset($pconf['text_intro'])) { - $out .= ''.dgettext($td, 'The following RRD stats are available:').'
'; + $out .= ''.dgettext($td, 'The following RRD stats are available:').'
'."\n"; } $stats = $this->h_page_statsArray($pconf); @@ -821,7 +876,7 @@ class rrdstat { if (isset($pconf['stats_url_add'])) { $sURL_add = $pconf['stats_url_add']; } else { $sURL_add = '&sub=%s'; } - $out .= '