我正在尝试通过php5-rrd libraires创建rrd图。 我想绘制(LASTHOUR,LASTDAY,LASTWEEK,LASTMONTH)图表。但效果不好,(可能缺少我的RRA设置)。我尝试使用" rrd_update"功能。但是没有用。所以尽量使用" rrd_fetch"功能。但所有数据都出现在-NaN。
这是我的控制台日志。
1426322479:6249:1817
Array
(
[start] => 1426318800
[end] => 1426322700
[step] => 300
[data] => Array
(
[Users] => Array
(
[1426319100] => NAN
[1426319400] => NAN
[1426319700] => NAN
[1426320000] => NAN
[1426320300] => NAN
[1426320600] => NAN
[1426320900] => NAN
[1426321200] => NAN
[1426321500] => NAN
[1426321800] => NAN
[1426322100] => NAN
[1426322400] => NAN
[1426322700] => NAN
)
[Games] => Array
(
[1426319100] => NAN
[1426319400] => NAN
[1426319700] => NAN
[1426320000] => NAN
[1426320300] => NAN
[1426320600] => NAN
[1426320900] => NAN
[1426321200] => NAN
[1426321500] => NAN
[1426321800] => NAN
[1426322100] => NAN
[1426322400] => NAN
[1426322700] => NAN
)
)
)
这是我的PHP代码
$rrdFile = dirname(__FILE__) . "/speed.rrd";
//create rrd file
rrd_create($rrdFile,
array(
"DS:Users:GAUGE:600:0:U",
"DS:Games:GAUGE:600:0:U",
"RRA:AVERAGE:0.5:1:1440",
"RRA:AVERAGE:0.5:5:1440",
"RRA:AVERAGE:0.5:30:800",
"RRA:AVERAGE:0.5:120:800",
"RRA:AVERAGE:0.5:1440:80"
)
);
//update rrd file
if(!(rrd_update($rrdFile,
array(
"N:".rand(0,9999).":".rand(0,9999)
)
))) {
$err = rrd_error();
echo "rrd_update() ERROR: $err\n";
}
// TEST CODE
$result = rrd_fetch( $rrdFile, array( "AVERAGE", "--resolution", "100", "--start", "-1h", "--end", "start+1h" ) );
print_r($result);
//graph output
if(!is_array(rrd_graph(dirname(__FILE__) . "/speed.png",
array(
"--start", "-1h",
"--title", "Status",
"--vertical-label", "Users & Games",
"--width", "600",
"--height", "200",
"DEF:Users=$rrdFile:Users:AVERAGE",
"DEF:Games=$rrdFile:Games:AVERAGE",
"CDEF:cUsers=Users",
"CDEF:cGames=Games",
"LINE:cUsers#FF0000",
"LINE:cGames#00FF00"
)
))) {
$err = rrd_error();
echo "rrd_graph() ERROR: $err\n";
}
答案 0 :(得分:1)
您没有足够的样本数据,因此您的图表和RRA都是空的。
您的图表设置为最近1小时的图表;由于您具有默认间隔(5分钟),这意味着只有来自最高分辨率RRA的12个样本。
但是,您没有输入任何数据!您只需调用rrd_update
一次,时间戳为'now',这不足以填充一个RRA条目(您将需要至少两个样本,时间间隔为5分钟,以完全填充RRA条目)
如果您希望生成一些测试数据,请从过去3600秒的时间戳开始,并添加12个样本,每次迭代时间戳增加300。这将导致您的主要(5分钟)RRA中的11个条目,以及您的第二个25分钟RRA中的2个条目。