mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-04 08:02:05 +02:00
Improve performance of billing poller
This commit is contained in:
@@ -82,10 +82,8 @@ function getValue($host, $port, $id, $inout) {
|
|||||||
|
|
||||||
function getLastPortCounter($port_id, $inout) {
|
function getLastPortCounter($port_id, $inout) {
|
||||||
$return = array();
|
$return = array();
|
||||||
$rows = dbFetchCell('SELECT count(counter) from `port_'.mres($inout)."_measurements` WHERE `port_id`='".mres($port_id)."'");
|
$row = dbFetchRow('SELECT counter,delta FROM `port_'.mres($inout)."_measurements` WHERE `port_id`='".mres($port_id)."' ORDER BY timestamp DESC LIMIT 1");
|
||||||
|
if (!is_null($row)) {
|
||||||
if ($rows > 0) {
|
|
||||||
$row = dbFetchRow('SELECT counter,delta FROM `port_'.mres($inout)."_measurements` WHERE `port_id`='".mres($port_id)."' ORDER BY timestamp DESC");
|
|
||||||
$return[counter] = $row['counter'];
|
$return[counter] = $row['counter'];
|
||||||
$return[delta] = $row['delta'];
|
$return[delta] = $row['delta'];
|
||||||
$return[state] = 'ok';
|
$return[state] = 'ok';
|
||||||
@@ -101,10 +99,8 @@ function getLastPortCounter($port_id, $inout) {
|
|||||||
|
|
||||||
function getLastMeasurement($bill_id) {
|
function getLastMeasurement($bill_id) {
|
||||||
$return = array();
|
$return = array();
|
||||||
$rows = dbFetchCell("SELECT count(delta) from bill_data WHERE bill_id='".mres($bill_id)."'");
|
$row = dbFetchRow("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id='".mres($bill_id)."' ORDER BY timestamp DESC LIMIT 1");
|
||||||
|
if (!is_null($row)) {
|
||||||
if ($rows > 0) {
|
|
||||||
$row = dbFetchRow("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id='".mres($bill_id)."' ORDER BY timestamp DESC");
|
|
||||||
$return[delta] = $row['delta'];
|
$return[delta] = $row['delta'];
|
||||||
$return[delta_in] = $row['delta_in'];
|
$return[delta_in] = $row['delta_in'];
|
||||||
$return[delta_out] = $row['delta_out'];
|
$return[delta_out] = $row['delta_out'];
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
ALTER TABLE port_in_measurements ADD INDEX (`port_id`, `timestamp`);
|
||||||
|
ALTER TABLE port_out_measurements ADD INDEX (`port_id`, `timestamp`);
|
||||||
|
ALTER TABLE bill_data ADD INDEX (`bill_id`, `timestamp`);
|
||||||
Reference in New Issue
Block a user