Always add 'extended' metrics to db and remove option

This commit is contained in:
Eldon Koyle
2015-12-08 09:54:31 -07:00
parent 1ee481ff6e
commit 81d84e0f8b
2 changed files with 11 additions and 27 deletions

View File

@ -77,7 +77,6 @@ $config['memcached']['host'] = 'localhost';
$config['memcached']['port'] = 11211; $config['memcached']['port'] = 11211;
$config['memcached']['ttl'] = 240; $config['memcached']['ttl'] = 240;
$config['extended_port_metrics'] = false;
$config['slow_statistics'] = true; $config['slow_statistics'] = true;
// THIS WILL CHANGE TO FALSE IN FUTURE // THIS WILL CHANGE TO FALSE IN FUTURE
// RRD Format Settings // RRD Format Settings

View File

@ -216,13 +216,8 @@ d_echo($port_stats);
// FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :> // FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :>
// -- i can make it a function, so that you don't know what it's doing. // -- i can make it a function, so that you don't know what it's doing.
// -- $ports = adamasMagicFunction($ports_db); ? // -- $ports = adamasMagicFunction($ports_db); ?
if ($config['extended_port_metrics']) { // select * doesn't do what we want if multiple tables have the same column name -- last one wins :/
// select * doesn't do what we want if multiple tables have the same column name -- last one wins :/ $ports_db = dbFetchRows('SELECT *, `ports_statistics`.`port_id` AS `ports_statistics_port_id`, `ports`.`port_id` AS `port_id` FROM `ports` LEFT OUTER JOIN `ports_statistics` ON `ports`.`port_id` = `ports_statistics`.`port_id` WHERE `ports`.`device_id` = ?', array($device['device_id']));
$ports_db = dbFetchRows('SELECT *, `ports_statistics`.`port_id` AS `ports_statistics_port_id`, `ports`.`port_id` AS `port_id` FROM `ports` LEFT OUTER JOIN `ports_statistics` ON `ports`.`port_id` = `ports_statistics`.`port_id` WHERE `ports`.`device_id` = ?', array($device['device_id']));
}
else {
$ports_db = dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($device['device_id']));
}
foreach ($ports_db as $port) { foreach ($ports_db as $port) {
$ports[$port['ifIndex']] = $port; $ports[$port['ifIndex']] = $port;
@ -234,9 +229,7 @@ foreach ($port_stats as $ifIndex => $port) {
echo 'valid'; echo 'valid';
if (!is_array($ports[$port['ifIndex']])) { if (!is_array($ports[$port['ifIndex']])) {
$port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports'); $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports');
if ($config['extended_port_metrics']) { dbInsert(array('port_id' => $port_id), 'ports_statistics');
dbInsert(array('port_id' => $port_id), 'ports_statistics');
}
$ports[$port['ifIndex']] = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($port_id)); $ports[$port['ifIndex']] = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($port_id));
echo 'Adding: '.$port['ifName'].'('.$ifIndex.')('.$ports[$port['ifIndex']]['port_id'].')'; echo 'Adding: '.$port['ifName'].'('.$ifIndex.')('.$ports[$port['ifIndex']]['port_id'].')';
// print_r($ports); // print_r($ports);
@ -245,9 +238,8 @@ foreach ($port_stats as $ifIndex => $port) {
dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports[$ifIndex]['port_id'])); dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports[$ifIndex]['port_id']));
$ports[$ifIndex]['deleted'] = '0'; $ports[$ifIndex]['deleted'] = '0';
} }
if ($config['extended_port_metrics'] && if ($ports[$ifIndex]['ports_statistics_port_id'] === null) {
$ports[$ifIndex]['ports_statistics_port_id'] === null) { // in case the port was created before we created the table
// in case someone enabled the option after the port was already created
dbInsert(array('port_id' => $ports[$ifIndex]['port_id']), 'ports_statistics'); dbInsert(array('port_id' => $ports[$ifIndex]['port_id']), 'ports_statistics');
} }
} }
@ -430,17 +422,12 @@ foreach ($ports as $port) {
// End parse ifAlias // End parse ifAlias
// Update IF-MIB metrics // Update IF-MIB metrics
$_stat_oids = $stat_oids_db; $_stat_oids = $stat_oids_db + $stat_oids_db_extended;
if ($config['extended_port_metrics']) {
$_stat_oids = $_stat_oids + $stat_oids_db_extended;
}
foreach ($_stat_oids as $oid) { foreach ($_stat_oids as $oid) {
$port_update = 'update'; $port_update = 'update';
if ($config['extended_port_metrics']) { $extended_metric = !in_array($oid, $stat_oids_db, true);
$extended_metric = !in_array($oid, $stat_oids_db, true); if ($extended_metric) {
if ($extended_metric) { $port_update = 'update_extended';
$port_update = 'update_extended';
}
} }
if ($config['slow_statistics'] == true) { if ($config['slow_statistics'] == true) {
@ -587,10 +574,8 @@ foreach ($ports as $port) {
// Update Database // Update Database
if (count($port['update'])) { if (count($port['update'])) {
$updated = dbUpdate($port['update'], 'ports', '`port_id` = ?', array($port['port_id'])); $updated = dbUpdate($port['update'], 'ports', '`port_id` = ?', array($port['port_id']));
if ($config['extended_port_metrics'] and count($port['update_extended'])) { // do we want to do something else with this?
// do we want to do something else with this? $updated += dbUpdate($port['update_extended'], 'ports_statistics', '`port_id` = ?', array($port['port_id']));
$updated += dbUpdate($port['update_extended'], 'ports_statistics', '`port_id` = ?', array($port['port_id']));
}
d_echo("$updated updated"); d_echo("$updated updated");
} }