Don't use $config['rrdcached_dir'] anymore, always use relative directories when using rrdcached.

Wait for output on every command, this prevents input left in the buffer from messing up subsequent commands.
It doesn't seem like there is a penalty, but I'd have to do more testing.
This commit is contained in:
Tony Murray
2016-07-25 16:24:09 -05:00
parent c43f533b55
commit e3772e2653
4 changed files with 13 additions and 31 deletions

View File

@@ -85,7 +85,6 @@ Running Apache and an install of LibreNMS in /opt/librenms
```php
$config['distributed_poller'] = true;
$config['rrdcached'] = "example.com:42217";
$config['rrdcached_dir'] = ".";
```
Database Server:
@@ -126,7 +125,6 @@ $config['distributed_poller_host'] = "example.com";
$config['distributed_poller_port'] = 11211;
$config['distributed_poller'] = true;
$config['rrdcached'] = "example.com:42217";
$config['rrdcached_dir'] = ".";
$config['update'] = 0;
```
@@ -153,7 +151,6 @@ $config['distributed_poller_host'] = "example.com";
$config['distributed_poller_port'] = 11211;
$config['distributed_poller'] = true;
$config['rrdcached'] = "example.com:42217";
$config['rrdcached_dir'] = ".";
$config['update'] = 0;
```
@@ -178,7 +175,6 @@ $config['distributed_poller_host'] = "example.com";
$config['distributed_poller_port'] = 11211;
$config['distributed_poller'] = true;
$config['rrdcached'] = "example.com:42217";
$config['rrdcached_dir'] = ".";
$config['update'] = 0;
```

View File

@@ -104,11 +104,9 @@ Settings to enable memcached - currently it's not recommended to run memcached u
```php
$config['rrdcached'] = "unix:/var/run/rrdcached.sock"; // or a tcp connection 127.0.0.1:42217
$config['rrdcached_dir'] = FALSE;
```
To enable rrdcached you need to set at least the `rrdcached` option. If `rrdcached` is a tcp socket then you need to configure `rrdcached_dir` as well.
This should be set based on your base directory for running rrdcached. For instance if -b for rrdcached is set to /var/lib/rrd but you are expecting
LibreNMS to store them in /var/lib/rrd/librenms then you would need to set `rrdcached_dir` to librenms.
To enable rrdcached you need to set at least the `rrdcached` option. Make sure rrdcached is started with the `-b` option set to the correct directoy,
as configured in `$config['rrd_dir`]`.
#### WebUI Settings

View File

@@ -91,8 +91,7 @@ $config['rrd_rra'] .= ' RRA:LAST:0.5:1:1440 ';
// RRDCacheD - Make sure it can write to your RRD dir!
// $config['rrdcached'] = "unix:/var/run/rrdcached.sock";
$config['rrdcached_dir'] = false;
// Set this if you are using tcp connections to rrdcached
// Web Interface Settings
if (isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT'])) {
if (strpos($_SERVER['SERVER_NAME'], ':')) {

View File

@@ -104,10 +104,7 @@ function rrdtool_graph($graph_file, $options)
// 1 => readable handle connected to child stdout
// Any error output will be appended to /tmp/error-output.txt
if ($config['rrdcached']) {
if (isset($config['rrdcached_dir']) && $config['rrdcached_dir'] !== false) {
$options = str_replace($config['rrd_dir'].'/', './'.$config['rrdcached_dir'].'/', $options);
$options = str_replace($config['rrd_dir'], './'.$config['rrdcached_dir'].'/', $options);
}
$options = str_replace(array($config['rrd_dir'].'/', $config['rrd_dir']), '', $options);
fwrite($rrd_pipes[0], 'graph --daemon '.$config['rrdcached']." $graph_file $options");
}
@@ -158,7 +155,7 @@ function rrdtool_graph($graph_file, $options)
* @global debug
* @global rrd_pipes
*/
function rrdtool($command, $filename, $options, $timeout=0)
function rrdtool($command, $filename, $options, $timeout=1)
{
global $config, $debug, $rrd_pipes, $console_color;
@@ -167,11 +164,11 @@ function rrdtool($command, $filename, $options, $timeout=0)
(version_compare($config['rrdtool_version'], '1.5', '>=') && $command != "tune") || // 1.5+ supports all except tune
($command != "create" && $command != "tune")) // older supports all except create and tune
) {
if (isset($config['rrdcached_dir']) && $config['rrdcached_dir'] !== false) {
$filename = str_replace($config['rrd_dir'].'/', './'.$config['rrdcached_dir'].'/', $filename);
$filename = str_replace($config['rrd_dir'], './'.$config['rrdcached_dir'].'/', $filename);
}
// only relative paths if using rrdcached
$filename = str_replace(array($config['rrd_dir'].'/', $config['rrd_dir']), '', $filename);
// using rrdcached, append --daemon
$cmd = "$command $filename $options --daemon ".$config['rrdcached'];
} else {
$cmd = "$command $filename $options";
@@ -182,26 +179,18 @@ function rrdtool($command, $filename, $options, $timeout=0)
print $console_color->convert('[%rRRD Disabled%n]');
$output = array(null, null);
} else {
if ($timeout > 0) {
// if we care about the output, indicated by the fact that we are waiting for it
// remove any previous output before sending the command
stream_get_contents($rrd_pipes[1]);
stream_get_contents($rrd_pipes[2]);
}
fwrite($rrd_pipes[0], $cmd . "\n");
if ($timeout > 0) {
// this causes us to block until we receive output for up to $timeout seconds
stream_select($r = $rrd_pipes, $w = null, $x = null, $timeout);
}
// this causes us to block until we receive output for up to $timeout seconds
stream_select($r = $rrd_pipes, $w = null, $x = null, $timeout);
$output = array(stream_get_contents($rrd_pipes[1]), stream_get_contents($rrd_pipes[2]));
}
if ($debug) {
echo $output[0];
echo $output[1];
print $console_color->convert('RRD[%g'.$cmd."%n] \n");
echo 'rrdtool output: ';
var_dump($output);
}
return $output;