mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added generic memcached support to dbFacile.*
Remove now obsolete memcached code in: html/ajax_rulesuggest.php Remove all the broken memcached code in: html/pages/device/health/mempool.inc.php html/pages/device/overview/generic/sensor.inc.php html/pages/device/overview/mempools.inc.php html/pages/device/port.inc.php html/pages/device/ports.inc.php html/pages/health/sensors.inc.php includes/polling/functions.inc.php includes/polling/mempools.inc.php includes/polling/ports.inc.php includes/polling/storage.inc.php
This commit is contained in:
@@ -72,11 +72,6 @@ if (isset($_GET['term'],$_GET['device_id'])) {
|
||||
$_GET['device_id'] = mres($_GET['device_id']);
|
||||
if (strstr($_GET['term'], '.')) {
|
||||
$term = explode('.', $_GET['term']);
|
||||
if ($config['memcached']['enable']) {
|
||||
$chk = $memcache->get('rule-suggest_'.$term[0]);
|
||||
}
|
||||
|
||||
if (!(sizeof($chk) > 0) || $chk === false) {
|
||||
if ($term[0] == 'macros') {
|
||||
foreach ($config['alert']['macros']['rule'] as $macro => $v) {
|
||||
$chk[] = 'macros.'.$macro;
|
||||
@@ -90,16 +85,10 @@ if (isset($_GET['term'],$_GET['device_id'])) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$current = true;
|
||||
}
|
||||
else {
|
||||
if ($config['memcached']['enable']) {
|
||||
$chk = $memcache->get('rule-suggest-toplvl');
|
||||
}
|
||||
|
||||
if (!(sizeof($chk) > 0) || $chk === false) {
|
||||
$tmp = dbFetchRows("SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME = 'device_id'");
|
||||
foreach ($tmp as $tst) {
|
||||
$chk[] = $tst['TABLE_NAME'].'.';
|
||||
@@ -108,13 +97,7 @@ if (isset($_GET['term'],$_GET['device_id'])) {
|
||||
$chk[] = 'macros.';
|
||||
$chk[] = 'bills.';
|
||||
}
|
||||
}
|
||||
if (sizeof($chk) > 0) {
|
||||
if ($config['memcached']['enable']) {
|
||||
$memcache->set('rule-suggest-'.$oterm, $chk, 86400);
|
||||
// Cache for 24h
|
||||
}
|
||||
|
||||
$obj = levsort($_GET['term'], $chk);
|
||||
$obj = array_chunk($obj, 20, true);
|
||||
$obj = $obj[0];
|
||||
|
@@ -13,17 +13,6 @@ foreach (dbFetchRows('SELECT * FROM `mempools` WHERE device_id = ?', array($devi
|
||||
$row_colour = $list_colour_b;
|
||||
}
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state');
|
||||
d_echo($state);
|
||||
|
||||
if (is_array($state)) {
|
||||
$mempool = array_merge($mempool, $state);
|
||||
}
|
||||
|
||||
unset($state);
|
||||
}
|
||||
|
||||
$text_descr = rewrite_entity_descr($mempool['mempool_descr']);
|
||||
|
||||
$mempool_url = 'graphs/id='.$mempool['mempool_id'].'/type=mempool_usage/';
|
||||
|
@@ -12,10 +12,6 @@ if (count($sensors)) {
|
||||
echo ' </div>
|
||||
<table class="table table-hover table-condensed table-striped">';
|
||||
foreach ($sensors as $sensor) {
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value');
|
||||
}
|
||||
|
||||
if (empty($sensor['sensor_current'])) {
|
||||
$sensor['sensor_current'] = 'NaN';
|
||||
}
|
||||
|
@@ -19,17 +19,6 @@ if (count($mempools)) {
|
||||
';
|
||||
|
||||
foreach ($mempools as $mempool) {
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state');
|
||||
d_echo($state);
|
||||
|
||||
if (is_array($state)) {
|
||||
$mempool = array_merge($mempool, $state);
|
||||
}
|
||||
|
||||
unset($state);
|
||||
}
|
||||
|
||||
$percent = round($mempool['mempool_perc'], 0);
|
||||
$text_descr = rewrite_entity_descr($mempool['mempool_descr']);
|
||||
$total = formatStorage($mempool['mempool_total']);
|
||||
|
@@ -6,17 +6,6 @@ if (!isset($vars['view'])) {
|
||||
|
||||
$port = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($vars['port']));
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$state = $memcache->get('port-'.$port['port_id'].'-state');
|
||||
d_echo($state);
|
||||
|
||||
if (is_array($state)) {
|
||||
$port = array_merge($port, $state);
|
||||
}
|
||||
|
||||
unset($state);
|
||||
}
|
||||
|
||||
$port_details = 1;
|
||||
|
||||
$hostname = $device['hostname'];
|
||||
|
@@ -136,19 +136,7 @@ else {
|
||||
}
|
||||
|
||||
foreach ($ports as $port) {
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$state = $memcache->get('port-'.$port['port_id'].'-state');
|
||||
d_echo($state);
|
||||
|
||||
if (is_array($state)) {
|
||||
$port = array_merge($port, $state);
|
||||
}
|
||||
|
||||
unset($state);
|
||||
}
|
||||
|
||||
include 'includes/print-interface.inc.php';
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
@@ -22,11 +22,6 @@ echo '<tr class="tablehead">
|
||||
</tr>';
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $sensor) {
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value');
|
||||
d_echo('Memcached['.'sensor-'.$sensor['sensor_id'].'-value'.'='.$sensor['sensor_current'].']');
|
||||
}
|
||||
|
||||
if (empty($sensor['sensor_current'])) {
|
||||
$sensor['sensor_current'] = 'NaN';
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@
|
||||
|
||||
|
||||
function dbQuery($sql, $parameters=array()) {
|
||||
global $fullSql, $debug, $sql_debug, $console_color;
|
||||
global $fullSql, $debug, $sql_debug;
|
||||
$fullSql = dbMakeQuery($sql, $parameters);
|
||||
if ($debug) {
|
||||
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||
@@ -239,7 +239,14 @@ function dbDelete($table, $where=null, $parameters=array()) {
|
||||
|
||||
|
||||
function dbFetchRows($sql, $parameters=array()) {
|
||||
global $db_stats;
|
||||
global $db_stats, $config;
|
||||
|
||||
if ($config['memcached']['enable']) {
|
||||
$result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters)));
|
||||
if (!empty($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$time_start = microtime(true);
|
||||
$result = dbQuery($sql, $parameters);
|
||||
@@ -251,6 +258,9 @@ function dbFetchRows($sql, $parameters=array()) {
|
||||
}
|
||||
|
||||
mysql_free_result($result);
|
||||
if ($config['memcached']['enable']) {
|
||||
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']);
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
@@ -296,7 +306,14 @@ function dbFetch($sql, $parameters=array()) {
|
||||
|
||||
|
||||
function dbFetchRow($sql=null, $parameters=array()) {
|
||||
global $db_stats;
|
||||
global $db_stats, $config;
|
||||
|
||||
if ($config['memcached']['enable']) {
|
||||
$result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters)));
|
||||
if (!empty($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$time_start = microtime(true);
|
||||
$result = dbQuery($sql, $parameters);
|
||||
@@ -308,6 +325,9 @@ function dbFetchRow($sql=null, $parameters=array()) {
|
||||
$db_stats['fetchrow_sec'] += number_format(($time_end - $time_start), 8);
|
||||
$db_stats['fetchrow']++;
|
||||
|
||||
if ($config['memcached']['enable']) {
|
||||
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']);
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
else {
|
||||
|
@@ -22,7 +22,6 @@
|
||||
* Used by the other _query functions.
|
||||
* */
|
||||
|
||||
|
||||
function dbQuery($sql, $parameters=array()) {
|
||||
global $fullSql, $debug, $sql_debug, $console_color, $database_link;
|
||||
$fullSql = dbMakeQuery($sql, $parameters);
|
||||
@@ -240,7 +239,14 @@ function dbDelete($table, $where=null, $parameters=array()) {
|
||||
|
||||
|
||||
function dbFetchRows($sql, $parameters=array()) {
|
||||
global $db_stats;
|
||||
global $db_stats, $config;
|
||||
|
||||
if ($config['memcached']['enable']) {
|
||||
$result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters)));
|
||||
if (!empty($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$time_start = microtime(true);
|
||||
$result = dbQuery($sql, $parameters);
|
||||
@@ -252,6 +258,9 @@ function dbFetchRows($sql, $parameters=array()) {
|
||||
}
|
||||
|
||||
mysqli_free_result($result);
|
||||
if ($config['memcached']['enable']) {
|
||||
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']);
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
@@ -297,7 +306,14 @@ function dbFetch($sql, $parameters=array()) {
|
||||
|
||||
|
||||
function dbFetchRow($sql=null, $parameters=array()) {
|
||||
global $db_stats;
|
||||
global $db_stats, $config;
|
||||
|
||||
if ($config['memcached']['enable']) {
|
||||
$result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters)));
|
||||
if (!empty($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
$time_start = microtime(true);
|
||||
$result = dbQuery($sql, $parameters);
|
||||
@@ -309,6 +325,9 @@ function dbFetchRow($sql=null, $parameters=array()) {
|
||||
$db_stats['fetchrow_sec'] += number_format(($time_end - $time_start), 8);
|
||||
$db_stats['fetchrow']++;
|
||||
|
||||
if ($config['memcached']['enable']) {
|
||||
$config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']);
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
else {
|
||||
@@ -326,7 +345,8 @@ function dbFetchRow($sql=null, $parameters=array()) {
|
||||
|
||||
|
||||
function dbFetchCell($sql, $parameters=array()) {
|
||||
global $db_stats;
|
||||
global $db_stats, $config;
|
||||
|
||||
$time_start = microtime(true);
|
||||
$row = dbFetchRow($sql, $parameters);
|
||||
if ($row) {
|
||||
|
@@ -75,6 +75,7 @@ $config['sfdp'] = '/usr/bin/sfdp';
|
||||
$config['memcached']['enable'] = false;
|
||||
$config['memcached']['host'] = 'localhost';
|
||||
$config['memcached']['port'] = 11211;
|
||||
$config['memcached']['ttl'] = 240;
|
||||
|
||||
$config['slow_statistics'] = true;
|
||||
// THIS WILL CHANGE TO FALSE IN FUTURE
|
||||
|
@@ -30,6 +30,22 @@ else {
|
||||
$database_db = mysql_select_db($config['db_name'], $database_link);
|
||||
}
|
||||
|
||||
$config['time']['now'] = time();
|
||||
$config['time']['now'] -= ($config['time']['now'] % 300);
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
if (class_exists('Memcached')) {
|
||||
$config['memcached']['ttl'] += $config['time']['now'];
|
||||
$config['memcached']['resource'] = new Memcached();
|
||||
$config['memcached']['resource']->addServer($config['memcached']['host'], $config['memcached']['port']);
|
||||
}
|
||||
else {
|
||||
echo "WARNING: You have enabled memcached but have not installed the PHP bindings. Disabling memcached support.\n";
|
||||
echo "Try 'apt-get install php5-memcached' or 'pecl install memcached'. You will need the php5-dev and libmemcached-dev packages to use pecl.\n\n";
|
||||
$config['memcached']['enable'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$clone = $config;
|
||||
foreach (dbFetchRows('select config_name,config_value from config') as $obj) {
|
||||
$clone = array_replace_recursive($clone, mergecnf($obj));
|
||||
@@ -1703,22 +1719,7 @@ if (isset($_SERVER['HTTPS'])) {
|
||||
$config['base_url'] = preg_replace('/^http:/', 'https:', $config['base_url']);
|
||||
}
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
if (class_exists('Memcached')) {
|
||||
$memcache = new Memcached();
|
||||
$memcache->addServer($config['memcached']['host'], $config['memcached']['port']);
|
||||
$memcache->getStats();
|
||||
}
|
||||
else {
|
||||
echo "WARNING: You have enabled memcached but have not installed the PHP bindings. Disabling memcached support.\n";
|
||||
echo "Try 'apt-get install php5-memcached' or 'pecl install memcached'. You will need the php5-dev and libmemcached-dev packages to use pecl.\n\n";
|
||||
$config['memcached']['enable'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Set some times needed by loads of scripts (it's dynamic, so we do it here!)
|
||||
$config['time']['now'] = time();
|
||||
$config['time']['now'] -= ($config['time']['now'] % 300);
|
||||
$config['time']['fourhour'] = ($config['time']['now'] - 14400);
|
||||
// time() - (4 * 60 * 60);
|
||||
$config['time']['sixhour'] = ($config['time']['now'] - 21600);
|
||||
|
@@ -119,12 +119,7 @@ function poll_sensor($device, $class, $unit) {
|
||||
log_event(ucfirst($class).' '.$sensor['sensor_descr'].' above threshold: '.$sensor_value." $unit (> ".$sensor['sensor_limit']." $unit)", $device, $class, $sensor['sensor_id']);
|
||||
}
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$memcache->set('sensor-'.$sensor['sensor_id'].'-value', $sensor_value);
|
||||
}
|
||||
else {
|
||||
dbUpdate(array('sensor_current' => $sensor_value), 'sensors', '`sensor_class` = ? AND `sensor_id` = ?', array($class, $sensor['sensor_id']));
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
}//end poll_sensor()
|
||||
|
@@ -47,14 +47,7 @@ foreach (dbFetchRows('SELECT * FROM mempools WHERE device_id = ?', array($device
|
||||
$mempool['state']['mempool_lowestfree'] = $mempool['lowestfree'];
|
||||
}
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
d_echo($mempool['state']);
|
||||
|
||||
$memcache->set('mempool-'.$mempool['mempool_id'].'-value', $mempool['state']);
|
||||
}
|
||||
else {
|
||||
dbUpdate($mempool['state'], 'mempools', '`mempool_id` = ?', array($mempool['mempool_id']));
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
}//end foreach
|
||||
|
@@ -244,17 +244,6 @@ foreach ($ports as $port) {
|
||||
$this_port['ifDescr'] = $matches[1];
|
||||
}
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$state = $memcache->get('port-'.$port['port_id'].'-state');
|
||||
d_echo($state);
|
||||
|
||||
if (is_array($state)) {
|
||||
$port = array_merge($port, $state);
|
||||
}
|
||||
|
||||
unset($state);
|
||||
}
|
||||
|
||||
$polled_period = ($polled - $port['poll_time']);
|
||||
|
||||
$port['update'] = array();
|
||||
@@ -266,12 +255,6 @@ foreach ($ports as $port) {
|
||||
$port['update']['poll_period'] = $polled_period;
|
||||
}
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$port['state']['poll_time'] = $polled;
|
||||
$port['state']['poll_prev'] = $port['poll_time'];
|
||||
$port['state']['poll_period'] = $polled_period;
|
||||
}
|
||||
|
||||
// Copy ifHC[In|Out]Octets values to non-HC if they exist
|
||||
if ($this_port['ifHCInOctets'] > 0 && is_numeric($this_port['ifHCInOctets']) && $this_port['ifHCOutOctets'] > 0 && is_numeric($this_port['ifHCOutOctets'])) {
|
||||
echo 'HC ';
|
||||
@@ -400,11 +383,6 @@ foreach ($ports as $port) {
|
||||
$port['update'][$oid.'_prev'] = $port[$oid];
|
||||
}
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$port['state'][$oid] = $this_port[$oid];
|
||||
$port['state'][$oid.'_prev'] = $port[$oid];
|
||||
}
|
||||
|
||||
$oid_prev = $oid.'_prev';
|
||||
if (isset($port[$oid])) {
|
||||
$oid_diff = ($this_port[$oid] - $port[$oid]);
|
||||
@@ -422,11 +400,6 @@ foreach ($ports as $port) {
|
||||
$port['update'][$oid.'_delta'] = $oid_diff;
|
||||
}
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$port['state'][$oid.'_rate'] = $oid_rate;
|
||||
$port['state'][$oid.'_delta'] = $oid_diff;
|
||||
}
|
||||
|
||||
d_echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n");
|
||||
}//end if
|
||||
}//end foreach
|
||||
@@ -451,13 +424,6 @@ foreach ($ports as $port) {
|
||||
echo 'bytes('.formatStorage($port['stats']['ifInOctets_diff']).'/'.formatStorage($port['stats']['ifOutOctets_diff']).')';
|
||||
echo 'pkts('.format_si($port['stats']['ifInUcastPkts_rate']).'pps/'.format_si($port['stats']['ifOutUcastPkts_rate']).'pps)';
|
||||
|
||||
// Store aggregate in/out state
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$port['state']['ifOctets_rate'] = ($port['stats']['ifOutOctets_rate'] + $port['stats']['ifInOctets_rate']);
|
||||
$port['state']['ifUcastPkts_rate'] = ($port['stats']['ifOutUcastPkts_rate'] + $port['stats']['ifInUcastPkts_rate']);
|
||||
$port['state']['ifErrors_rate'] = ($port['stats']['ifOutErrors_rate'] + $port['stats']['ifInErrors_rate']);
|
||||
}
|
||||
|
||||
// Port utilisation % threshold alerting. // FIXME allow setting threshold per-port. probably 90% of ports we don't care about.
|
||||
if ($config['alerts']['port_util_alert'] && $port['ignore'] == '0') {
|
||||
// Check for port saturation of $config['alerts']['port_util_perc'] or higher. Alert if we see this.
|
||||
@@ -547,13 +513,6 @@ foreach ($ports as $port) {
|
||||
include 'port-alcatel.inc.php';
|
||||
}
|
||||
|
||||
// Update Memcached
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
d_echo($port['state']);
|
||||
|
||||
$memcache->set('port-'.$port['port_id'].'-state', $port['state']);
|
||||
}
|
||||
|
||||
foreach ($port['update'] as $key => $val_check) {
|
||||
if (!isset($val_check)) {
|
||||
unset($port['update'][$key]);
|
||||
|
@@ -37,16 +37,7 @@ foreach (dbFetchRows('SELECT * FROM storage WHERE device_id = ?', array($device[
|
||||
|
||||
rrdtool_update($storage_rrd, $fields);
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$memcache->set('storage-'.$storage['storage_id'].'-used', $storage['used']);
|
||||
$memcache->set('storage-'.$storage['storage_id'].'-free', $storage['free']);
|
||||
$memcache->set('storage-'.$storage['storage_id'].'-size', $storage['size']);
|
||||
$memcache->set('storage-'.$storage['storage_id'].'-units', $storage['units']);
|
||||
$memcache->set('storage-'.$storage['storage_id'].'-perc', $percent);
|
||||
}
|
||||
else {
|
||||
$update = dbUpdate(array('storage_used' => $storage['used'], 'storage_free' => $storage['free'], 'storage_size' => $storage['size'], 'storage_units' => $storage['units'], 'storage_perc' => $percent), 'storage', '`storage_id` = ?', array($storage['storage_id']));
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
}//end foreach
|
||||
|
Reference in New Issue
Block a user