First cut at unified data storage for rrdtool & influxdb

As a side-effect, this adds InfluxDB support for MIB-based polling.
This commit is contained in:
Paul Gear
2016-01-15 21:49:57 +10:00
parent 61af4f9d7f
commit 3831ad3f45
11 changed files with 154 additions and 184 deletions
+20 -27
View File
@@ -331,49 +331,42 @@ function rrdtool_tune($type, $filename, $max) {
}
} // rrdtool_tune
/*
* Please use this instead of creating & updating RRD files manually.
* @param device Device object - only 'hostname' is used at present
* @param name Array of rrdname components
* @param def Array of data definitions
* @param val Array of value definitions
*
* rrdtool backend implementation of data_update
*/
function rrd_create_update($device, $name, $def, $val, $step=300)
function rrdtool_data_update($device, $measurement, $tags, $fields)
{
global $config;
$rrd = rrd_name($device['hostname'], $name);
if (!is_file($rrd) && $def != null) {
$rrd_name = $tags['rrd_name'] ? $tags['rrd_name'] : $measurement;
$step = $tags['rrd_step'] ? $tags['rrd_step'] : 300;
$rrd = rrd_name($device['hostname'], $rrd_name);
if (!is_file($rrd) && $tags['rrd_def']) {
// add the --step and the rra definitions to the array
$newdef = "--step $step ".implode(' ', $def).$config['rrd_rra'];
$newdef = "--step $step ".implode(' ', $tags['rrd_def']).$config['rrd_rra'];
rrdtool_create($rrd, $newdef);
}
rrdtool_update($rrd, $val);
} // rrd_create_update
/*
* @return bool indicating existence of RRD file
* @param device Device object as used with rrd_create_update()
* @param name RRD name array as used with rrd_create_update() and rrd_name()
*/
function rrd_file_exists($device, $name)
{
return is_file(rrd_name($device['hostname'], $name));
} // rrd_file_exists
rrdtool_update($rrd, $fields);
} // rrdtool_data_update
/*
* @return bool indicating rename success or failure
* @param device Device object as used with rrd_create_update()
* @param oldname RRD name array as used with rrd_create_update() and rrd_name()
* @param newname RRD name array as used with rrd_create_update() and rrd_name()
* @param device Device object
* @param oldname RRD name array as used with rrd_name()
* @param newname RRD name array as used with rrd_name()
*/
function rrd_file_rename($device, $oldname, $newname)
{
$oldrrd = rrd_name($device['hostname'], $oldname);
$newrrd = rrd_name($device['hostname'], $newname);
return rename($oldrrd, $newrrd);
if (is_file($oldrrd) && !is_file($newrrd)) {
return rename($oldrrd, $newrrd);
}
else {
return true;
}
} // rrd_file_rename