Ejemplo n.º 1
0
 /**
  * Generate MySQL status information.
  * Additionally generate MySQL status after 10 seconds delay to see the difference.
  *
  * @return array
  * @throws Exception
  */
 protected function _generateMysqlStatusData()
 {
     // MySQL Status
     $data = array();
     $importantConfig = array('Aborted_clients', 'Aborted_connects', 'Com_select', 'Connections', 'Created_tmp_disk_tables', 'Created_tmp_files', 'Created_tmp_tables', 'Handler_read_rnd_next', 'Innodb_buffer_pool_read_requests', 'Innodb_buffer_pool_write_requests', 'Innodb_log_waits', 'Innodb_log_write_requests', 'Innodb_log_writes', 'Open_files', 'Open_streams', 'Open_table_definitions', 'Open_tables', 'Opened_files', 'Opened_table_definitions', 'Opened_tables', 'Qcache_lowmem_prunes', 'Select_full_join', 'Select_full_range_join', 'Select_range', 'Select_range_check', 'Select_scan', 'Slow_queries', 'Slave_running', 'Sort_range', 'Sort_rows', 'Sort_scan', 'Table_locks_immediate', 'Table_locks_waited', 'Threads_cached', 'Threads_connected', 'Threads_created', 'Threads_running');
     try {
         if (!$this->_readConnection) {
             throw new Exception('Cant\'t connect to DB. MySQL Status data can\'t be collected.');
         }
         $variables = $this->_readConnection->fetchPairs('SHOW GLOBAL STATUS');
         $this->_log(null, '10 seconds wait time to collect MySQL status data:');
         for ($i = 1; $i <= 10; $i++) {
             $this->_log(null, $i . '...');
             sleep(1);
         }
         $variablesAfter10Sec = $this->_readConnection->fetchPairs('SHOW GLOBAL STATUS');
         if ($variables && $variablesAfter10Sec) {
             foreach ($variables as $name => $value) {
                 if (!in_array($name, $importantConfig)) {
                     continue;
                 }
                 $valueAfter10Sec = 'n/a';
                 if (isset($variablesAfter10Sec[$name])) {
                     $difference = '';
                     if (is_numeric($variablesAfter10Sec[$name])) {
                         $difference = $variablesAfter10Sec[$name] - $value;
                         if ($difference != 0) {
                             $difference = ' (diff: ' . ($difference > 0 ? '+' : '') . $difference . ')';
                         } else {
                             $difference = '';
                         }
                     }
                     $valueAfter10Sec = $variablesAfter10Sec[$name] . $difference;
                 }
                 $data[] = array($name, $value, $valueAfter10Sec);
             }
         }
         unset($variables, $variablesAfter10Sec);
     } catch (Exception $e) {
         $this->_log($e);
     }
     $systemReport = array();
     $systemReport['MySQL Status'] = array('header' => array('Variable', 'Value', 'Value after 10 sec'), 'data' => $data);
     return $systemReport;
 }