librenms/includes/polling/processors.inc.php
Neil Lathwood fad5aca1b7 feature: Allow customisation of rrd step/heartbeat when creating new rrd files (#5947)
* feature: Allow customisation of rrd step/heartbeat when creating new rrd files

* revert defaults

* added docs + webui config option

* Move RrdDefinition to an Object to make them easier to create and remove the possibility of typos.

* Fix style/lint issues and missing use statements

* 3 more missing use statements

* updated doc + moved schema file
2017-02-23 22:45:50 +00:00

42 lines
1.3 KiB
PHP

<?php
use LibreNMS\RRD\RrdDefinition;
foreach (dbFetchRows('SELECT * FROM processors WHERE device_id = ?', array($device['device_id'])) as $processor) {
echo 'Processor '.$processor['processor_descr'].'... ';
$processor_type = $processor['processor_type'];
$processor_index = $processor['processor_index'];
$file = $config['install_dir'].'/includes/polling/processors/'. $processor_type .'.inc.php';
if (is_file($file)) {
include $file;
} else {
$proc = snmp_get($device, $processor['processor_oid'], '-O Uqnv', '""');
}
$rrd_name = array('processor', $processor_type, $processor_index);
$rrd_def = RrdDefinition::make()->addDataset('usage', 'GAUGE', -273, 1000);
$proc = trim(str_replace('"', '', $proc));
list($proc) = preg_split('@\ @', $proc);
if (!$processor['processor_precision']) {
$processor['processor_precision'] = '1';
};
$proc = round(($proc / $processor['processor_precision']), 2);
echo $proc."%\n";
$fields = array(
'usage' => $proc,
);
$tags = compact('processor_type', 'processor_index', 'rrd_name', 'rrd_def');
data_update($device, 'processors', $tags, $fields);
dbUpdate(array('processor_usage' => $proc), 'processors', '`processor_id` = ?', array($processor['processor_id']));
}//end foreach
unset($processor);