PHP 8.4.1 Released!

rrd_xport

(PECL rrd >= 0.9.0)

rrd_xport导出 RRD 数据库的相关信息

说明

rrd_xport(array $options): array

导出 RRD 数据库文件的相关信息。这些数据可以通过用户空间的 PHP 脚本转换为 XML 文件,然后再恢复为 RRD 数据库文件。

参数

options

导出的数组选项,可以通过 rrd xport 手册查看。

返回值

有关 RRD 数据库文件信息的数组, 或者在失败时返回 false

添加备注

用户贡献的备注 2 notes

up
1
mrezahamedany
7 years ago
an example that shows the usage of this method ( tested in php version 5.6.30 )

class Rrd{
public function getData($id , $start , $end)
{
$step = 300 ;
$rrdFile ="/path/to/file/'.$id.rrd";

try{
$options = ["--start", $start , "--end", $end ,"-- step",$step,"DEF:out=$rrdFile:name:AVERAGE", "XPORT:out:test"];
$result = rrd_xport($options);
$datas = $result['data'][0]['data'];
foreach($datas as $data => $value){

if( is_nan($value) === true ) $value = 0 ;
$output[] = [$data=>$value] ;
}
return json_encode($output);

}catch (Exception $e){

dd($e->getMessage());
}

}
}
up
1
Peter R
11 months ago
A small example of connecting to an rrdcached daemon (This one running on localhost, but works across network as well) and getting in and output bits from an interface.

$options = array(
'--daemon', '127.0.0.1:42217',
'--start', time() - 3600,
'DEF:in_oct=rrdfile.rrd:INOCTETS:AVERAGE',
'DEF:out_oct=rrdfile.rrd:OUTOCTETS:AVERAGE',
'CDEF:in_bits=in_oct,8,*',
'CDEF:out_bits=out_oct,8,*',
'XPORT:in_bits',
'XPORT:out_bits'
);

$result = rrd_xport($options);

var_dump($result);
To Top