From 2e791308f123b7cd5f56b864780062a6dbce3ad7 Mon Sep 17 00:00:00 2001 From: laf Date: Thu, 19 Nov 2015 10:20:56 +0000 Subject: [PATCH] Centralised innodb buffer check and added to validate --- daily.php | 17 +++++------------ includes/functions.php | 28 ++++++++++++++++++++++++++++ validate.php | 7 +++++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/daily.php b/daily.php index 8569f1c9aa..7205a1f5b9 100644 --- a/daily.php +++ b/daily.php @@ -13,10 +13,8 @@ require 'includes/functions.php'; $options = getopt('f:'); if ($options['f'] === 'update') { - $pool_size = dbFetchCell('SELECT @@innodb_buffer_pool_size'); - // The following query is from the excellent mysqltuner.pl by Major Hayden https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl - $pool_used = dbFetchCell('SELECT SUM(DATA_LENGTH+INDEX_LENGTH) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ("information_schema", "performance_schema", "mysql") AND ENGINE = "InnoDB" GROUP BY ENGINE ORDER BY ENGINE ASC'); - if ($pool_used > $pool_size) { + $innodb_buffer = innodb_buffer_check(); + if ($innodb_buffer['used'] > $innodb_buffer['size']) { if (!empty($config['alert']['default_mail'])) { $subject = $config['project_name'] . ' auto-update action required'; $message = ' @@ -26,19 +24,14 @@ We have just tried to update your installation but it looks like the InnoDB buff Because of this we have stopped the auto-update running to ensure your system is ok. -You currently have a configured innodb_buffer_pool_size of ' . $pool_size / 1024 / 1024 . ' MiB but is currently using ' . $pool_used / 1024 / 1024 . ' MiB +You currently have a configured innodb_buffer_pool_size of ' . $innodb_buffer['size'] / 1024 / 1024 . ' MiB but is currently using ' . $innodb_buffer['used'] / 1024 / 1024 . ' MiB Take a look at https://dev.mysql.com/doc/refman/5.6/en/innodb-buffer-pool.html for further details. The ' . $config['project_name'] . ' team.'; send_mail($config['alert']['default_mail'],$subject,$message,$html=false); - } else { - echo 'InnoDB Buffersize too small.'.PHP_EOL; - echo 'Current size: '.($pool_size / 1024 / 1024).' MiB'.PHP_EOL; - echo 'Minimum Required: '.($pool_used / 1024 / 1024).' MiB'.PHP_EOL; - echo 'To ensure integrity, we\'re not going to pull any updates until the buffersize has been adjusted.'.PHP_EOL; - echo 'Config proposal: "innodb_buffer_pool_size = '.pow(2,ceil(log(($pool_used / 1024 / 1024),2))).'M"'.PHP_EOL; - } + } + echo warn_innodb_buffer($innodb_buffer); exit(2); } else { diff --git a/includes/functions.php b/includes/functions.php index 11ff1531fa..318656fc1a 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1278,3 +1278,31 @@ function host_exists($hostname) { return false; } } + +/** + * Check the innodb buffer size + * + * @return array including the current set size and the currently used buffer +**/ +function innodb_buffer_check() { + $pool['size'] = dbFetchCell('SELECT @@innodb_buffer_pool_size'); + // The following query is from the excellent mysqltuner.pl by Major Hayden https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl + $pool['used'] = dbFetchCell('SELECT SUM(DATA_LENGTH+INDEX_LENGTH) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ("information_schema", "performance_schema", "mysql") AND ENGINE = "InnoDB" GROUP BY ENGINE ORDER BY ENGINE ASC'); + return $pool; +} + +/** + * Print warning about InnoDB buffer size + * + * @param array $innodb_buffer An array that contains the used and current size + * + * @return string $output +**/ +function warn_innodb_buffer($innodb_buffer) { + $output = 'InnoDB Buffersize too small.'.PHP_EOL; + $output .= 'Current size: '.($innodb_buffer['size'] / 1024 / 1024).' MiB'.PHP_EOL; + $output .= 'Minimum Required: '.($innodb_buffer['used'] / 1024 / 1024).' MiB'.PHP_EOL; + $output .= 'To ensure integrity, we\'re not going to pull any updates until the buffersize has been adjusted.'.PHP_EOL; + $output .= 'Config proposal: "innodb_buffer_pool_size = '.pow(2,ceil(log(($innodb_buffer['used'] / 1024 / 1024),2))).'M"'.PHP_EOL; + return $output; +} diff --git a/validate.php b/validate.php index dbfc89c4a3..2c03165876 100755 --- a/validate.php +++ b/validate.php @@ -93,6 +93,13 @@ if(strstr($strict_mode, 'STRICT_TRANS_TABLES')) { print_warn('You have MySQL STRICT_TRANS_TABLES enabled, it is advisable to disable this until full support has been added: https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html'); } +// Test for MySQL InnoDB buffer size +$innodb_buffer = innodb_buffer_check(); +if ($innodb_buffer['used'] > $innodb_buffer['size']) { + print_fail('Your Innodb buffer size is not big enough...'); + echo warn_innodb_buffer($innodb_buffer); +} + // Test transports if ($config['alerts']['email']['enable'] === true) { print_warn('You have the old alerting system enabled - this is to be deprecated on the 1st of June 2015: https://groups.google.com/forum/#!topic/librenms-project/1llxos4m0p4');