use rrdtool pipe in poller.

git-svn-id: http://www.observium.org/svn/observer/trunk@2631 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2011-10-01 14:54:06 +00:00
parent c15bfa62a4
commit 66dd6dbd61
6 changed files with 203 additions and 94 deletions

View File

@@ -1,57 +1,5 @@
<?php
function rrdtool_graph($graph_file, $options)
{
global $config, $debug;
if ($debug) { echo("$options"); }
$command = $config['rrdtool'] . " -";
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
);
$cwd = $config['rrd_dir'];
$env = array();
$process = proc_open($command, $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process))
{
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to /tmp/error-output.txt
if ($config['rrdcached'])
{
fwrite($pipes[0], "graph --daemon " . $config['rrdcached'] . " $graph_file $options");
} else {
fwrite($pipes[0], "graph $graph_file $options");
}
fclose($pipes[0]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
if ($debug)
{
echo("<p>");
if ($debug) { echo("graph $graph_file $options"); }
echo("</p><p>");
echo "command returned $return_value\n";
echo("</p>");
}
}
}
function generate_link($text, $vars, $new_vars = array())
{
return '<a href="'.generate_url($vars, $new_vars).'">'.$text.'</a>';

View File

@@ -25,6 +25,7 @@ include_once("../includes/common.php");
include_once("../includes/dbFacile.php");
include_once("../includes/rewrites.php");
include_once("includes/functions.inc.php");
include_once("../includes/rrdtool.inc.php");
include_once("includes/authenticate.inc.php");
$from = mres($_GET['from']);
@@ -54,8 +55,6 @@ preg_match('/^(?P<type>[A-Za-z0-9]+)_(?P<subtype>.+)/', mres($_GET['type']), $gr
$type = $graphtype['type'];
$subtype = $graphtype['subtype'];
if ($debug) {print_r($graphtype); }
if (is_file($config['install_dir'] . "/html/includes/graphs/$type/$subtype.inc.php"))
{
if (isset($config['allow_unauth_graphs_cidr']) && count($config['allow_unauth_graphs_cidr']) > 0)
@@ -141,8 +140,11 @@ if ($error_msg) {
} else {
if ($rrd_options)
{
if ($config['rrdcached']) { $rrd_switches = " --daemon ".$config['rrdcached'] . " "; }
rrdtool_graph($graphfile, " $rrd_options");
#rrdtool_graph($filename, $options)
rrdtool_graph($graphfile, $rrd_options);
if ($debug) { echo("<pre>".$rrd_cmd."</pre>"); }
if (is_file($graphfile))
{
@@ -150,8 +152,10 @@ if ($error_msg) {
{
header('Content-type: image/png');
$fd = fopen($graphfile,'r');fpassthru($fd);fclose($fd);
unlink($graphfile);
} else {
echo(`ls -l $graphfile`);
}
unlink($graphfile);
}
else
{