1<?php 2 3function executeEx($cmd,&$retstr) { 4 $retval=0; 5 exec($cmd,$retstr,$retval); 6 return $retval==0; 7} 8 9function rrd_last_compat($fname) { 10 global $rrdtool_path; 11 12 $cmd=$rrdtool_path." last ".$fname; 13 14 if (!executeEx($cmd,$retstr)) 15 return 0; 16 17 return $retstr[0]; 18} 19 20function rrd_fetch_compat($fname,$opts,$nopts) { 21 global $rrdtool_path; 22 23 $result['start']=0; 24 $result['end']=0; 25 $result['step']=0; 26 $result['ds_cnt']=0; 27 $result['ds_namv']=array(); 28 $result['data']=array(); 29 $cmd=$rrdtool_path." fetch ".$fname." ".implode(" ",$opts); 30 31 if (!executeEx($cmd,$retstr)) 32 return $result; 33 34 $tmp=preg_replace('/\s\s+/', ' ',$retstr[0]); 35 $tmp=preg_replace('/^\s+/', '',$tmp); 36 $tmp=preg_replace('/\s+$/', '',$tmp); 37 38 $result['ds_namv']=explode(' ',$tmp); 39 $result['ds_cnt']=count($result['ds_namv']); 40 unset($retstr[0]); 41 unset($retstr[1]); 42 43 foreach($retstr as $line) { 44 list($ltime,$lvalues)=explode(': ',$line); 45 if ($result['start']!=0 && $result['step']==0) 46 $result['step']=$ltime-$result['start']; 47 if ($result['start']==0) 48 $result['start']=$ltime; 49 $result['end']=$ltime; 50 foreach(explode(' ',$lvalues) as $value) 51 $result['data'][]=$value; 52 } 53 54 return $result; 55} 56 57?> 58