我在ubuntu中使用rrdtool创建图表, rrdtool在命令中使用选项来创建图形。 我正在尝试使用以下命令通过php创建此选项
$rrd_options="";
$unit_text = str_pad(substr($unit_text, 0, 18), 18);
$line_text = str_pad(substr($line_text, 0, 12), 12);
$rrd_options = "$rrd_options". "
DEF:".$ds."=".$rrd_filename.":".$ds.":AVERAGE";
$rrd_options ="$rrd_options". "
DEF:".$ds."_max=".$rrd_filename.":".$ds.":MAX";
$rrd_options = "$rrd_options"."
DEF:".$ds."_min=".$rrd_filename.":".$ds.":MIN";
$rrd_options ="$rrd_options". " AREA:".$ds."#".$colour_area.":";
$rrd_options ="$rrd_options". "
AREA:".$ds."_max#".$colour_area_max.":";
$rrd_options ="$rrd_options". "
LINE1.25:".$ds."#".$colour_line.":'".$line_text."'";
$rrd_options ="$rrd_options". " GPRINT:".$ds.":LAST:%6.2lf%s";
$rrd_options ="$rrd_options". " GPRINT:".$ds.":AVERAGE:%6.2lf%s";
$rrd_options ="$rrd_options". " GPRINT:".$ds."_max:MAX:%6.2lf%s";
当我使用echo命令打印此变量时,结果将如下所示
DEF:LOAD=/var/www/html/rrd/10.10.0.144/fortigate_cpu.rrd:LOAD:AVERAGE DEF:LOAD_max=/var/www/html/rrd/10.10.0.144/fortigate_cpu.rrd:LOAD:MAX DEF:LOAD_min=/var/www/html/rrd/10.10.0.144/fortigate_cpu.rrd:LOAD:MIN AREA:LOAD#9999cc: AREA:LOAD_max#9999cc: LINE1.25:LOAD#0000cc:' ' GPRINT:LOAD:LAST:%6.2lf%s GPRINT:LOAD:AVERAGE:%6.2lf%s GPRINT:LOAD_max:MAX:%6.2lf%s
并且我已经创建了创建命令字符串的函数 这是功能
function rrdtool_build_command($command, $filename, $rrd_options)
{
return "$command $filename $options";
}
我尝试使用rrdtool_build_command
函数执行proc_open
的输出
使用此代码
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/error-output.txt", "a")
);
$cwd = '/tmp';
$cmd=rrdtool_build_command(' rrdtool graph', $graph_file, $options);
$process = proc_open($cmd, $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process)) {
fclose($pipes[0]);
stream_get_contents($pipes[1]);
fclose($pipes[1]);
$return_value = proc_close($process);
echo "command returned $return_value\n";
尝试执行命令时的结果是
另一方面,当我将选项直接放在没有问题的情况下执行的命令中。我的意思是,如果我获得rrd_options变量的值并像这样手动创建cmd命令返回127
rrdtool图5wyFz8ARRvclaTk7.png DEF:LOAD = / var / www / html / rrd / 10.10.0.144 / fortigate_cpu.rrd:LOAD:AVERAGE DEF:LOAD_max = / var / www / html / rrd / 10.10.0.144 / fortigate_cpu .rrd:LOAD:MAX DEF:LOAD_min = / var / www / html / rrd / 10.10.0.144 / fortigate_cpu.rrd:LOAD:MIN AREA:LOAD#9999cc:AREA:LOAD_max#9999cc:LINE1.25:LOAD#0000cc: ''GPRINT:LOAD:LAST:%6.2lf%s GPRINT:LOAD:AVERAGE:%6.2lf%s GPRINT:LOAD_max:MAX:%6.2lf%sc
并将此cmd直接传递给PROC_OPEN函数,可以成功执行 即使它与rrdtool_command_build函数的返回值相同 ,我希望我能清楚地说明我的问题,哪里出了问题以及如何解决。请帮助我。