diff --git a/doc/Extensions/Memcached.md b/doc/Extensions/Memcached.md new file mode 100644 index 000000000..ae55ff342 --- /dev/null +++ b/doc/Extensions/Memcached.md @@ -0,0 +1,16 @@ +# Memcached + +LibreNMS can store SQL results in memcached to achieve performance advantages of in-memory value storage and removing work load for frequent queries off the MySQL backend. + +To enable memcached in your install you need to have `memcached` installed and the PHP extension `php5-memcached` or `php-memcached` and add the following lines to your `config.php`: + +```php +$config['memcached']['enable'] = true; +$config['memcached']['host'] = "localhost"; +$config['memcached']['port'] = 11211; +``` + +By default values are kept for 4 Minutes inside the memcached, you can adjust this retention time by modifying the `$config['memcached']['ttl']` value to any desired amount of seconds. +It's strongly discouraged to set this above `300` (5 Minutes) to avoid interferences with the polling, discovery and alerting processes. + +If you use the Distributed Poller, you can point this to the same memcached instance. However a local memcached will perform better in any case. diff --git a/html/ajax_rulesuggest.php b/html/ajax_rulesuggest.php index bb49ecab2..cee773a2f 100644 --- a/html/ajax_rulesuggest.php +++ b/html/ajax_rulesuggest.php @@ -72,22 +72,16 @@ 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; - } + if ($term[0] == 'macros') { + foreach ($config['alert']['macros']['rule'] as $macro => $v) { + $chk[] = 'macros.'.$macro; } - else { - $tmp = dbFetchRows('SHOW COLUMNS FROM '.$term[0]); - foreach ($tmp as $tst) { - if (isset($tst['Field'])) { - $chk[] = $term[0].'.'.$tst['Field']; - } + } + else { + $tmp = dbFetchRows('SHOW COLUMNS FROM '.$term[0]); + foreach ($tmp as $tst) { + if (isset($tst['Field'])) { + $chk[] = $term[0].'.'.$tst['Field']; } } } @@ -95,29 +89,18 @@ if (isset($_GET['term'],$_GET['device_id'])) { $current = true; } else { - if ($config['memcached']['enable']) { - $chk = $memcache->get('rule-suggest-toplvl'); + $tmp = dbFetchRows("SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME = 'device_id'"); + foreach ($tmp as $tst) { + $chk[] = $tst['TABLE_NAME'].'.'; } - 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'].'.'; - } - - $chk[] = 'macros.'; - $chk[] = 'bills.'; - } + $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]; + $obj = levsort($_GET['term'], $chk); + $obj = array_chunk($obj, 20, true); + $obj = $obj[0]; $flds = array(); if ($current === true) { foreach ($obj as $fld) { diff --git a/html/includes/authentication/mysql.inc.php b/html/includes/authentication/mysql.inc.php index 84e119cea..c16e716f8 100644 --- a/html/includes/authentication/mysql.inc.php +++ b/html/includes/authentication/mysql.inc.php @@ -3,7 +3,7 @@ function authenticate($username, $password) { $encrypted_old = md5($password); - $row = dbFetchRow('SELECT username,password FROM `users` WHERE `username`= ?', array($username)); + $row = dbFetchRow('SELECT username,password FROM `users` WHERE `username`= ?', array($username), true); if ($row['username'] && $row['username'] == $username) { // Migrate from old, unhashed password if ($row['password'] == $encrypted_old) { @@ -36,7 +36,7 @@ function authenticate($username, $password) { function reauthenticate($sess_id, $token) { list($uname,$hash) = explode('|', $token); - $session = dbFetchRow("SELECT * FROM `session` WHERE `session_username` = '$uname' AND session_value='$sess_id'"); + $session = dbFetchRow("SELECT * FROM `session` WHERE `session_username` = '$uname' AND session_value='$sess_id'", array(), true); $hasher = new PasswordHash(8, false); if ($hasher->CheckPassword($uname.$session['session_token'], $hash)) { $_SESSION['username'] = $uname; @@ -59,7 +59,7 @@ function passwordscanchange($username='') { return 1; } else { - return dbFetchCell('SELECT can_modify_passwd FROM users WHERE username = ?', array($username)); + return dbFetchCell('SELECT can_modify_passwd FROM users WHERE username = ?', array($username), true); } }//end passwordscanchange() @@ -114,20 +114,20 @@ function adduser($username, $password, $level, $email='', $realname='', $can_mod function user_exists($username) { - $return = @dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username)); + $return = @dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username), true); return $return; }//end user_exists() function get_userlevel($username) { - return dbFetchCell('SELECT `level` FROM `users` WHERE `username` = ?', array($username)); + return dbFetchCell('SELECT `level` FROM `users` WHERE `username` = ?', array($username), true); }//end get_userlevel() function get_userid($username) { - return dbFetchCell('SELECT `user_id` FROM `users` WHERE `username` = ?', array($username)); + return dbFetchCell('SELECT `user_id` FROM `users` WHERE `username` = ?', array($username), true); }//end get_userid() @@ -158,7 +158,7 @@ function can_update_users() { function get_user($user_id) { - return dbFetchRow('SELECT * FROM `users` WHERE `user_id` = ?', array($user_id)); + return dbFetchRow('SELECT * FROM `users` WHERE `user_id` = ?', array($user_id), true); }//end get_user() diff --git a/html/includes/table/poll-log.inc.php b/html/includes/table/poll-log.inc.php index 0b0ce89c4..722c47d31 100644 --- a/html/includes/table/poll-log.inc.php +++ b/html/includes/table/poll-log.inc.php @@ -42,7 +42,7 @@ if ($rowCount != -1) { $sql = "SELECT D.device_id,D.hostname AS `hostname`, D.last_polled AS `last_polled`, `group_name`, D.last_polled_timetaken AS `last_polled_timetaken` $sql"; -foreach (dbFetchRows($sql) as $device) { +foreach (dbFetchRows($sql,array(),true) as $device) { if (empty($device['group_name'])) { $device['group_name'] = 'General'; } diff --git a/html/index.php b/html/index.php index c21b204d4..8d2503a39 100644 --- a/html/index.php +++ b/html/index.php @@ -32,7 +32,7 @@ function catchFatal() { } } -if (strpos($_SERVER['PATH_INFO'], "debug")) { +if (strpos($_SERVER['PATH_INFO'], "debug") || true) { $debug = "1"; ini_set('display_errors', 0); ini_set('display_startup_errors', 1); @@ -66,6 +66,8 @@ require 'includes/functions.inc.php'; require 'includes/vars.inc.php'; require 'includes/plugins.inc.php'; +$config['memcached']['ttl'] = $config['time']['now']+300; + Plugins::start(); $runtime_start = utime(); diff --git a/html/pages/deleted-ports.inc.php b/html/pages/deleted-ports.inc.php index 32b11b304..8f2895281 100644 --- a/html/pages/deleted-ports.inc.php +++ b/html/pages/deleted-ports.inc.php @@ -22,7 +22,7 @@ else if ($vars['purge']) { echo ''; echo ""; -foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) { +foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id",array(),true) as $interface) { $interface = ifLabel($interface, $interface); if (port_permitted($interface['port_id'], $interface['device_id'])) { echo ''; diff --git a/html/pages/device/edit.inc.php b/html/pages/device/edit.inc.php index 0448ac01d..86cc6d490 100644 --- a/html/pages/device/edit.inc.php +++ b/html/pages/device/edit.inc.php @@ -1,6 +1,7 @@ 'device', 'device' => $device['device_id'], diff --git a/html/pages/device/health/mempool.inc.php b/html/pages/device/health/mempool.inc.php index 2cfbcd207..c53189caf 100644 --- a/html/pages/device/health/mempool.inc.php +++ b/html/pages/device/health/mempool.inc.php @@ -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/'; @@ -55,4 +44,4 @@ foreach (dbFetchRows('SELECT * FROM `mempools` WHERE device_id = ?', array($devi echo ""; $i++; -}//end foreach \ No newline at end of file +}//end foreach diff --git a/html/pages/device/overview/generic/sensor.inc.php b/html/pages/device/overview/generic/sensor.inc.php index 39a841466..8b50d1de3 100644 --- a/html/pages/device/overview/generic/sensor.inc.php +++ b/html/pages/device/overview/generic/sensor.inc.php @@ -12,10 +12,6 @@ if (count($sensors)) { echo '
Purge All
'; 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'; } diff --git a/html/pages/device/overview/mempools.inc.php b/html/pages/device/overview/mempools.inc.php index 01895ee7d..639b33dd2 100644 --- a/html/pages/device/overview/mempools.inc.php +++ b/html/pages/device/overview/mempools.inc.php @@ -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']); diff --git a/html/pages/device/port.inc.php b/html/pages/device/port.inc.php index bd9c38acd..bdaacd127 100644 --- a/html/pages/device/port.inc.php +++ b/html/pages/device/port.inc.php @@ -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']; diff --git a/html/pages/device/ports.inc.php b/html/pages/device/ports.inc.php index d4cac0dbf..56d3ee542 100644 --- a/html/pages/device/ports.inc.php +++ b/html/pages/device/ports.inc.php @@ -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++; } diff --git a/html/pages/health/sensors.inc.php b/html/pages/health/sensors.inc.php index 7ed65f926..b882ab4d9 100644 --- a/html/pages/health/sensors.inc.php +++ b/html/pages/health/sensors.inc.php @@ -22,11 +22,6 @@ echo ''; 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'; } diff --git a/html/pages/settings.inc.php b/html/pages/settings.inc.php index d7170ee97..2f7a9517e 100644 --- a/html/pages/settings.inc.php +++ b/html/pages/settings.inc.php @@ -24,6 +24,7 @@ * @subpackage Page */ $pagetitle[] = 'Global Settings'; +$config['memcached']['enable'] = false; ?>
diff --git a/includes/dbFacile.mysql.php b/includes/dbFacile.mysql.php index 0d1d7150c..bdcce1ac1 100644 --- a/includes/dbFacile.mysql.php +++ b/includes/dbFacile.mysql.php @@ -238,8 +238,15 @@ function dbDelete($table, $where=null, $parameters=array()) { * */ -function dbFetchRows($sql, $parameters=array()) { - global $db_stats; +function dbFetchRows($sql, $parameters=array(), $nocache=false) { + global $db_stats, $config; + + if ($config['memcached']['enable'] && $nocache === false) { + $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'] && $nocache === false) { + $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); + } return $rows; } @@ -273,8 +283,8 @@ function dbFetchRows($sql, $parameters=array()) { * */ -function dbFetch($sql, $parameters=array()) { - return dbFetchRows($sql, $parameters); +function dbFetch($sql, $parameters=array(), $nocache=false) { + return dbFetchRows($sql, $parameters, $nocache); /* // for now, don't do the iterator thing $result = dbQuery($sql, $parameters); @@ -295,8 +305,15 @@ function dbFetch($sql, $parameters=array()) { * */ -function dbFetchRow($sql=null, $parameters=array()) { - global $db_stats; +function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { + global $db_stats, $config; + + if ($config['memcached']['enable'] && $nocache === false) { + $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'] && $nocache === false) { + $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); + } return $row; } else { @@ -324,10 +344,10 @@ function dbFetchRow($sql=null, $parameters=array()) { * */ -function dbFetchCell($sql, $parameters=array()) { +function dbFetchCell($sql, $parameters=array(), $nocache=false) { global $db_stats; $time_start = microtime(true); - $row = dbFetchRow($sql, $parameters); + $row = dbFetchRow($sql, $parameters, $nocache); if ($row) { return array_shift($row); // shift first field off first row @@ -349,11 +369,11 @@ function dbFetchCell($sql, $parameters=array()) { * */ -function dbFetchColumn($sql, $parameters=array()) { +function dbFetchColumn($sql, $parameters=array(), $nocache=false) { global $db_stats; $time_start = microtime(true); $cells = array(); - foreach (dbFetch($sql, $parameters) as $row) { + foreach (dbFetch($sql, $parameters, $nocache) as $row) { $cells[] = array_shift($row); } diff --git a/includes/dbFacile.mysqli.php b/includes/dbFacile.mysqli.php index 2408ca990..9e49491a6 100644 --- a/includes/dbFacile.mysqli.php +++ b/includes/dbFacile.mysqli.php @@ -239,8 +239,15 @@ function dbDelete($table, $where=null, $parameters=array()) { * */ -function dbFetchRows($sql, $parameters=array()) { - global $db_stats; +function dbFetchRows($sql, $parameters=array(), $nocache=false) { + global $db_stats, $config; + + if ($config['memcached']['enable'] && $nocache === false) { + $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 +259,9 @@ function dbFetchRows($sql, $parameters=array()) { } mysqli_free_result($result); + if ($config['memcached']['enable'] && $nocache === false) { + $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); + } return $rows; } @@ -274,8 +284,8 @@ function dbFetchRows($sql, $parameters=array()) { * */ -function dbFetch($sql, $parameters=array()) { - return dbFetchRows($sql, $parameters); +function dbFetch($sql, $parameters=array(), $nocache=false) { + return dbFetchRows($sql, $parameters, $nocache); /* // for now, don't do the iterator thing $result = dbQuery($sql, $parameters); @@ -296,8 +306,15 @@ function dbFetch($sql, $parameters=array()) { * */ -function dbFetchRow($sql=null, $parameters=array()) { - global $db_stats; +function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { + global $db_stats, $config; + + if ($config['memcached']['enable'] && $nocache === false) { + $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 +326,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'] && $nocache === false) { + $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); + } return $row; } else { @@ -325,10 +345,11 @@ function dbFetchRow($sql=null, $parameters=array()) { * */ -function dbFetchCell($sql, $parameters=array()) { - global $db_stats; +function dbFetchCell($sql, $parameters=array(), $nocache=false) { + global $db_stats, $config; + $time_start = microtime(true); - $row = dbFetchRow($sql, $parameters); + $row = dbFetchRow($sql, $parameters, $nocache); if ($row) { return array_shift($row); // shift first field off first row @@ -350,11 +371,11 @@ function dbFetchCell($sql, $parameters=array()) { * */ -function dbFetchColumn($sql, $parameters=array()) { +function dbFetchColumn($sql, $parameters=array(), $nocache=false) { global $db_stats; $time_start = microtime(true); $cells = array(); - foreach (dbFetch($sql, $parameters) as $row) { + foreach (dbFetch($sql, $parameters, $nocache) as $row) { $cells[] = array_shift($row); } @@ -375,9 +396,9 @@ function dbFetchColumn($sql, $parameters=array()) { */ -function dbFetchKeyValue($sql, $parameters=array()) { +function dbFetchKeyValue($sql, $parameters=array(), $nocache=false) { $data = array(); - foreach (dbFetch($sql, $parameters) as $row) { + foreach (dbFetch($sql, $parameters, $nocache) as $row) { $key = array_shift($row); if (sizeof($row) == 1) { // if there were only 2 fields in the result diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index c1a86e0c1..e42195015 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -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 diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 40162649c..327e5e574 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -30,6 +30,19 @@ else { $database_db = mysql_select_db($config['db_name'], $database_link); } +if ($config['memcached']['enable'] === true) { + if (class_exists('Memcached')) { + $config['memcached']['ttl'] = 60; + $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,19 +1716,6 @@ 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); diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 927163bad..bbdad009c 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -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'])); - } + dbUpdate(array('sensor_current' => $sensor_value), 'sensors', '`sensor_class` = ? AND `sensor_id` = ?', array($class, $sensor['sensor_id'])); }//end foreach }//end poll_sensor() diff --git a/includes/polling/mempools.inc.php b/includes/polling/mempools.inc.php index 01188b8a6..a36196c1d 100644 --- a/includes/polling/mempools.inc.php +++ b/includes/polling/mempools.inc.php @@ -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'])); - } + dbUpdate($mempool['state'], 'mempools', '`mempool_id` = ?', array($mempool['mempool_id'])); echo "\n"; }//end foreach diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index cea5abca4..88492bf6a 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -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]); diff --git a/includes/polling/storage.inc.php b/includes/polling/storage.inc.php index 6b2e662f6..23cff2e47 100644 --- a/includes/polling/storage.inc.php +++ b/includes/polling/storage.inc.php @@ -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'])); - } + $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