mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Sanity check the in/out_delta value, if it's out of the range of the
ifSpeed then we use the previous value
This commit is contained in:
@@ -131,8 +131,8 @@ foreach (dbFetch('SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bil
|
||||
$period = $row['period'];
|
||||
$in_delta = $row['in_delta'];
|
||||
$out_delta = $row['out_delta'];
|
||||
$in_value = round(($in_delta * 8 / $period), 2);
|
||||
$out_value = round(($out_delta * 8 / $period), 2);
|
||||
$in_value = delta_to_bits($in_delta, $period);
|
||||
$out_value = delta_to_bits($out_delta, $period);;
|
||||
|
||||
$last = $timestamp;
|
||||
|
||||
|
@@ -63,7 +63,7 @@ function getDates($dayofmonth, $months=0) {
|
||||
}//end getDates()
|
||||
|
||||
|
||||
function getValue($host, $port, $id, $inout) {
|
||||
function getValue($host, $port, $id, $inout, $port_data=array()) {
|
||||
global $config;
|
||||
|
||||
$oid = 'IF-MIB::ifHC'.$inout.'Octets.'.$id;
|
||||
@@ -81,8 +81,9 @@ function getValue($host, $port, $id, $inout) {
|
||||
|
||||
function getLastPortCounter($port_id) {
|
||||
$return = array();
|
||||
$row = dbFetchRow("SELECT in_counter, in_delta, out_counter, out_delta FROM bill_port_counters WHERE `port_id` = ?", array($port_id));
|
||||
$row = dbFetchRow("SELECT timestamp, in_counter, in_delta, out_counter, out_delta FROM bill_port_counters WHERE `port_id` = ?", array($port_id));
|
||||
if (!is_null($row)) {
|
||||
$return[timestamp] = $row['timestamp'];
|
||||
$return[in_counter] = $row['in_counter'];
|
||||
$return[in_delta] = $row['in_delta'];
|
||||
$return[out_counter] = $row['out_counter'];
|
||||
|
@@ -1534,3 +1534,7 @@ function create_sensor_to_state_index($device, $state_name, $index)
|
||||
dbInsert($insert, 'sensors_to_state_indexes');
|
||||
}
|
||||
}
|
||||
|
||||
function delta_to_bits($delta,$period) {
|
||||
return round(($_delta * 8 / $period), 2);
|
||||
}
|
||||
|
@@ -73,14 +73,22 @@ function CollectData($bill_id) {
|
||||
$port_data['last_out_measurement'] = $last_counters[out_counter];
|
||||
$port_data['last_out_delta'] = $last_counters[out_delta];
|
||||
|
||||
if ($port_data['in_measurement'] >= $port_data['last_in_measurement']) {
|
||||
$tmp_period = dbFetchCell("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('".mres($last_counters['timestamp'])."')");
|
||||
|
||||
if (delta_to_bits($port_data['in_delta'], $tmp_period) > $port_data['ifSpeed']) {
|
||||
$port_data['in_delta'] = $port_data['last_in_delta'];
|
||||
}
|
||||
elseif ($port_data['in_measurement'] >= $port_data['last_in_measurement']) {
|
||||
$port_data['in_delta'] = ($port_data['in_measurement'] - $port_data['last_in_measurement']);
|
||||
}
|
||||
else {
|
||||
$port_data['in_delta'] = $port_data['last_in_delta'];
|
||||
}
|
||||
|
||||
if ($port_data['out_measurement'] >= $port_data['last_out_measurement']) {
|
||||
if (delta_to_bits($port_data['out_delta'], $tmp_period) > $port_data['ifSpeed']) {
|
||||
$port_data['out_delta'] = $port_data['last_out_delta'];
|
||||
}
|
||||
elseif ($port_data['out_measurement'] >= $port_data['last_out_measurement']) {
|
||||
$port_data['out_delta'] = ($port_data['out_measurement'] - $port_data['last_out_measurement']);
|
||||
}
|
||||
else {
|
||||
@@ -91,7 +99,7 @@ function CollectData($bill_id) {
|
||||
$port_data['in_delta'] = '0';
|
||||
$port_data['out_delta'] = '0';
|
||||
}
|
||||
|
||||
|
||||
$fields = array('timestamp' => $now, 'in_counter' => $port_data['in_measurement'], 'out_counter' => $port_data['out_measurement'], 'in_delta' => $port_data['in_delta'], 'out_delta' => $port_data['out_delta']);
|
||||
if (dbUpdate($fields, 'bill_port_counters', "`port_id`='" . mres($port_id) . "'") == 0) {
|
||||
$fields['port_id'] = $port_id;
|
||||
|
Reference in New Issue
Block a user