Two more fixes for Tracking in Drizzle
[phpmyadmin.git] / server_status.php
blob52a7a9b0037c6627acd2dcdfc1006f29d149588c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * displays status variables with descriptions and some hints an optmizing
5 * + reset status variables
7 * @package phpMyAdmin
8 */
10 /**
11 * no need for variables importing
12 * @ignore
14 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
15 define('PMA_NO_VARIABLES_IMPORT', true);
18 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true)
19 $GLOBALS['is_header_sent'] = true;
21 require_once './libraries/common.inc.php';
23 /**
24 * Ajax request
27 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
28 // Send with correct charset
29 header('Content-Type: text/html; charset=UTF-8');
31 // real-time charting data
32 if (isset($_REQUEST['chart_data'])) {
33 switch($_REQUEST['type']) {
34 // Process and Connections realtime chart
35 case 'proc':
36 $c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1);
37 $result = PMA_DBI_query('SHOW PROCESSLIST');
38 $num_procs = PMA_DBI_num_rows($result);
40 $ret = array(
41 'x' => microtime(true)*1000,
42 'y_proc' => $num_procs,
43 'y_conn' => $c['Connections']
46 exit(json_encode($ret));
48 // Query realtime chart
49 case 'queries':
50 if (PMA_DRIZZLE) {
51 $sql = "SELECT concat('Com_', variable_name), variable_value
52 FROM data_dictionary.GLOBAL_STATEMENTS
53 WHERE variable_value > 0
54 UNION
55 SELECT variable_name, variable_value
56 FROM data_dictionary.GLOBAL_STATUS
57 WHERE variable_name = 'Questions'";
58 $queries = PMA_DBI_fetch_result($sql, 0, 1);
59 } else {
60 $queries = PMA_DBI_fetch_result(
61 "SHOW GLOBAL STATUS
62 WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions')
63 AND Value > 0'", 0, 1);
65 cleanDeprecated($queries);
66 // admin commands are not queries
67 unset($queries['Com_admin_commands']);
68 $questions = $queries['Questions'];
69 unset($queries['Questions']);
71 //$sum=array_sum($queries);
72 $ret = array(
73 'x' => microtime(true)*1000,
74 'y' => $questions,
75 'pointInfo' => $queries
78 exit(json_encode($ret));
80 // Traffic realtime chart
81 case 'traffic':
82 $traffic = PMA_DBI_fetch_result(
83 "SHOW GLOBAL STATUS
84 WHERE Variable_name = 'Bytes_received'
85 OR Variable_name = 'Bytes_sent'", 0, 1);
87 $ret = array(
88 'x' => microtime(true)*1000,
89 'y_sent' => $traffic['Bytes_sent'],
90 'y_received' => $traffic['Bytes_received']
93 exit(json_encode($ret));
95 // Data for the monitor
96 case 'chartgrid':
97 $ret = json_decode($_REQUEST['requiredData'], true);
98 $statusVars = array();
99 $serverVars = array();
100 $sysinfo = $cpuload = $memory = 0;
101 $pName = '';
103 /* Accumulate all required variables and data */
104 // For each chart
105 foreach ($ret as $chart_id => $chartNodes) {
106 // For each data series
107 foreach ($chartNodes as $node_id => $nodeDataPoints) {
108 // For each data point in the series (usually just 1)
109 foreach ($nodeDataPoints as $point_id => $dataPoint) {
110 $pName = $dataPoint['name'];
112 switch ($dataPoint['type']) {
113 /* We only collect the status and server variables here to
114 * read them all in one query, and only afterwards assign them.
115 * Also do some white list filtering on the names
117 case 'servervar':
118 if (!preg_match('/[^a-zA-Z_]+/', $pName))
119 $serverVars[] = $pName;
120 break;
122 case 'statusvar':
123 if (!preg_match('/[^a-zA-Z_]+/', $pName))
124 $statusVars[] = $pName;
125 break;
127 case 'proc':
128 $result = PMA_DBI_query('SHOW PROCESSLIST');
129 $ret[$chart_id][$node_id][$point_id]['value'] = PMA_DBI_num_rows($result);
130 break;
132 case 'cpu':
133 if (!$sysinfo) {
134 require_once('libraries/sysinfo.lib.php');
135 $sysinfo = getSysInfo();
137 if (!$cpuload)
138 $cpuload = $sysinfo->loadavg();
140 if (PHP_OS == 'Linux') {
141 $ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle'];
142 $ret[$chart_id][$node_id][$point_id]['busy'] = $cpuload['busy'];
143 } else
144 $ret[$chart_id][$node_id][$point_id]['value'] = $cpuload['loadavg'];
146 break;
148 case 'memory':
149 if (!$sysinfo) {
150 require_once('libraries/sysinfo.lib.php');
151 $sysinfo = getSysInfo();
153 if (!$memory)
154 $memory = $sysinfo->memory();
156 $ret[$chart_id][$node_id][$point_id]['value'] = $memory[$pName];
157 break;
163 // Retrieve all required status variables
164 if (count($statusVars)) {
165 $statusVarValues = PMA_DBI_fetch_result(
166 "SHOW GLOBAL STATUS
167 WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1);
168 } else {
169 $statusVarValues = array();
172 // Retrieve all required server variables
173 if (count($serverVars)) {
174 $serverVarValues = PMA_DBI_fetch_result(
175 "SHOW GLOBAL VARIABLES
176 WHERE Variable_name='" . implode("' OR Variable_name='", $serverVars) . "'", 0, 1);
177 } else {
178 $serverVarValues = array();
181 // ...and now assign them
182 foreach ($ret as $chart_id => $chartNodes) {
183 foreach ($chartNodes as $node_id => $nodeDataPoints) {
184 foreach ($nodeDataPoints as $point_id => $dataPoint) {
185 switch($dataPoint['type']) {
186 case 'statusvar':
187 $ret[$chart_id][$node_id][$point_id]['value'] = $statusVarValues[$dataPoint['name']];
188 break;
189 case 'servervar':
190 $ret[$chart_id][$node_id][$point_id]['value'] = $serverVarValues[$dataPoint['name']];
191 break;
197 $ret['x'] = microtime(true)*1000;
199 exit(json_encode($ret));
203 if (isset($_REQUEST['log_data'])) {
204 if(PMA_MYSQL_INT_VERSION < 50106) exit('""');
206 $start = intval($_REQUEST['time_start']);
207 $end = intval($_REQUEST['time_end']);
209 if ($_REQUEST['type'] == 'slow') {
210 $q = 'SELECT start_time, user_host, Sec_to_Time(Sum(Time_to_Sec(query_time))) as query_time, Sec_to_Time(Sum(Time_to_Sec(lock_time))) as lock_time, '.
211 'SUM(rows_sent) AS rows_sent, SUM(rows_examined) AS rows_examined, db, sql_text, COUNT(sql_text) AS \'#\' '.
212 'FROM `mysql`.`slow_log` WHERE start_time > FROM_UNIXTIME(' . $start . ') '.
213 'AND start_time < FROM_UNIXTIME(' . $end . ') GROUP BY sql_text';
215 $result = PMA_DBI_try_query($q);
217 $return = array('rows' => array(), 'sum' => array());
218 $type = '';
220 while ($row = PMA_DBI_fetch_assoc($result)) {
221 $type = strtolower(substr($row['sql_text'], 0, strpos($row['sql_text'], ' ')));
223 switch($type) {
224 case 'insert':
225 case 'update':
226 // Cut off big inserts and updates, but append byte count therefor
227 if(strlen($row['sql_text']) > 220)
228 $row['sql_text'] = substr($row['sql_text'], 0, 200) . '... [' .
229 implode(' ', PMA_formatByteDown(strlen($row['sql_text']), 2, 2)) . ']';
231 break;
232 default:
233 break;
236 if(!isset($return['sum'][$type])) $return['sum'][$type] = 0;
237 $return['sum'][$type] += $row['#'];
238 $return['rows'][] = $row;
241 $return['sum']['TOTAL'] = array_sum($return['sum']);
242 $return['numRows'] = count($return['rows']);
244 PMA_DBI_free_result($result);
246 exit(json_encode($return));
249 if($_REQUEST['type'] == 'general') {
250 $limitTypes = (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes'])
251 ? 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ' : '';
253 $q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, server_id, argument, count(argument) as \'#\' '.
254 'FROM `mysql`.`general_log` WHERE command_type=\'Query\' '.
255 'AND event_time > FROM_UNIXTIME(' . $start . ') AND event_time < FROM_UNIXTIME(' . $end . ') '.
256 $limitTypes . 'GROUP by argument'; // HAVING count > 1';
258 $result = PMA_DBI_try_query($q);
260 $return = array('rows' => array(), 'sum' => array());
261 $type = '';
262 $insertTables = array();
263 $insertTablesFirst = -1;
264 $i = 0;
265 $removeVars = isset($_REQUEST['removeVariables']) && $_REQUEST['removeVariables'];
267 while ($row = PMA_DBI_fetch_assoc($result)) {
268 preg_match('/^(\w+)\s/', $row['argument'], $match);
269 $type = strtolower($match[1]);
271 if(!isset($return['sum'][$type])) $return['sum'][$type] = 0;
272 $return['sum'][$type] += $row['#'];
274 switch($type) {
275 case 'insert':
276 // Group inserts if selected
277 if($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i', $row['argument'], $matches)) {
278 $insertTables[$matches[2]]++;
279 if ($insertTables[$matches[2]] > 1) {
280 $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
282 // Add a ... to the end of this query to indicate that there's been other queries
283 if($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.')
284 $return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
286 // Group this value, thus do not add to the result list
287 continue 2;
288 } else {
289 $insertTablesFirst = $i;
290 $insertTables[$matches[2]] += $row['#'] - 1;
293 // No break here
295 case 'update':
296 // Cut off big inserts and updates, but append byte count therefor
297 if(strlen($row['argument']) > 220)
298 $row['argument'] = substr($row['argument'], 0, 200) . '... [' .
299 implode(' ', PMA_formatByteDown(strlen($row['argument'])), 2, 2) . ']';
301 break;
303 default: break;
306 $return['rows'][] = $row;
307 $i++;
310 $return['sum']['TOTAL'] = array_sum($return['sum']);
311 $return['numRows'] = count($return['rows']);
313 PMA_DBI_free_result($result);
315 exit(json_encode($return));
319 if (isset($_REQUEST['logging_vars'])) {
320 if(isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) {
321 $value = PMA_sqlAddslashes($_REQUEST['varValue']);
322 if(!is_numeric($value)) $value="'" . $value . "'";
324 if(! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName']))
325 PMA_DBI_query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value);
329 $loggingVars = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES WHERE Variable_name IN ("general_log","slow_query_log","long_query_time","log_output")', 0, 1);
330 exit(json_encode($loggingVars));
333 if(isset($_REQUEST['query_analyzer'])) {
334 $return = array();
336 if(strlen($_REQUEST['database']))
337 PMA_DBI_select_db($_REQUEST['database']);
339 if ($profiling = PMA_profilingSupported())
340 PMA_DBI_query('SET PROFILING=1;');
342 // Do not cache query
343 $query = preg_replace('/^(\s*SELECT)/i', '\\1 SQL_NO_CACHE', $_REQUEST['query']);
345 $result = PMA_DBI_try_query($query);
346 $return['affectedRows'] = $GLOBALS['cached_affected_rows'];
348 $result = PMA_DBI_try_query('EXPLAIN ' . $query);
349 while ($row = PMA_DBI_fetch_assoc($result)) {
350 $return['explain'][] = $row;
353 // In case an error happened
354 $return['error'] = PMA_DBI_getError();
356 PMA_DBI_free_result($result);
358 if($profiling) {
359 $return['profiling'] = array();
360 $result = PMA_DBI_try_query('SELECT seq,state,duration FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID=1 ORDER BY seq');
361 while ($row = PMA_DBI_fetch_assoc($result)) {
362 $return['profiling'][]= $row;
364 PMA_DBI_free_result($result);
367 exit(json_encode($return));
370 if(isset($_REQUEST['advisor'])) {
371 include('libraries/Advisor.class.php');
372 $advisor = new Advisor();
373 exit(json_encode($advisor->run()));
379 * Replication library
381 if (PMA_DRIZZLE) {
382 $server_master_status = false;
383 $server_slave_status = false;
384 } else {
385 require './libraries/replication.inc.php';
386 require_once './libraries/replication_gui.lib.php';
390 * JS Includes
393 $GLOBALS['js_include'][] = 'server_status.js';
394 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
395 $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
396 $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
397 // Charting
398 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
399 /* Files required for chart exporting */
400 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
401 /* < IE 9 doesn't support canvas natively */
402 if(PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
403 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
405 $GLOBALS['js_include'][] = 'canvg/canvg.js';
408 * flush status variables if requested
410 if (isset($_REQUEST['flush'])) {
411 $_flush_commands = array(
412 'STATUS',
413 'TABLES',
414 'QUERY CACHE',
417 if (in_array($_REQUEST['flush'], $_flush_commands)) {
418 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
420 unset($_flush_commands);
424 * Kills a selected process
426 if (!empty($_REQUEST['kill'])) {
427 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
428 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
429 } else {
430 $message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
432 $message->addParam($_REQUEST['kill']);
433 //$message->display();
439 * get status from server
441 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
442 if (PMA_DRIZZLE) {
443 // Drizzle doesn't put query statistics into variables, add it
444 $sql = "SELECT concat('Com_', variable_name), variable_value
445 FROM data_dictionary.GLOBAL_STATEMENTS";
446 $statements = PMA_DBI_fetch_result($sql, 0, 1);
447 $server_status = array_merge($server_status, $statements);
451 * for some calculations we require also some server settings
453 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
456 * cleanup of some deprecated values
458 cleanDeprecated($server_status);
461 * calculate some values
463 // Key_buffer_fraction
464 if (isset($server_status['Key_blocks_unused'])
465 && isset($server_variables['key_cache_block_size'])
466 && isset($server_variables['key_buffer_size'])) {
467 $server_status['Key_buffer_fraction_%'] =
469 - $server_status['Key_blocks_unused']
470 * $server_variables['key_cache_block_size']
471 / $server_variables['key_buffer_size']
472 * 100;
473 } elseif (isset($server_status['Key_blocks_used'])
474 && isset($server_variables['key_buffer_size'])) {
475 $server_status['Key_buffer_fraction_%'] =
476 $server_status['Key_blocks_used']
477 * 1024
478 / $server_variables['key_buffer_size'];
481 // Ratio for key read/write
482 if (isset($server_status['Key_writes'])
483 && isset($server_status['Key_write_requests'])
484 && $server_status['Key_write_requests'] > 0) {
485 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
488 if (isset($server_status['Key_reads'])
489 && isset($server_status['Key_read_requests'])
490 && $server_status['Key_read_requests'] > 0) {
491 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
494 // Threads_cache_hitrate
495 if (isset($server_status['Threads_created'])
496 && isset($server_status['Connections'])
497 && $server_status['Connections'] > 0) {
499 $server_status['Threads_cache_hitrate_%'] =
500 100 - $server_status['Threads_created'] / $server_status['Connections'] * 100;
504 * split variables in sections
506 $allocations = array(
507 // variable name => section
508 // variable names match when they begin with the given string
510 'Com_' => 'com',
511 'Innodb_' => 'innodb',
512 'Ndb_' => 'ndb',
513 'Handler_' => 'handler',
514 'Qcache_' => 'qcache',
515 'Threads_' => 'threads',
516 'Slow_launch_threads' => 'threads',
518 'Binlog_cache_' => 'binlog_cache',
519 'Created_tmp_' => 'created_tmp',
520 'Key_' => 'key',
522 'Delayed_' => 'delayed',
523 'Not_flushed_delayed_rows' => 'delayed',
525 'Flush_commands' => 'query',
526 'Last_query_cost' => 'query',
527 'Slow_queries' => 'query',
528 'Queries' => 'query',
529 'Prepared_stmt_count' => 'query',
531 'Select_' => 'select',
532 'Sort_' => 'sort',
534 'Open_tables' => 'table',
535 'Opened_tables' => 'table',
536 'Open_table_definitions' => 'table',
537 'Opened_table_definitions' => 'table',
538 'Table_locks_' => 'table',
540 'Rpl_status' => 'repl',
541 'Slave_' => 'repl',
543 'Tc_' => 'tc',
545 'Ssl_' => 'ssl',
547 'Open_files' => 'files',
548 'Open_streams' => 'files',
549 'Opened_files' => 'files',
552 $sections = array(
553 // section => section name (description)
554 'com' => 'Com',
555 'query' => __('SQL query'),
556 'innodb' => 'InnoDB',
557 'ndb' => 'NDB',
558 'handler' => __('Handler'),
559 'qcache' => __('Query cache'),
560 'threads' => __('Threads'),
561 'binlog_cache' => __('Binary log'),
562 'created_tmp' => __('Temporary data'),
563 'delayed' => __('Delayed inserts'),
564 'key' => __('Key cache'),
565 'select' => __('Joins'),
566 'repl' => __('Replication'),
567 'sort' => __('Sorting'),
568 'table' => __('Tables'),
569 'tc' => __('Transaction coordinator'),
570 'files' => __('Files'),
571 'ssl' => 'SSL',
572 'other' => __('Other')
576 * define some needfull links/commands
578 // variable or section name => (name => url)
579 $links = array();
581 $links['table'][__('Flush (close) all tables')]
582 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
583 $links['table'][__('Show open tables')]
584 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
585 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
587 if ($server_master_status) {
588 $links['repl'][__('Show slave hosts')]
589 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
590 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
591 $links['repl'][__('Show master status')] = '#replication_master';
593 if ($server_slave_status) {
594 $links['repl'][__('Show slave status')] = '#replication_slave';
597 $links['repl']['doc'] = 'replication';
599 $links['qcache'][__('Flush query cache')]
600 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
601 PMA_generate_common_url();
602 $links['qcache']['doc'] = 'query_cache';
604 //$links['threads'][__('Show processes')]
605 // = 'server_processlist.php?' . PMA_generate_common_url();
606 $links['threads']['doc'] = 'mysql_threads';
608 $links['key']['doc'] = 'myisam_key_cache';
610 $links['binlog_cache']['doc'] = 'binary_log';
612 $links['Slow_queries']['doc'] = 'slow_query_log';
614 $links['innodb'][__('Variables')]
615 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
616 $links['innodb'][__('InnoDB Status')]
617 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
618 PMA_generate_common_url();
619 $links['innodb']['doc'] = 'innodb';
622 // Variable to contain all com_ variables (query statistics)
623 $used_queries = array();
625 // Variable to map variable names to their respective section name (used for js category filtering)
626 $allocationMap = array();
628 // Variable to mark used sections
629 $categoryUsed = array();
631 // sort vars into arrays
632 foreach ($server_status as $name => $value) {
633 $section_found = false;
634 foreach ($allocations as $filter => $section) {
635 if (strpos($name, $filter) !== false) {
636 $allocationMap[$name] = $section;
637 $categoryUsed[$section] = true;
638 $section_found = true;
639 if ($section == 'com' && $value > 0) $used_queries[$name] = $value;
640 break; // Only exits inner loop
643 if (!$section_found) {
644 $allocationMap[$name] = 'other';
645 $categoryUsed['other'] = true;
649 if(PMA_DRIZZLE) {
650 $used_queries = PMA_DBI_fetch_result('SELECT * FROM data_dictionary.global_statements', 0, 1);
651 unset($used_queries['admin_commands']);
652 } else {
653 // admin commands are not queries (e.g. they include COM_PING, which is excluded from $server_status['Questions'])
654 unset($used_queries['Com_admin_commands']);
657 /* Ajax request refresh */
658 if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
659 switch($_REQUEST['show']) {
660 case 'query_statistics':
661 printQueryStatistics();
662 exit();
663 case 'server_traffic':
664 printServerTraffic();
665 exit();
666 case 'variables_table':
667 // Prints the variables table
668 printVariablesTable();
669 exit();
671 default:
672 break;
676 $server_db_isLocal = strtolower($cfg['Server']['host']) == 'localhost'
677 || $cfg['Server']['host'] == '127.0.0.1'
678 || $cfg['Server']['host'] == '::1';
680 PMA_AddJSCode('pma_token = \'' . $_SESSION[' PMA_token '] . "';\n" .
681 'url_query = \'' . str_replace('&amp;', '&', PMA_generate_common_url($db)) . "';\n" .
682 'server_time_diff = new Date().getTime() - ' . (microtime(true)*1000) . ";\n" .
683 'server_os = \'' . PHP_OS . "';\n" .
684 'is_superuser = ' . (PMA_isSuperuser() ? 'true' : 'false') . ";\n" .
685 'server_db_isLocal = ' . ($server_db_isLocal ? 'true' : 'false') . ";\n" .
686 'profiling_docu = \'' . PMA_showMySQLDocu('general-thread-states', 'general-thread-states') . "';\n" .
687 'explain_docu = \'' . PMA_showMySQLDocu('explain-output', 'explain-output') . ";'\n");
690 * start output
694 * Does the common work
696 require './libraries/server_common.inc.php';
701 * Displays the links
703 require './libraries/server_links.inc.php';
706 <div id="serverstatus">
707 <h2><?php
709 * Displays the sub-page heading
711 if ($GLOBALS['cfg']['MainPageIconic']) {
712 echo '<img class="icon ic_s_status" src="themes/dot.gif" width="16" height="16" alt="" />';
715 echo __('Runtime Information');
717 ?></h2>
718 <div id="serverStatusTabs">
719 <ul>
720 <li><a href="#statustabs_traffic"><?php echo __('Server'); ?></a></li>
721 <li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
722 <li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
723 <li class="jsfeature"><a href="#statustabs_charting"><?php echo __('Monitor'); ?></a></li>
724 <li class="jsfeature"><a href="#statustabs_advisor"><?php echo __('Advisor'); ?></a></li>
725 </ul>
727 <div id="statustabs_traffic" class="clearfloat">
728 <div class="buttonlinks jsfeature">
729 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&amp;' . PMA_generate_common_url(); ?>" >
730 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
731 <?php echo __('Refresh'); ?>
732 </a>
733 <span class="refreshList" style="display:none;">
734 <label for="id_trafficChartRefresh"><?php echo __('Refresh rate: '); ?></label>
735 <?php refreshList('trafficChartRefresh'); ?>
736 </span>
738 <a class="tabChart livetrafficLink" href="#">
739 <?php echo __('Live traffic chart'); ?>
740 </a>
741 <a class="tabChart liveconnectionsLink" href="#">
742 <?php echo __('Live conn./process chart'); ?>
743 </a>
744 </div>
745 <div class="tabInnerContent">
746 <?php printServerTraffic(); ?>
747 </div>
748 </div>
749 <div id="statustabs_queries" class="clearfloat">
750 <div class="buttonlinks jsfeature">
751 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
752 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
753 <?php echo __('Refresh'); ?>
754 </a>
755 <span class="refreshList" style="display:none;">
756 <label for="id_queryChartRefresh"><?php echo __('Refresh rate: '); ?></label>
757 <?php refreshList('queryChartRefresh'); ?>
758 </span>
759 <a class="tabChart livequeriesLink" href="#">
760 <?php echo __('Live query chart'); ?>
761 </a>
762 </div>
763 <div class="tabInnerContent">
764 <?php printQueryStatistics(); ?>
765 </div>
766 </div>
767 <div id="statustabs_allvars" class="clearfloat">
768 <fieldset id="tableFilter" class="jsfeature">
769 <div class="buttonlinks">
770 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
771 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
772 <?php echo __('Refresh'); ?>
773 </a>
774 </div>
775 <legend>Filters</legend>
776 <div class="formelement">
777 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
778 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
779 </div>
780 <div class="formelement">
781 <input type="checkbox" name="filterAlert" id="filterAlert" />
782 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
783 </div>
784 <div class="formelement">
785 <select id="filterCategory" name="filterCategory">
786 <option value=''><?php echo __('Filter by category...'); ?></option>
787 <?php
788 foreach ($sections as $section_id => $section_name) {
789 if (isset($categoryUsed[$section_id])) {
791 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
792 <?php
796 </select>
797 </div>
798 <div class="formelement">
799 <input type="checkbox" name="dontFormat" id="dontFormat" />
800 <label for="dontFormat"><?php echo __('Show unformatted values'); ?></label>
801 </div>
802 </fieldset>
803 <div id="linkSuggestions" class="defaultLinks" style="display:none">
804 <p class="notice"><?php echo __('Related links:'); ?>
805 <?php
806 foreach ($links as $section_name => $section_links) {
807 echo '<span class="status_' . $section_name . '"> ';
808 $i=0;
809 foreach ($section_links as $link_name => $link_url) {
810 if ($i > 0) echo ', ';
811 if ('doc' == $link_name) {
812 echo PMA_showMySQLDocu($link_url, $link_url);
813 } else {
814 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
816 $i++;
818 echo '</span>';
820 unset($link_url, $link_name, $i);
822 </p>
823 </div>
824 <div class="tabInnerContent">
825 <?php printVariablesTable(); ?>
826 </div>
827 </div>
829 <div id="statustabs_charting" class="jsfeature">
830 <?php printMonitor(); ?>
831 </div>
833 <div id="statustabs_advisor" class="jsfeature">
834 <div class="tabLinks">
835 <img src="themes/dot.gif" class="icon ic_play" alt="" /> <a href="#startAnalyzer"><?php echo __('Run analyzer'); ?></a>
836 <img src="themes/dot.gif" class="icon ic_b_help" alt="" /> <a href="#openAdvisorInstructions"><?php echo __('Instructions'); ?></a>
837 </div>
838 <div class="tabInnerContent clearfloat">
839 </div>
840 <div id="advisorInstructionsDialog" style="display:none;">
841 <?php
842 echo '<p>';
843 echo __('The Advisor system can provide recommendations on server variables by analyzing the server status variables.');
844 echo '</p> <p>';
845 echo __('Do note however that this system provides recommendations based on simple calculations and by rule of thumb which may not necessarily apply to your system.');
846 echo '</p> <p>';
847 echo __('Prior to changing any of the configuration, be sure to know what you are changing (by reading the documentation) and how to undo the change. Wrong tuning can have a very negative effect on performance.');
848 echo '</p> <p>';
849 echo __('The best way to tune your system would be to change only one setting at a time, observe or benchmark your database, and undo the change if there was no clearly measurable improvement.');
850 echo '</p>';
852 </div>
853 </div>
854 </div>
855 </div>
857 <?php
859 function printQueryStatistics()
861 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
863 $hour_factor = 3600 / $server_status['Uptime'];
865 $total_queries = array_sum($used_queries);
868 <h3 id="serverstatusqueries">
869 <?php
870 /* l10n: Questions is the name of a MySQL Status variable */
871 echo sprintf(__('Questions since startup: %s'), PMA_formatNumber($total_queries, 0)) . ' ';
872 echo PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_Questions');
874 <br />
875 <span>
876 <?php
877 echo '&oslash; ' . __('per hour') . ': ';
878 echo PMA_formatNumber($total_queries * $hour_factor, 0);
879 echo '<br />';
881 echo '&oslash; ' . __('per minute') . ': ';
882 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
883 echo '<br />';
885 if ($total_queries / $server_status['Uptime'] >= 1) {
886 echo '&oslash; ' . __('per second') . ': ';
887 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
890 </span>
891 </h3>
892 <?php
894 // reverse sort by value to show most used statements first
895 arsort($used_queries);
897 $odd_row = true;
898 $count_displayed_rows = 0;
899 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
903 <table id="serverstatusqueriesdetails" class="data sortable noclick">
904 <col class="namecol" />
905 <col class="valuecol" span="3" />
906 <thead>
907 <tr><th><?php echo __('Statements'); ?></th>
908 <th><?php
909 /* l10n: # = Amount of queries */
910 echo __('#');
912 </th>
913 <th>&oslash; <?php echo __('per hour'); ?></th>
914 <th>%</th>
915 </tr>
916 </thead>
917 <tbody>
919 <?php
920 $chart_json = array();
921 $query_sum = array_sum($used_queries);
922 $other_sum = 0;
923 foreach ($used_queries as $name => $value) {
924 $odd_row = !$odd_row;
926 // For the percentage column, use Questions - Connections, because
927 // the number of connections is not an item of the Query types
928 // but is included in Questions. Then the total of the percentages is 100.
929 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
931 // Group together values that make out less than 2% into "Other", but only if we have more than 6 fractions already
932 if ($value < $query_sum * 0.02 && count($chart_json)>6)
933 $other_sum += $value;
934 else $chart_json[$name] = $value;
936 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
937 <th class="name"><?php echo htmlspecialchars($name); ?></th>
938 <td class="value"><?php echo htmlspecialchars(PMA_formatNumber($value, 5, 0, true)); ?></td>
939 <td class="value"><?php echo
940 htmlspecialchars(PMA_formatNumber($value * $hour_factor, 4, 1, true)); ?></td>
941 <td class="value"><?php echo
942 htmlspecialchars(PMA_formatNumber($value * $perc_factor, 0, 2)); ?>%</td>
943 </tr>
944 <?php
947 </tbody>
948 </table>
950 <div id="serverstatusquerieschart">
951 <span style="display:none;">
952 <?php
953 if ($other_sum > 0)
954 $chart_json[__('Other')] = $other_sum;
956 echo json_encode($chart_json);
958 </span>
959 </div>
960 <?php
963 function printServerTraffic()
965 global $server_status, $PMA_PHP_SELF;
966 global $server_master_status, $server_slave_status, $replication_types;
968 $hour_factor = 3600 / $server_status['Uptime'];
971 * starttime calculation
973 $start_time = PMA_DBI_fetch_value(
974 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
977 <h3><?php
978 echo sprintf(
979 __('Network traffic since startup: %s'),
980 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
983 </h3>
986 <?php
987 echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'),
988 PMA_timespanFormat($server_status['Uptime']),
989 PMA_localisedDate($start_time)) . "\n";
991 </p>
993 <?php
994 if ($server_master_status || $server_slave_status) {
995 echo '<p class="notice">';
996 if ($server_master_status && $server_slave_status) {
997 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
998 } elseif ($server_master_status) {
999 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
1000 } elseif ($server_slave_status) {
1001 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
1003 echo ' ';
1004 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
1005 echo '</p>';
1008 /* if the server works as master or slave in replication process, display useful information */
1009 if ($server_master_status || $server_slave_status)
1012 <hr class="clearfloat" />
1014 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
1015 <?php
1017 foreach ($replication_types as $type)
1019 if (${"server_{$type}_status"}) {
1020 PMA_replication_print_status_table($type);
1023 unset($types);
1027 <table id="serverstatustraffic" class="data noclick">
1028 <thead>
1029 <tr>
1030 <th colspan="2"><?php echo __('Traffic') . '&nbsp;' . PMA_showHint(__('On a busy server, the byte counters may overrun, so those statistics as reported by the MySQL server may be incorrect.')); ?></th>
1031 <th>&oslash; <?php echo __('per hour'); ?></th>
1032 </tr>
1033 </thead>
1034 <tbody>
1035 <tr class="odd">
1036 <th class="name"><?php echo __('Received'); ?></th>
1037 <td class="value"><?php echo
1038 implode(' ',
1039 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
1040 <td class="value"><?php echo
1041 implode(' ',
1042 PMA_formatByteDown(
1043 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
1044 </tr>
1045 <tr class="even">
1046 <th class="name"><?php echo __('Sent'); ?></th>
1047 <td class="value"><?php echo
1048 implode(' ',
1049 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
1050 <td class="value"><?php echo
1051 implode(' ',
1052 PMA_formatByteDown(
1053 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
1054 </tr>
1055 <tr class="odd">
1056 <th class="name"><?php echo __('Total'); ?></th>
1057 <td class="value"><?php echo
1058 implode(' ',
1059 PMA_formatByteDown(
1060 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
1061 ); ?></td>
1062 <td class="value"><?php echo
1063 implode(' ',
1064 PMA_formatByteDown(
1065 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
1066 * $hour_factor, 3, 1)
1067 ); ?></td>
1068 </tr>
1069 </tbody>
1070 </table>
1072 <table id="serverstatusconnections" class="data noclick">
1073 <thead>
1074 <tr>
1075 <th colspan="2"><?php echo __('Connections'); ?></th>
1076 <th>&oslash; <?php echo __('per hour'); ?></th>
1077 <th>%</th>
1078 </tr>
1079 </thead>
1080 <tbody>
1081 <tr class="odd">
1082 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
1083 <td class="value"><?php echo
1084 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
1085 <td class="value">--- </td>
1086 <td class="value">--- </td>
1087 </tr>
1088 <tr class="even">
1089 <th class="name"><?php echo __('Failed attempts'); ?></th>
1090 <td class="value"><?php echo
1091 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
1092 <td class="value"><?php echo
1093 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
1094 4, 2, true); ?></td>
1095 <td class="value"><?php echo
1096 $server_status['Connections'] > 0
1097 ? PMA_formatNumber(
1098 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
1099 0, 2, true) . '%'
1100 : '--- '; ?></td>
1101 </tr>
1102 <tr class="odd">
1103 <th class="name"><?php echo __('Aborted'); ?></th>
1104 <td class="value"><?php echo
1105 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
1106 <td class="value"><?php echo
1107 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
1108 4, 2, true); ?></td>
1109 <td class="value"><?php echo
1110 $server_status['Connections'] > 0
1111 ? PMA_formatNumber(
1112 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
1113 0, 2, true) . '%'
1114 : '--- '; ?></td>
1115 </tr>
1116 <tr class="even">
1117 <th class="name"><?php echo __('Total'); ?></th>
1118 <td class="value"><?php echo
1119 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
1120 <td class="value"><?php echo
1121 PMA_formatNumber($server_status['Connections'] * $hour_factor,
1122 4, 2); ?></td>
1123 <td class="value"><?php echo
1124 PMA_formatNumber(100, 0, 2); ?>%</td>
1125 </tr>
1126 </tbody>
1127 </table>
1128 <?php
1130 $url_params = array();
1132 $show_full_sql = !empty($_REQUEST['full']);
1133 if ($show_full_sql) {
1134 $url_params['full'] = 1;
1135 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
1136 } else {
1137 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
1139 if (PMA_DRIZZLE) {
1140 $sql_query = "SELECT
1141 p.id AS Id,
1142 p.username AS User,
1143 p.host AS Host,
1144 p.db AS db,
1145 p.command AS Command,
1146 p.time AS Time,
1147 p.state AS State,
1148 " . ($show_full_sql ? 's.query' : 'left(p.info, ' . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info
1149 FROM data_dictionary.PROCESSLIST p
1150 " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
1151 } else {
1152 $sql_query = $show_full_sql
1153 ? 'SHOW FULL PROCESSLIST'
1154 : 'SHOW PROCESSLIST';
1156 $result = PMA_DBI_query($sql_query);
1159 * Displays the page
1162 <table id="tableprocesslist" class="data clearfloat noclick">
1163 <thead>
1164 <tr>
1165 <th><?php echo __('Processes'); ?></th>
1166 <th><?php echo __('ID'); ?></th>
1167 <th><?php echo __('User'); ?></th>
1168 <th><?php echo __('Host'); ?></th>
1169 <th><?php echo __('Database'); ?></th>
1170 <th><?php echo __('Command'); ?></th>
1171 <th><?php echo __('Time'); ?></th>
1172 <th><?php echo __('Status'); ?></th>
1173 <th><?php echo __('SQL query'); ?>
1174 <a href="<?php echo $full_text_link; ?>"
1175 title="<?php echo $show_full_sql ? __('Truncate Shown Queries') : __('Show Full Queries'); ?>">
1176 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . ($show_full_sql ? 'partial' : 'full'); ?>text.png"
1177 alt="<?php echo $show_full_sql ? __('Truncate Shown Queries') : __('Show Full Queries'); ?>" />
1178 </a>
1179 </th>
1180 </tr>
1181 </thead>
1182 <tbody>
1183 <?php
1184 $odd_row = true;
1185 while ($process = PMA_DBI_fetch_assoc($result)) {
1186 $url_params['kill'] = $process['Id'];
1187 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
1189 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
1190 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
1191 <td class="value"><?php echo $process['Id']; ?></td>
1192 <td><?php echo $process['User']; ?></td>
1193 <td><?php echo $process['Host']; ?></td>
1194 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
1195 <td><?php echo $process['Command']; ?></td>
1196 <td class="value"><?php echo $process['Time']; ?></td>
1197 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
1198 <td>
1199 <?php
1200 if (empty($process['Info'])) {
1201 echo '---';
1202 } else {
1203 if (!$show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
1204 echo htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
1205 } else {
1206 echo PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
1210 </td>
1211 </tr>
1212 <?php
1213 $odd_row = ! $odd_row;
1216 </tbody>
1217 </table>
1218 <?php
1221 function printVariablesTable()
1223 global $server_status, $server_variables, $allocationMap, $links;
1225 * Messages are built using the message name
1227 $strShowStatus = array(
1228 'Aborted_clients' => __('The number of connections that were aborted because the client died without closing the connection properly.'),
1229 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
1230 'Binlog_cache_disk_use' => __('The number of transactions that used the temporary binary log cache but that exceeded the value of binlog_cache_size and used a temporary file to store statements from the transaction.'),
1231 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
1232 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
1233 'Created_tmp_disk_tables' => __('The number of temporary tables on disk created automatically by the server while executing statements. If Created_tmp_disk_tables is big, you may want to increase the tmp_table_size value to cause temporary tables to be memory-based instead of disk-based.'),
1234 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
1235 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
1236 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
1237 'Delayed_insert_threads' => __('The number of INSERT DELAYED handler threads in use. Every different table on which one uses INSERT DELAYED gets its own thread.'),
1238 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
1239 'Flush_commands' => __('The number of executed FLUSH statements.'),
1240 'Handler_commit' => __('The number of internal COMMIT statements.'),
1241 'Handler_delete' => __('The number of times a row was deleted from a table.'),
1242 'Handler_discover' => __('The MySQL server can ask the NDB Cluster storage engine if it knows about a table with a given name. This is called discovery. Handler_discover indicates the number of time tables have been discovered.'),
1243 'Handler_read_first' => __('The number of times the first entry was read from an index. If this is high, it suggests that the server is doing a lot of full index scans; for example, SELECT col1 FROM foo, assuming that col1 is indexed.'),
1244 'Handler_read_key' => __('The number of requests to read a row based on a key. If this is high, it is a good indication that your queries and tables are properly indexed.'),
1245 'Handler_read_next' => __('The number of requests to read the next row in key order. This is incremented if you are querying an index column with a range constraint or if you are doing an index scan.'),
1246 'Handler_read_prev' => __('The number of requests to read the previous row in key order. This read method is mainly used to optimize ORDER BY ... DESC.'),
1247 'Handler_read_rnd' => __('The number of requests to read a row based on a fixed position. This is high if you are doing a lot of queries that require sorting of the result. You probably have a lot of queries that require MySQL to scan whole tables or you have joins that don\'t use keys properly.'),
1248 'Handler_read_rnd_next' => __('The number of requests to read the next row in the data file. This is high if you are doing a lot of table scans. Generally this suggests that your tables are not properly indexed or that your queries are not written to take advantage of the indexes you have.'),
1249 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
1250 'Handler_update' => __('The number of requests to update a row in a table.'),
1251 'Handler_write' => __('The number of requests to insert a row in a table.'),
1252 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
1253 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
1254 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
1255 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
1256 'Innodb_buffer_pool_pages_latched' => __('The number of latched pages in InnoDB buffer pool. These are pages currently being read or written or that can\'t be flushed or removed for some other reason.'),
1257 'Innodb_buffer_pool_pages_misc' => __('The number of pages busy because they have been allocated for administrative overhead such as row locks or the adaptive hash index. This value can also be calculated as Innodb_buffer_pool_pages_total - Innodb_buffer_pool_pages_free - Innodb_buffer_pool_pages_data.'),
1258 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
1259 'Innodb_buffer_pool_read_ahead_rnd' => __('The number of "random" read-aheads InnoDB initiated. This happens when a query is to scan a large portion of a table but in random order.'),
1260 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
1261 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
1262 'Innodb_buffer_pool_reads' => __('The number of logical reads that InnoDB could not satisfy from buffer pool and had to do a single-page read.'),
1263 'Innodb_buffer_pool_wait_free' => __('Normally, writes to the InnoDB buffer pool happen in the background. However, if it\'s necessary to read or create a page and no clean pages are available, it\'s necessary to wait for pages to be flushed first. This counter counts instances of these waits. If the buffer pool size was set properly, this value should be small.'),
1264 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
1265 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
1266 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
1267 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
1268 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
1269 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
1270 'Innodb_data_reads' => __('The total number of data reads.'),
1271 'Innodb_data_writes' => __('The total number of data writes.'),
1272 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
1273 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
1274 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
1275 'Innodb_log_waits' => __('The number of waits we had because log buffer was too small and we had to wait for it to be flushed before continuing.'),
1276 'Innodb_log_write_requests' => __('The number of log write requests.'),
1277 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
1278 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
1279 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
1280 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
1281 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
1282 'Innodb_pages_created' => __('The number of pages created.'),
1283 'Innodb_page_size' => __('The compiled-in InnoDB page size (default 16KB). Many values are counted in pages; the page size allows them to be easily converted to bytes.'),
1284 'Innodb_pages_read' => __('The number of pages read.'),
1285 'Innodb_pages_written' => __('The number of pages written.'),
1286 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
1287 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
1288 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
1289 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
1290 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
1291 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
1292 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
1293 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
1294 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
1295 'Key_blocks_not_flushed' => __('The number of key blocks in the key cache that have changed but haven\'t yet been flushed to disk. It used to be known as Not_flushed_key_blocks.'),
1296 'Key_blocks_unused' => __('The number of unused blocks in the key cache. You can use this value to determine how much of the key cache is in use.'),
1297 'Key_blocks_used' => __('The number of used blocks in the key cache. This value is a high-water mark that indicates the maximum number of blocks that have ever been in use at one time.'),
1298 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
1299 'Key_reads' => __('The number of physical reads of a key block from disk. If Key_reads is big, then your key_buffer_size value is probably too small. The cache miss rate can be calculated as Key_reads/Key_read_requests.'),
1300 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
1301 'Key_writes' => __('The number of physical writes of a key block to disk.'),
1302 'Last_query_cost' => __('The total cost of the last compiled query as computed by the query optimizer. Useful for comparing the cost of different query plans for the same query. The default value of 0 means that no query has been compiled yet.'),
1303 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
1304 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
1305 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
1306 'Open_files' => __('The number of files that are open.'),
1307 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
1308 'Open_tables' => __('The number of tables that are open.'),
1309 'Qcache_free_blocks' => __('The number of free memory blocks in query cache. High numbers can indicate fragmentation issues, which may be solved by issuing a FLUSH QUERY CACHE statement.'),
1310 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
1311 'Qcache_hits' => __('The number of cache hits.'),
1312 'Qcache_inserts' => __('The number of queries added to the cache.'),
1313 'Qcache_lowmem_prunes' => __('The number of queries that have been removed from the cache to free up memory for caching new queries. This information can help you tune the query cache size. The query cache uses a least recently used (LRU) strategy to decide which queries to remove from the cache.'),
1314 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
1315 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
1316 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
1317 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
1318 'Select_full_join' => __('The number of joins that do not use indexes. If this value is not 0, you should carefully check the indexes of your tables.'),
1319 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
1320 'Select_range_check' => __('The number of joins without keys that check for key usage after each row. (If this is not 0, you should carefully check the indexes of your tables.)'),
1321 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
1322 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
1323 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
1324 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
1325 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
1326 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
1327 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
1328 'Sort_merge_passes' => __('The number of merge passes the sort algorithm has had to do. If this value is large, you should consider increasing the value of the sort_buffer_size system variable.'),
1329 'Sort_range' => __('The number of sorts that were done with ranges.'),
1330 'Sort_rows' => __('The number of sorted rows.'),
1331 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
1332 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
1333 'Table_locks_waited' => __('The number of times that a table lock could not be acquired immediately and a wait was needed. If this is high, and you have performance problems, you should first optimize your queries, and then either split your table or tables or use replication.'),
1334 'Threads_cached' => __('The number of threads in the thread cache. The cache hit rate can be calculated as Threads_created/Connections. If this value is red you should raise your thread_cache_size.'),
1335 'Threads_connected' => __('The number of currently open connections.'),
1336 'Threads_created' => __('The number of threads created to handle connections. If Threads_created is big, you may want to increase the thread_cache_size value. (Normally this doesn\'t give a notable performance improvement if you have a good thread implementation.)'),
1337 'Threads_running' => __('The number of threads that are not sleeping.')
1341 * define some alerts
1343 // name => max value before alert
1344 $alerts = array(
1345 // lower is better
1346 // variable => max value
1347 'Aborted_clients' => 0,
1348 'Aborted_connects' => 0,
1350 'Binlog_cache_disk_use' => 0,
1352 'Created_tmp_disk_tables' => 0,
1354 'Handler_read_rnd' => 0,
1355 'Handler_read_rnd_next' => 0,
1357 'Innodb_buffer_pool_pages_dirty' => 0,
1358 'Innodb_buffer_pool_reads' => 0,
1359 'Innodb_buffer_pool_wait_free' => 0,
1360 'Innodb_log_waits' => 0,
1361 'Innodb_row_lock_time_avg' => 10, // ms
1362 'Innodb_row_lock_time_max' => 50, // ms
1363 'Innodb_row_lock_waits' => 0,
1365 'Slow_queries' => 0,
1366 'Delayed_errors' => 0,
1367 'Select_full_join' => 0,
1368 'Select_range_check' => 0,
1369 'Sort_merge_passes' => 0,
1370 'Opened_tables' => 0,
1371 'Table_locks_waited' => 0,
1372 'Qcache_lowmem_prunes' => 0,
1374 'Qcache_free_blocks' => isset($server_status['Qcache_total_blocks']) ? $server_status['Qcache_total_blocks'] / 5 : 0,
1375 'Slow_launch_threads' => 0,
1377 // depends on Key_read_requests
1378 // normaly lower then 1:0.01
1379 'Key_reads' => isset($server_status['Key_read_requests']) ? (0.01 * $server_status['Key_read_requests']) : 0,
1380 // depends on Key_write_requests
1381 // normaly nearly 1:1
1382 'Key_writes' => isset($server_status['Key_write_requests']) ? (0.9 * $server_status['Key_write_requests']) : 0,
1384 'Key_buffer_fraction' => 0.5,
1386 // alert if more than 95% of thread cache is in use
1387 'Threads_cached' => isset($server_variables['thread_cache_size']) ? 0.95 * $server_variables['thread_cache_size'] : 0
1389 // higher is better
1390 // variable => min value
1391 //'Handler read key' => '> ',
1395 <table class="data sortable noclick" id="serverstatusvariables">
1396 <col class="namecol" />
1397 <col class="valuecol" />
1398 <col class="descrcol" />
1399 <thead>
1400 <tr>
1401 <th><?php echo __('Variable'); ?></th>
1402 <th><?php echo __('Value'); ?></th>
1403 <th><?php echo __('Description'); ?></th>
1404 </tr>
1405 </thead>
1406 <tbody>
1407 <?php
1409 $odd_row = false;
1410 foreach ($server_status as $name => $value) {
1411 $odd_row = !$odd_row;
1413 <tr class="<?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_' . $allocationMap[$name]:''; ?>">
1414 <th class="name"><?php echo htmlspecialchars(str_replace('_', ' ', $name)) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1415 </th>
1416 <td class="value"><span class="formatted"><?php
1417 if (isset($alerts[$name])) {
1418 if ($value > $alerts[$name]) {
1419 echo '<span class="attention">';
1420 } else {
1421 echo '<span class="allfine">';
1424 if ('%' === substr($name, -1, 1)) {
1425 echo htmlspecialchars(PMA_formatNumber($value, 0, 2)) . ' %';
1426 } elseif (strpos($name, 'Uptime')!==FALSE) {
1427 echo htmlspecialchars(PMA_timespanFormat($value));
1428 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1429 echo htmlspecialchars(PMA_formatNumber($value, 3, 1));
1430 } elseif (is_numeric($value) && $value == (int) $value) {
1431 echo htmlspecialchars(PMA_formatNumber($value, 3, 0));
1432 } elseif (is_numeric($value)) {
1433 echo htmlspecialchars(PMA_formatNumber($value, 3, 1));
1434 } else {
1435 echo htmlspecialchars($value);
1437 if (isset($alerts[$name])) {
1438 echo '</span>';
1440 ?></span><span style="display:none;" class="original"><?php echo $value; ?></span>
1441 </td>
1442 <td class="descr">
1443 <?php
1444 if (isset($strShowStatus[$name ])) {
1445 echo $strShowStatus[$name];
1448 if (isset($links[$name])) {
1449 foreach ($links[$name] as $link_name => $link_url) {
1450 if ('doc' == $link_name) {
1451 echo PMA_showMySQLDocu($link_url, $link_url);
1452 } else {
1453 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1454 "\n";
1457 unset($link_url, $link_name);
1460 </td>
1461 </tr>
1462 <?php
1465 </tbody>
1466 </table>
1467 <?php
1470 function printMonitor()
1472 global $server_status, $server_db_isLocal;
1474 <div class="tabLinks" style="display:none;">
1475 <a href="#pauseCharts">
1476 <img src="themes/dot.gif" class="icon ic_play" alt="" />
1477 <?php echo __('Start Monitor'); ?>
1478 </a>
1479 <a href="#settingsPopup" rel="popupLink" style="display:none;">
1480 <img src="themes/dot.gif" class="icon ic_s_cog" alt="" />
1481 <?php echo __('Settings'); ?>
1482 </a>
1483 <?php if (!PMA_DRIZZLE) { ?>
1484 <a href="#monitorInstructionsDialog">
1485 <img src="themes/dot.gif" class="icon ic_b_help" alt="" />
1486 <?php echo __('Instructions/Setup'); ?>
1487 </a>
1488 <?php } ?>
1489 <a href="#endChartEditMode" style="display:none;">
1490 <img src="themes/dot.gif" class="icon ic_s_okay" alt="" />
1491 <?php echo __('Done rearranging/editing charts'); ?>
1492 </a>
1493 </div>
1495 <div class="popupContent settingsPopup">
1496 <a href="#addNewChart">
1497 <img src="themes/dot.gif" class="icon ic_b_chart" alt="" />
1498 <?php echo __('Add chart'); ?>
1499 </a>
1500 <a href="#rearrangeCharts"><img class="icon ic_b_tblops" src="themes/dot.gif" width="16" height="16" alt="" /><?php echo __('Rearrange/edit charts'); ?></a>
1501 <div class="clearfloat paddingtop"></div>
1502 <div class="floatleft">
1503 <?php
1504 echo __('Refresh rate') . '<br />';
1505 refreshList('gridChartRefresh', 5, Array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200));
1506 ?><br />
1507 </div>
1508 <div class="floatleft">
1509 <?php echo __('Chart columns'); ?> <br />
1510 <select name="chartColumns">
1511 <option>1</option>
1512 <option>2</option>
1513 <option>3</option>
1514 <option>4</option>
1515 <option>5</option>
1516 <option>6</option>
1517 <option>7</option>
1518 <option>8</option>
1519 <option>9</option>
1520 <option>10</option>
1521 </select>
1522 </div>
1524 <div class="clearfloat paddingtop">
1525 <b><?php echo __('Chart arrangement'); ?></b> <?php echo PMA_showHint(__('The arrangement of the charts is stored to the browsers local storage. You may want to export it if you have a complicated set up.')); ?><br/>
1526 <a href="#importMonitorConfig"><?php echo __('Import'); ?></a>&nbsp;&nbsp;<a href="#exportMonitorConfig"><?php echo __('Export'); ?></a>&nbsp;&nbsp;<a href="#clearMonitorConfig"><?php echo __('Reset to default'); ?></a>
1527 </div>
1528 </div>
1530 <div id="monitorInstructionsDialog" title="<?php echo __('Monitor Instructions'); ?>" style="display:none;">
1531 <?php echo __('The phpMyAdmin Monitor can assist you in optimizing the server configuration and track down time intensive queries. For the latter you will need to set log_output to \'TABLE\' and have either the slow_query_log or general_log enabled. Note however, that the general_log produces a lot of data and increases server load by up to 15%'); ?>
1532 <?php if(PMA_MYSQL_INT_VERSION < 50106) { ?>
1534 <img class="icon ic_s_attention" src="themes/dot.gif" alt="" />
1535 <?php
1536 echo __('Unfortunately your Database server does not support logging to table, which is a requirement for analyzing the database logs with phpMyAdmin. Logging to table is supported by MySQL 5.1.6 and onwards. You may still use the server charting features however.');
1538 </p>
1539 <?php
1540 } else {
1542 <p></p>
1543 <img class="ajaxIcon" src="<?php echo $GLOBALS['pmaThemeImage']; ?>ajax_clock_small.gif" alt="Loading" />
1544 <div class="ajaxContent"></div>
1545 <div class="monitorUse" style="display:none;">
1546 <p></p>
1547 <?php
1548 echo '<strong>';
1549 echo __('Using the monitor:');
1550 echo '</strong><p>';
1551 echo __('Ok, you are good to go! Once you click \'Start monitor\' your browser will refresh all displayed charts in a regular interval. You may add charts and change the refresh rate under \'Settings\', or remove any chart using the cog icon on each respective chart.');
1552 echo '</p><p>';
1553 echo __('To display queries from the logs, select the relevant time span on any chart by holding down the left mouse button and panning over the chart. Once confirmed, this will load a table of grouped queries, there you may click on any occuring SELECT statements to further analyze them.');
1554 echo '</p>';
1557 <img class="icon ic_s_attention" src="themes/dot.gif" alt="" />
1558 <?php
1559 echo '<strong>';
1560 echo __('Please note:');
1561 echo '</strong><br />';
1562 echo __('Enabling the general_log may increase the server load by 5-15%. Also be aware that generating statistics from the logs is a load intensive task, so it is advisable to select only a small time span and to disable the general_log and empty its table once monitoring is not required any more.');
1564 </p>
1565 </div>
1566 <?php } ?>
1567 </div>
1569 <div id="addChartDialog" title="Add chart" style="display:none;">
1570 <div id="tabGridVariables">
1571 <p><input type="text" name="chartTitle" value="<?php echo __('Chart Title'); ?>" /></p>
1573 <input type="radio" name="chartType" value="preset" id="chartPreset" />
1574 <label for="chartPreset"><?php echo __('Preset chart'); ?></label>
1575 <select name="presetCharts"></select><br/>
1577 <input type="radio" name="chartType" value="variable" id="chartStatusVar" checked="checked" />
1578 <label for="chartStatusVar"><?php echo __('Status variable(s)'); ?></label><br/>
1579 <div id="chartVariableSettings">
1580 <label for="chartSeries"><?php echo __('Select series:'); ?></label><br />
1581 <select id="chartSeries" name="varChartList" size="1">
1582 <option><?php echo __('Commonly monitored'); ?></option>
1583 <option>Processes</option>
1584 <option>Questions</option>
1585 <option>Connections</option>
1586 <option>Bytes_sent</option>
1587 <option>Bytes_received</option>
1588 <option>Threads_connected</option>
1589 <option>Created_tmp_disk_tables</option>
1590 <option>Handler_read_first</option>
1591 <option>Innodb_buffer_pool_wait_free</option>
1592 <option>Key_reads</option>
1593 <option>Open_tables</option>
1594 <option>Select_full_join</option>
1595 <option>Slow_queries</option>
1596 </select><br />
1597 <label for="variableInput"><?php echo __('or type variable name:'); ?> </label>
1598 <input type="text" name="variableInput" id="variableInput" />
1599 <p></p>
1600 <input type="checkbox" name="differentialValue" id="differentialValue" value="differential" checked="checked" />
1601 <label for="differentialValue"><?php echo __('Display as differential value'); ?></label><br />
1602 <input type="checkbox" id="useDivisor" name="useDivisor" value="1" />
1603 <label for="useDivisor"><?php echo __('Apply a divisor'); ?></label>
1604 <span class="divisorInput" style="display:none;">
1605 <input type="text" name="valueDivisor" size="4" value="1" />
1606 (<a href="#kibDivisor"><?php echo __('KiB'); ?></a>, <a href="#mibDivisor"><?php echo __('MiB'); ?></a>)
1607 </span><br />
1609 <input type="checkbox" id="useUnit" name="useUnit" value="1" />
1610 <label for="useUnit"><?php echo __('Append unit to data values'); ?></label>
1612 <span class="unitInput" style="display:none;">
1613 <input type="text" name="valueUnit" size="4" value="" />
1614 </span>
1616 <a href="#submitAddSeries"><b><?php echo __('Add this series'); ?></b></a>
1617 <span id="clearSeriesLink" style="display:none;">
1618 | <a href="#submitClearSeries"><?php echo __('Clear series'); ?></a>
1619 </span>
1620 </p>
1621 <?php echo __('Series in Chart:'); ?><br/>
1622 <span id="seriesPreview">
1623 <i><?php echo __('None'); ?></i>
1624 </span>
1625 </div>
1626 </div>
1627 </div>
1629 <!-- For generic use -->
1630 <div id="emptyDialog" title="Dialog" style="display:none;">
1631 </div>
1633 <?php if (!PMA_DRIZZLE) { ?>
1634 <div id="logAnalyseDialog" title="<?php echo __('Log statistics'); ?>" style="display:none;">
1635 <p> <?php echo __('Selected time range:'); ?>
1636 <input type="text" name="dateStart" class="datetimefield" value="" /> -
1637 <input type="text" name="dateEnd" class="datetimefield" value="" /></p>
1638 <input type="checkbox" id="limitTypes" value="1" checked="checked" />
1639 <label for="limitTypes">
1640 <?php echo __('Only retrieve SELECT,INSERT,UPDATE and DELETE Statements'); ?>
1641 </label>
1642 <br/>
1643 <input type="checkbox" id="removeVariables" value="1" checked="checked" />
1644 <label for="removeVariables">
1645 <?php echo __('Remove variable data in INSERT statements for better grouping'); ?>
1646 </label>
1648 <?php
1649 echo '<p>';
1650 echo __('Choose from which log you want the statistics to be generated from.');
1651 echo '</p><p>';
1652 echo __('Results are grouped by query text.');
1653 echo '</p>';
1655 </div>
1657 <div id="queryAnalyzerDialog" title="<?php echo __('Query analyzer'); ?>" style="display:none;">
1658 <textarea id="sqlquery"> </textarea>
1659 <p></p>
1660 <div class="placeHolder"></div>
1661 </div>
1662 <?php } ?>
1664 <table border="0" class="clearfloat" id="chartGrid">
1666 </table>
1667 <div id="logTable">
1668 <br/>
1669 </div>
1671 <script type="text/javascript">
1672 variableNames = [ <?php
1673 $i=0;
1674 foreach ($server_status as $name=>$value) {
1675 if (is_numeric($value)) {
1676 if ($i++ > 0) echo ", ";
1677 echo "'" . $name . "'";
1680 ?> ];
1681 </script>
1682 <?php
1685 /* Builds a <select> list for refresh rates */
1686 function refreshList($name, $defaultRate=5, $refreshRates=Array(1, 2, 5, 10, 20, 40, 60, 120, 300, 600))
1689 <select name="<?php echo $name; ?>" id="id_<?php echo $name; ?>">
1690 <?php
1691 foreach ($refreshRates as $rate) {
1692 $selected = ($rate == $defaultRate)?' selected="selected"':'';
1694 if ($rate<60)
1695 echo '<option value="' . $rate . '"' . $selected . '>' . sprintf(_ngettext('%d second', '%d seconds', $rate), $rate) . '</option>';
1696 else
1697 echo '<option value="' . $rate . '"' . $selected . '>' . sprintf(_ngettext('%d minute', '%d minutes', $rate/60), $rate/60) . '</option>';
1700 </select>
1701 <?php
1705 * cleanup of some deprecated values
1707 * @param array &$server_status
1709 function cleanDeprecated(&$server_status)
1711 $deprecated = array(
1712 'Com_prepare_sql' => 'Com_stmt_prepare',
1713 'Com_execute_sql' => 'Com_stmt_execute',
1714 'Com_dealloc_sql' => 'Com_stmt_close',
1717 foreach ($deprecated as $old => $new) {
1718 if (isset($server_status[$old]) && isset($server_status[$new])) {
1719 unset($server_status[$old]);
1725 * Sends the footer
1727 require './libraries/footer.inc.php';