Merge remote-tracking branch 'origin/master' into drizzle
[phpmyadmin.git] / server_status.php
blob387ce971000c84824e0f45f892f5b8f63b07bb11
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 case 'proc':
35 $c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1);
36 $result = PMA_DBI_query('SHOW PROCESSLIST');
37 $num_procs = PMA_DBI_num_rows($result);
39 $ret = array(
40 'x' => microtime(true)*1000,
41 'y_proc' => $num_procs,
42 'y_conn' => $c['Connections']
45 exit(json_encode($ret));
47 case 'queries':
48 if (PMA_DRIZZLE) {
49 $sql = "SELECT concat('Com_', variable_name), variable_value
50 FROM data_dictionary.GLOBAL_STATEMENTS
51 WHERE variable_value > 0
52 UNION
53 SELECT variable_name, variable_value
54 FROM data_dictionary.GLOBAL_STATUS
55 WHERE variable_name = 'Questions'";
56 $queries = PMA_DBI_fetch_result($sql, 0, 1);
57 } else {
58 $queries = PMA_DBI_fetch_result(
59 "SHOW GLOBAL STATUS
60 WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions')
61 AND Value > 0'", 0, 1);
63 cleanDeprecated($queries);
64 // admin commands are not queries
65 unset($queries['Com_admin_commands']);
66 $questions = $queries['Questions'];
67 unset($queries['Questions']);
69 //$sum=array_sum($queries);
70 $ret = array(
71 'x' => microtime(true)*1000,
72 'y' => $questions,
73 'pointInfo' => $queries
76 exit(json_encode($ret));
78 case 'traffic':
79 $traffic = PMA_DBI_fetch_result(
80 "SHOW GLOBAL STATUS
81 WHERE Variable_name = 'Bytes_received'
82 OR Variable_name = 'Bytes_sent'", 0, 1);
84 $ret = array(
85 'x' => microtime(true)*1000,
86 'y_sent' => $traffic['Bytes_sent'],
87 'y_received' => $traffic['Bytes_received']
90 exit(json_encode($ret));
92 case 'chartgrid':
93 $ret = json_decode($_REQUEST['requiredData'], true);
94 $statusVars = array();
95 $sysinfo = $cpuload = $memory = 0;
97 foreach ($ret as $chart_id => $chartNodes) {
98 foreach ($chartNodes as $node_id => $node) {
99 switch ($node['dataType']) {
100 case 'statusvar':
101 // Some white list filtering
102 if (!preg_match('/[^a-zA-Z_]+/',$node['dataPoint']))
103 $statusVars[] = $node['dataPoint'];
104 break;
106 case 'proc':
107 $result = PMA_DBI_query('SHOW PROCESSLIST');
108 $ret[$chart_id][$node_id]['y'] = PMA_DBI_num_rows($result);
109 break;
111 case 'cpu':
112 if (!$sysinfo) {
113 require_once('libraries/sysinfo.lib.php');
114 $sysinfo = getSysInfo();
116 if (!$cpuload)
117 $cpuload = $sysinfo->loadavg();
119 if (PHP_OS == 'Linux') {
120 $ret[$chart_id][$node_id]['idle'] = $cpuload['idle'];
121 $ret[$chart_id][$node_id]['busy'] = $cpuload['busy'];
122 } else
123 $ret[$chart_id][$node_id]['y'] = $cpuload['loadavg'];
125 break;
127 case 'memory':
128 if (!$sysinfo) {
129 require_once('libraries/sysinfo.lib.php');
130 $sysinfo = getSysInfo();
132 if (!$memory)
133 $memory = $sysinfo->memory();
135 $ret[$chart_id][$node_id]['y'] = $memory[$node['dataPoint']];
136 break;
141 $vars = PMA_DBI_fetch_result(
142 "SHOW GLOBAL STATUS
143 WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1);
145 foreach ($ret as $chart_id => $chartNodes) {
146 foreach ($chartNodes as $node_id => $node) {
147 if ($node['dataType'] == 'statusvar')
148 $ret[$chart_id][$node_id]['y'] = $vars[$node['dataPoint']];
152 $ret['x'] = microtime(true)*1000;
154 exit(json_encode($ret));
158 if (isset($_REQUEST['log_data'])) {
159 if(PMA_MYSQL_INT_VERSION < 50106) exit('""');
161 $start = intval($_REQUEST['time_start']);
162 $end = intval($_REQUEST['time_end']);
164 if ($_REQUEST['type'] == 'slow') {
165 $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, '.
166 'SUM(rows_sent) AS rows_sent, SUM(rows_examined) AS rows_examined, db, sql_text, COUNT(sql_text) AS \'#\' '.
167 'FROM `mysql`.`slow_log` WHERE start_time > FROM_UNIXTIME('.$start.') '.
168 'AND start_time < FROM_UNIXTIME('.$end.') GROUP BY sql_text';
170 $result = PMA_DBI_try_query($q);
172 $return = array('rows' => array(), 'sum' => array());
173 $type = '';
175 while ($row = PMA_DBI_fetch_assoc($result)) {
176 $type = strtolower(substr($row['sql_text'],0,strpos($row['sql_text'],' ')));
178 switch($type) {
179 case 'insert':
180 case 'update':
181 // Cut off big inserts and updates, but append byte count therefor
182 if(strlen($row['sql_text']) > 220)
183 $row['sql_text'] = substr($row['sql_text'],0,200) . '... [' .
184 implode(' ',PMA_formatByteDown(strlen($row['sql_text']), 2, 2)).']';
186 break;
187 default:
188 break;
191 if(!isset($return['sum'][$type])) $return['sum'][$type] = 0;
192 $return['sum'][$type] += $row['#'];
193 $return['rows'][] = $row;
196 $return['sum']['TOTAL'] = array_sum($return['sum']);
197 $return['numRows'] = count($return['rows']);
199 PMA_DBI_free_result($result);
201 exit(json_encode($return));
204 if($_REQUEST['type'] == 'general') {
205 $limitTypes = (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes'])
206 ? 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ' : '';
208 $q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, server_id, argument, count(argument) as \'#\' '.
209 'FROM `mysql`.`general_log` WHERE command_type=\'Query\' '.
210 'AND event_time > FROM_UNIXTIME('.$start.') AND event_time < FROM_UNIXTIME('.$end.') '.
211 $limitTypes . 'GROUP by argument'; // HAVING count > 1';
213 $result = PMA_DBI_try_query($q);
215 $return = array('rows' => array(), 'sum' => array());
216 $type = '';
217 $insertTables = array();
218 $insertTablesFirst = -1;
219 $i = 0;
220 $removeVars = isset($_REQUEST['removeVariables']) && $_REQUEST['removeVariables'];
222 while ($row = PMA_DBI_fetch_assoc($result)) {
223 preg_match('/^(\w+)\s/',$row['argument'],$match);
224 $type = strtolower($match[1]);
226 if(!isset($return['sum'][$type])) $return['sum'][$type] = 0;
227 $return['sum'][$type] += $row['#'];
229 switch($type) {
230 case 'insert':
231 // Group inserts if selected
232 if($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i',$row['argument'],$matches)) {
233 $insertTables[$matches[2]]++;
234 if ($insertTables[$matches[2]] > 1) {
235 $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
237 // Add a ... to the end of this query to indicate that there's been other queries
238 if($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.')
239 $return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
241 // Group this value, thus do not add to the result list
242 continue 2;
243 } else {
244 $insertTablesFirst = $i;
245 $insertTables[$matches[2]] += $row['#'] - 1;
248 // No break here
250 case 'update':
251 // Cut off big inserts and updates, but append byte count therefor
252 if(strlen($row['argument']) > 220)
253 $row['argument'] = substr($row['argument'],0,200) . '... [' .
254 implode(' ',PMA_formatByteDown(strlen($row['argument'])), 2, 2).']';
256 break;
258 default: break;
261 $return['rows'][] = $row;
262 $i++;
265 $return['sum']['TOTAL'] = array_sum($return['sum']);
266 $return['numRows'] = count($return['rows']);
268 PMA_DBI_free_result($result);
270 exit(json_encode($return));
274 if (isset($_REQUEST['logging_vars'])) {
275 if(isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) {
276 $value = PMA_sqlAddslashes($_REQUEST['varValue']);
277 if(!is_numeric($value)) $value="'".$value."'";
279 if(! preg_match("/[^a-zA-Z0-9_]+/",$_REQUEST['varName']))
280 PMA_DBI_query('SET GLOBAL '.$_REQUEST['varName'].' = '.$value);
284 $loggingVars = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES WHERE Variable_name IN ("general_log","slow_query_log","long_query_time","log_output")', 0, 1);
285 exit(json_encode($loggingVars));
288 if(isset($_REQUEST['query_analyzer'])) {
289 $return = array();
291 if(strlen($_REQUEST['database']))
292 PMA_DBI_select_db($_REQUEST['database']);
294 if ($profiling = PMA_profilingSupported())
295 PMA_DBI_query('SET PROFILING=1;');
297 // Do not cache query
298 $query = preg_replace('/^(\s*SELECT)/i','\\1 SQL_NO_CACHE',$_REQUEST['query']);
300 $result = PMA_DBI_try_query($query);
301 $return['affectedRows'] = $GLOBALS['cached_affected_rows'];
303 $result = PMA_DBI_try_query('EXPLAIN ' . $query);
304 while ($row = PMA_DBI_fetch_assoc($result)) {
305 $return['explain'][] = $row;
308 // In case an error happened
309 $return['error'] = PMA_DBI_getError();
311 PMA_DBI_free_result($result);
313 if($profiling) {
314 $return['profiling'] = array();
315 $result = PMA_DBI_try_query('SELECT seq,state,duration FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID=1 ORDER BY seq');
316 while ($row = PMA_DBI_fetch_assoc($result)) {
317 $return['profiling'][]= $row;
319 PMA_DBI_free_result($result);
322 exit(json_encode($return));
325 if(isset($_REQUEST['advisor'])) {
326 include('libraries/advisor.lib.php');
327 $advisor = new Advisor();
328 exit(json_encode($advisor->run()));
334 * Replication library
336 if (PMA_DRIZZLE) {
337 $server_master_status = false;
338 $server_slave_status = false;
339 } else {
340 require './libraries/replication.inc.php';
341 require_once './libraries/replication_gui.lib.php';
345 * JS Includes
348 $GLOBALS['js_include'][] = 'server_status.js';
349 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
350 $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
351 $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
352 $GLOBALS['js_include'][] = 'jquery/jquery.json-2.2.js';
353 $GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
354 $GLOBALS['js_include'][] = 'jquery/jquery.sortableTable.js';
355 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
356 // Charting
357 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
358 /* Files required for chart exporting */
359 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
360 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
361 $GLOBALS['js_include'][] = 'canvg/canvg.js';
362 $GLOBALS['js_include'][] = 'canvg/rgbcolor.js';
363 $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js';
364 $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js';
367 * flush status variables if requested
369 if (isset($_REQUEST['flush'])) {
370 $_flush_commands = array(
371 'STATUS',
372 'TABLES',
373 'QUERY CACHE',
376 if (in_array($_REQUEST['flush'], $_flush_commands)) {
377 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
379 unset($_flush_commands);
383 * Kills a selected process
385 if (!empty($_REQUEST['kill'])) {
386 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
387 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
388 } else {
389 $message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
391 $message->addParam($_REQUEST['kill']);
392 //$message->display();
398 * get status from server
400 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
401 if (PMA_DRIZZLE) {
402 // Drizzle doesn't put query statistics into variables, add it
403 $sql = "SELECT concat('Com_', variable_name), variable_value
404 FROM data_dictionary.GLOBAL_STATEMENTS";
405 $statements = PMA_DBI_fetch_result($sql, 0, 1);
406 $server_status = array_merge($server_status, $statements);
410 * for some calculations we require also some server settings
412 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
415 * cleanup of some deprecated values
417 cleanDeprecated($server_status);
420 * calculate some values
422 // Key_buffer_fraction
423 if (isset($server_status['Key_blocks_unused'])
424 && isset($server_variables['key_cache_block_size'])
425 && isset($server_variables['key_buffer_size'])) {
426 $server_status['Key_buffer_fraction_%'] =
428 - $server_status['Key_blocks_unused']
429 * $server_variables['key_cache_block_size']
430 / $server_variables['key_buffer_size']
431 * 100;
432 } elseif (isset($server_status['Key_blocks_used'])
433 && isset($server_variables['key_buffer_size'])) {
434 $server_status['Key_buffer_fraction_%'] =
435 $server_status['Key_blocks_used']
436 * 1024
437 / $server_variables['key_buffer_size'];
440 // Ratio for key read/write
441 if (isset($server_status['Key_writes'])
442 && isset($server_status['Key_write_requests'])
443 && $server_status['Key_write_requests'] > 0) {
444 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
447 if (isset($server_status['Key_reads'])
448 && isset($server_status['Key_read_requests'])
449 && $server_status['Key_read_requests'] > 0) {
450 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
453 // Threads_cache_hitrate
454 if (isset($server_status['Threads_created'])
455 && isset($server_status['Connections'])
456 && $server_status['Connections'] > 0) {
458 $server_status['Threads_cache_hitrate_%'] =
459 100 - $server_status['Threads_created'] / $server_status['Connections'] * 100;
463 * split variables in sections
465 $allocations = array(
466 // variable name => section
467 // variable names match when they begin with the given string
469 'Com_' => 'com',
470 'Innodb_' => 'innodb',
471 'Ndb_' => 'ndb',
472 'Handler_' => 'handler',
473 'Qcache_' => 'qcache',
474 'Threads_' => 'threads',
475 'Slow_launch_threads' => 'threads',
477 'Binlog_cache_' => 'binlog_cache',
478 'Created_tmp_' => 'created_tmp',
479 'Key_' => 'key',
481 'Delayed_' => 'delayed',
482 'Not_flushed_delayed_rows' => 'delayed',
484 'Flush_commands' => 'query',
485 'Last_query_cost' => 'query',
486 'Slow_queries' => 'query',
487 'Queries' => 'query',
488 'Prepared_stmt_count' => 'query',
490 'Select_' => 'select',
491 'Sort_' => 'sort',
493 'Open_tables' => 'table',
494 'Opened_tables' => 'table',
495 'Open_table_definitions' => 'table',
496 'Opened_table_definitions' => 'table',
497 'Table_locks_' => 'table',
499 'Rpl_status' => 'repl',
500 'Slave_' => 'repl',
502 'Tc_' => 'tc',
504 'Ssl_' => 'ssl',
506 'Open_files' => 'files',
507 'Open_streams' => 'files',
508 'Opened_files' => 'files',
511 $sections = array(
512 // section => section name (description)
513 'com' => 'Com',
514 'query' => __('SQL query'),
515 'innodb' => 'InnoDB',
516 'ndb' => 'NDB',
517 'handler' => __('Handler'),
518 'qcache' => __('Query cache'),
519 'threads' => __('Threads'),
520 'binlog_cache' => __('Binary log'),
521 'created_tmp' => __('Temporary data'),
522 'delayed' => __('Delayed inserts'),
523 'key' => __('Key cache'),
524 'select' => __('Joins'),
525 'repl' => __('Replication'),
526 'sort' => __('Sorting'),
527 'table' => __('Tables'),
528 'tc' => __('Transaction coordinator'),
529 'files' => __('Files'),
530 'ssl' => 'SSL',
531 'other' => __('Other')
535 * define some needfull links/commands
537 // variable or section name => (name => url)
538 $links = array();
540 $links['table'][__('Flush (close) all tables')]
541 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
542 $links['table'][__('Show open tables')]
543 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
544 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
546 if ($server_master_status) {
547 $links['repl'][__('Show slave hosts')]
548 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
549 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
550 $links['repl'][__('Show master status')] = '#replication_master';
552 if ($server_slave_status) {
553 $links['repl'][__('Show slave status')] = '#replication_slave';
556 $links['repl']['doc'] = 'replication';
558 $links['qcache'][__('Flush query cache')]
559 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
560 PMA_generate_common_url();
561 $links['qcache']['doc'] = 'query_cache';
563 //$links['threads'][__('Show processes')]
564 // = 'server_processlist.php?' . PMA_generate_common_url();
565 $links['threads']['doc'] = 'mysql_threads';
567 $links['key']['doc'] = 'myisam_key_cache';
569 $links['binlog_cache']['doc'] = 'binary_log';
571 $links['Slow_queries']['doc'] = 'slow_query_log';
573 $links['innodb'][__('Variables')]
574 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
575 $links['innodb'][__('InnoDB Status')]
576 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
577 PMA_generate_common_url();
578 $links['innodb']['doc'] = 'innodb';
581 // Variable to contain all com_ variables (query statistics)
582 $used_queries = array();
584 // Variable to map variable names to their respective section name (used for js category filtering)
585 $allocationMap = array();
587 // Variable to mark used sections
588 $categoryUsed = array();
590 // sort vars into arrays
591 foreach ($server_status as $name => $value) {
592 $section_found = false;
593 foreach ($allocations as $filter => $section) {
594 if (strpos($name, $filter) !== false) {
595 $allocationMap[$name] = $section;
596 $categoryUsed[$section] = true;
597 $section_found = true;
598 if ($section == 'com' && $value > 0) $used_queries[$name] = $value;
599 break; // Only exits inner loop
602 if (!$section_found) {
603 $allocationMap[$name] = 'other';
604 $categoryUsed['other'] = true;
608 if(PMA_DRIZZLE) {
609 $used_queries = PMA_DBI_fetch_result('SELECT * FROM data_dictionary.global_statements', 0, 1);
610 unset($used_queries['admin_commands']);
611 } else {
612 // admin commands are not queries (e.g. they include COM_PING, which is excluded from $server_status['Questions'])
613 unset($used_queries['Com_admin_commands']);
616 /* Ajax request refresh */
617 if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
618 switch($_REQUEST['show']) {
619 case 'query_statistics':
620 printQueryStatistics();
621 exit();
622 case 'server_traffic':
623 printServerTraffic();
624 exit();
625 case 'variables_table':
626 // Prints the variables table
627 printVariablesTable();
628 exit();
630 default:
631 break;
636 * start output
640 * Does the common work
642 require './libraries/server_common.inc.php';
646 * Displays the links
648 require './libraries/server_links.inc.php';
650 $server = 1;
651 if (isset($_REQUEST['server']) && intval($_REQUEST['server'])) $server = intval($_REQUEST['server']);
653 $server_db_isLocal = strtolower($cfg['Servers'][$server]['host']) == 'localhost'
654 || $cfg['Servers'][$server]['host'] == '127.0.0.1'
655 || $cfg['Servers'][$server]['host'] == '::1';
658 <script type="text/javascript">
659 pma_token = '<?php echo $_SESSION[' PMA_token ']; ?>';
660 url_query = '<?php echo str_replace('&amp;','&',$url_query);?>';
661 server_time_diff = new Date().getTime() - <?php echo microtime(true)*1000; ?>;
662 server_os = '<?php echo PHP_OS; ?>';
663 is_superuser = <?php echo PMA_isSuperuser()?'true':'false'; ?>;
664 server_db_isLocal = <?php echo ($server_db_isLocal)?'true':'false'; ?>;
665 profiling_docu = '<?php echo PMA_showMySQLDocu('general-thread-states','general-thread-states'); ?>';
666 explain_docu = '<?php echo PMA_showMySQLDocu('explain-output', 'explain-output'); ?>';
667 </script>
668 <div id="serverstatus">
669 <h2><?php
671 * Displays the sub-page heading
673 if ($GLOBALS['cfg']['MainPageIconic']) {
674 echo '<img class="icon ic_s_status" src="themes/dot.gif" width="16" height="16" alt="" />';
677 echo __('Runtime Information');
679 ?></h2>
680 <div id="serverStatusTabs">
681 <ul>
682 <li><a href="#statustabs_traffic"><?php echo __('Server'); ?></a></li>
683 <li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
684 <li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
685 <li><a href="#statustabs_charting"><?php echo __('Monitor'); ?></a></li>
686 <li><a href="#statustabs_advisor"><?php echo __('Advisor'); ?></a></li>
687 </ul>
689 <div id="statustabs_traffic">
690 <div class="buttonlinks">
691 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&amp;' . PMA_generate_common_url(); ?>" >
692 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
693 <?php echo __('Refresh'); ?>
694 </a>
695 <span class="refreshList" style="display:none;">
696 <label for="trafficChartRefresh"><?php echo __('Refresh rate: '); ?></label>
697 <?php refreshList('trafficChartRefresh'); ?>
698 </span>
700 <a class="tabChart livetrafficLink" href="#">
701 <?php echo __('Live traffic chart'); ?>
702 </a>
703 <a class="tabChart liveconnectionsLink" href="#">
704 <?php echo __('Live conn./process chart'); ?>
705 </a>
706 </div>
707 <div class="tabInnerContent">
708 <?php printServerTraffic(); ?>
709 </div>
710 </div>
711 <div id="statustabs_queries">
712 <div class="buttonlinks">
713 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
714 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
715 <?php echo __('Refresh'); ?>
716 </a>
717 <span class="refreshList" style="display:none;">
718 <label for="queryChartRefresh"><?php echo __('Refresh rate: '); ?></label>
719 <?php refreshList('queryChartRefresh'); ?>
720 </span>
721 <a class="tabChart livequeriesLink" href="#">
722 <?php echo __('Live query chart'); ?>
723 </a>
724 </div>
725 <div class="tabInnerContent">
726 <?php printQueryStatistics(); ?>
727 </div>
728 </div>
729 <div id="statustabs_allvars">
730 <fieldset id="tableFilter">
731 <div class="buttonlinks">
732 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
733 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
734 <?php echo __('Refresh'); ?>
735 </a>
736 </div>
737 <legend>Filters</legend>
738 <div class="formelement">
739 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
740 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
741 </div>
742 <div class="formelement">
743 <input type="checkbox" name="filterAlert" id="filterAlert">
744 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
745 </div>
746 <div class="formelement">
747 <select id="filterCategory" name="filterCategory">
748 <option value=''><?php echo __('Filter by category...'); ?></option>
749 <?php
750 foreach ($sections as $section_id => $section_name) {
751 if (isset($categoryUsed[$section_id])) {
753 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
754 <?php
758 </select>
759 </div>
760 <div class="formelement">
761 <input type="checkbox" name="dontFormat" id="dontFormat">
762 <label for="dontFormat"><?php echo __('Show unformatted values'); ?></label>
763 </div>
764 </fieldset>
765 <div id="linkSuggestions" class="defaultLinks" style="display:none">
766 <p class="notice"><?php echo __('Related links:'); ?>
767 <?php
768 foreach ($links as $section_name => $section_links) {
769 echo '<span class="status_'.$section_name.'"> ';
770 $i=0;
771 foreach ($section_links as $link_name => $link_url) {
772 if ($i > 0) echo ', ';
773 if ('doc' == $link_name) {
774 echo PMA_showMySQLDocu($link_url, $link_url);
775 } else {
776 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
778 $i++;
780 echo '</span>';
782 unset($link_url, $link_name, $i);
784 </p>
785 </div>
786 <div class="tabInnerContent">
787 <?php printVariablesTable(); ?>
788 </div>
789 </div>
791 <div id="statustabs_charting">
792 <?php printMonitor(); ?>
793 </div>
795 <div id="statustabs_advisor">
796 <p><a href="#startAnalyzer">Start analyzer</a> | <a href="#openAdvisorInstructions">Instructions</a></p>
797 <div class="tabInnerContent">
798 </div>
799 <div id="advisorInstructionsDialog" style="display:none;">
800 <?php echo __('The Advisor system can provide recommendations on server variables by analyzing the server status variables.
801 Do note however that this system provides recommendations based on fairly simple calculations and by rule of thumb and
802 may not necessarily work for your system.
803 Prior to changing any of the configuration, be sure to know what you are changing and how to undo the change. Wrong tuning
804 can have a very negative effect on performance.
805 The best way to tune the system would be to change only one setting at a time, observe or benchmark your database, and
806 undo the change if there was no clearly measurable improvement.'); ?>
807 </div>
808 </div>
809 </div>
810 </div>
812 <?php
814 function printQueryStatistics()
816 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
818 $hour_factor = 3600 / $server_status['Uptime'];
820 $total_queries = array_sum($used_queries);
823 <h3 id="serverstatusqueries">
824 <?php
825 /* l10n: Questions is the name of a MySQL Status variable */
826 echo sprintf(__('Questions since startup: %s'),PMA_formatNumber($total_queries, 0)) . ' ';
827 echo PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_Questions');
829 <br>
830 <span>
831 <?php
832 echo '&oslash; '.__('per hour').': ';
833 echo PMA_formatNumber($total_queries * $hour_factor, 0);
834 echo '<br>';
836 echo '&oslash; '.__('per minute').': ';
837 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
838 echo '<br>';
840 if ($total_queries / $server_status['Uptime'] >= 1) {
841 echo '&oslash; '.__('per second').': ';
842 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
845 </span>
846 </h3>
847 <?php
849 // reverse sort by value to show most used statements first
850 arsort($used_queries);
852 $odd_row = true;
853 $count_displayed_rows = 0;
854 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
858 <table id="serverstatusqueriesdetails" class="data sortable noclick">
859 <col class="namecol" />
860 <col class="valuecol" span="3" />
861 <thead>
862 <tr><th><?php echo __('Statements'); ?></th>
863 <th><?php
864 /* l10n: # = Amount of queries */
865 echo __('#');
867 <th>&oslash; <?php echo __('per hour'); ?></th>
868 <th>%</th>
869 </tr>
870 </thead>
871 <tbody>
873 <?php
874 $chart_json = array();
875 $query_sum = array_sum($used_queries);
876 $other_sum = 0;
877 foreach ($used_queries as $name => $value) {
878 $odd_row = !$odd_row;
880 // For the percentage column, use Questions - Connections, because
881 // the number of connections is not an item of the Query types
882 // but is included in Questions. Then the total of the percentages is 100.
883 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
885 // Group together values that make out less than 2% into "Other", but only if we have more than 6 fractions already
886 if ($value < $query_sum * 0.02 && count($chart_json)>6)
887 $other_sum += $value;
888 else $chart_json[$name] = $value;
890 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
891 <th class="name"><?php echo htmlspecialchars($name); ?></th>
892 <td class="value"><?php echo PMA_formatNumber($value, 5, 0, true); ?></td>
893 <td class="value"><?php echo
894 PMA_formatNumber($value * $hour_factor, 4, 1, true); ?></td>
895 <td class="value"><?php echo
896 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
897 </tr>
898 <?php
901 </tbody>
902 </table>
904 <div id="serverstatusquerieschart">
905 <span style="display:none;">
906 <?php
907 if ($other_sum > 0)
908 $chart_json[__('Other')] = $other_sum;
910 echo json_encode($chart_json);
912 </span>
913 </div>
914 <?php
917 function printServerTraffic()
919 global $server_status,$PMA_PHP_SELF;
920 global $server_master_status, $server_slave_status, $replication_types;
922 $hour_factor = 3600 / $server_status['Uptime'];
925 * starttime calculation
927 $start_time = PMA_DBI_fetch_value(
928 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
931 <h3><?php
932 echo sprintf(
933 __('Network traffic since startup: %s'),
934 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
937 </h3>
940 <?php
941 echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'),
942 PMA_timespanFormat($server_status['Uptime']),
943 PMA_localisedDate($start_time)) . "\n";
945 </p>
947 <?php
948 if ($server_master_status || $server_slave_status) {
949 echo '<p class="notice">';
950 if ($server_master_status && $server_slave_status) {
951 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
952 } elseif ($server_master_status) {
953 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
954 } elseif ($server_slave_status) {
955 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
957 echo ' ';
958 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
959 echo '</p>';
962 /* if the server works as master or slave in replication process, display useful information */
963 if ($server_master_status || $server_slave_status)
966 <hr class="clearfloat" />
968 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
969 <?php
971 foreach ($replication_types as $type)
973 if (${"server_{$type}_status"}) {
974 PMA_replication_print_status_table($type);
977 unset($types);
981 <table id="serverstatustraffic" class="data noclick">
982 <thead>
983 <tr>
984 <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>
985 <th>&oslash; <?php echo __('per hour'); ?></th>
986 </tr>
987 </thead>
988 <tbody>
989 <tr class="odd">
990 <th class="name"><?php echo __('Received'); ?></th>
991 <td class="value"><?php echo
992 implode(' ',
993 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
994 <td class="value"><?php echo
995 implode(' ',
996 PMA_formatByteDown(
997 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
998 </tr>
999 <tr class="even">
1000 <th class="name"><?php echo __('Sent'); ?></th>
1001 <td class="value"><?php echo
1002 implode(' ',
1003 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
1004 <td class="value"><?php echo
1005 implode(' ',
1006 PMA_formatByteDown(
1007 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
1008 </tr>
1009 <tr class="odd">
1010 <th class="name"><?php echo __('Total'); ?></th>
1011 <td class="value"><?php echo
1012 implode(' ',
1013 PMA_formatByteDown(
1014 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
1015 ); ?></td>
1016 <td class="value"><?php echo
1017 implode(' ',
1018 PMA_formatByteDown(
1019 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
1020 * $hour_factor, 3, 1)
1021 ); ?></td>
1022 </tr>
1023 </tbody>
1024 </table>
1026 <table id="serverstatusconnections" class="data noclick">
1027 <thead>
1028 <tr>
1029 <th colspan="2"><?php echo __('Connections'); ?></th>
1030 <th>&oslash; <?php echo __('per hour'); ?></th>
1031 <th>%</th>
1032 </tr>
1033 </thead>
1034 <tbody>
1035 <tr class="odd">
1036 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
1037 <td class="value"><?php echo
1038 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
1039 <td class="value">--- </td>
1040 <td class="value">--- </td>
1041 </tr>
1042 <tr class="even">
1043 <th class="name"><?php echo __('Failed attempts'); ?></th>
1044 <td class="value"><?php echo
1045 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
1046 <td class="value"><?php echo
1047 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
1048 4, 2, true); ?></td>
1049 <td class="value"><?php echo
1050 $server_status['Connections'] > 0
1051 ? PMA_formatNumber(
1052 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
1053 0, 2, true) . '%'
1054 : '--- '; ?></td>
1055 </tr>
1056 <tr class="odd">
1057 <th class="name"><?php echo __('Aborted'); ?></th>
1058 <td class="value"><?php echo
1059 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
1060 <td class="value"><?php echo
1061 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
1062 4, 2, true); ?></td>
1063 <td class="value"><?php echo
1064 $server_status['Connections'] > 0
1065 ? PMA_formatNumber(
1066 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
1067 0, 2, true) . '%'
1068 : '--- '; ?></td>
1069 </tr>
1070 <tr class="even">
1071 <th class="name"><?php echo __('Total'); ?></th>
1072 <td class="value"><?php echo
1073 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
1074 <td class="value"><?php echo
1075 PMA_formatNumber($server_status['Connections'] * $hour_factor,
1076 4, 2); ?></td>
1077 <td class="value"><?php echo
1078 PMA_formatNumber(100, 0, 2); ?>%</td>
1079 </tr>
1080 </tbody>
1081 </table>
1082 <?php
1084 $url_params = array();
1086 $show_full_sql = !empty($_REQUEST['full']);
1087 if ($show_full_sql) {
1088 $url_params['full'] = 1;
1089 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
1090 } else {
1091 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
1093 if (PMA_DRIZZLE) {
1094 $sql_query = "SELECT
1095 p.id AS Id,
1096 p.username AS User,
1097 p.host AS Host,
1098 p.db AS db,
1099 p.command AS Command,
1100 p.time AS Time,
1101 p.state AS State,
1102 " . ($show_full_sql ? 's.query' : 'left(p.info, ' . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info
1103 FROM data_dictionary.PROCESSLIST p
1104 " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
1105 } else {
1106 $sql_query = $show_full_sql
1107 ? 'SHOW FULL PROCESSLIST'
1108 : 'SHOW PROCESSLIST';
1110 $result = PMA_DBI_query($sql_query);
1113 * Displays the page
1116 <table id="tableprocesslist" class="data clearfloat noclick">
1117 <thead>
1118 <tr>
1119 <th><?php echo __('Processes'); ?></th>
1120 <th><?php echo __('ID'); ?></th>
1121 <th><?php echo __('User'); ?></th>
1122 <th><?php echo __('Host'); ?></th>
1123 <th><?php echo __('Database'); ?></th>
1124 <th><?php echo __('Command'); ?></th>
1125 <th><?php echo __('Time'); ?></th>
1126 <th><?php echo __('Status'); ?></th>
1127 <th><?php echo __('SQL query'); ?>
1128 <a href="<?php echo $full_text_link; ?>"
1129 title="<?php echo $show_full_sql ? __('Truncate Shown Queries') : __('Show Full Queries'); ?>">
1130 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . ($show_full_sql ? 'partial' : 'full'); ?>text.png"
1131 alt="<?php echo $show_full_sql ? __('Truncate Shown Queries') : __('Show Full Queries'); ?>" />
1132 </a>
1133 </th>
1134 </tr>
1135 </thead>
1136 <tbody>
1137 <?php
1138 $odd_row = true;
1139 while ($process = PMA_DBI_fetch_assoc($result)) {
1140 $url_params['kill'] = $process['Id'];
1141 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
1143 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
1144 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
1145 <td class="value"><?php echo $process['Id']; ?></td>
1146 <td><?php echo $process['User']; ?></td>
1147 <td><?php echo $process['Host']; ?></td>
1148 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
1149 <td><?php echo $process['Command']; ?></td>
1150 <td class="value"><?php echo $process['Time']; ?></td>
1151 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
1152 <td>
1153 <?php
1154 if (empty($process['Info'])) {
1155 echo '---';
1156 } else {
1157 if (!$show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
1158 echo htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
1159 } else {
1160 echo PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
1164 </td>
1165 </tr>
1166 <?php
1167 $odd_row = ! $odd_row;
1170 </tbody>
1171 </table>
1172 <?php
1175 function printVariablesTable()
1177 global $server_status, $server_variables, $allocationMap, $links;
1179 * Messages are built using the message name
1181 $strShowStatus = array(
1182 'Aborted_clients' => __('The number of connections that were aborted because the client died without closing the connection properly.'),
1183 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
1184 '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.'),
1185 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
1186 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
1187 '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.'),
1188 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
1189 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
1190 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
1191 '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.'),
1192 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
1193 'Flush_commands' => __('The number of executed FLUSH statements.'),
1194 'Handler_commit' => __('The number of internal COMMIT statements.'),
1195 'Handler_delete' => __('The number of times a row was deleted from a table.'),
1196 '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.'),
1197 '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.'),
1198 '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.'),
1199 '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.'),
1200 '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.'),
1201 '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.'),
1202 '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.'),
1203 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
1204 'Handler_update' => __('The number of requests to update a row in a table.'),
1205 'Handler_write' => __('The number of requests to insert a row in a table.'),
1206 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
1207 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
1208 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
1209 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
1210 '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.'),
1211 '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.'),
1212 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
1213 '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.'),
1214 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
1215 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
1216 '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.'),
1217 '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.'),
1218 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
1219 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
1220 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
1221 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
1222 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
1223 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
1224 'Innodb_data_reads' => __('The total number of data reads.'),
1225 'Innodb_data_writes' => __('The total number of data writes.'),
1226 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
1227 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
1228 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
1229 '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.'),
1230 'Innodb_log_write_requests' => __('The number of log write requests.'),
1231 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
1232 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
1233 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
1234 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
1235 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
1236 'Innodb_pages_created' => __('The number of pages created.'),
1237 '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.'),
1238 'Innodb_pages_read' => __('The number of pages read.'),
1239 'Innodb_pages_written' => __('The number of pages written.'),
1240 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
1241 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
1242 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
1243 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
1244 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
1245 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
1246 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
1247 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
1248 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
1249 '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.'),
1250 '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.'),
1251 '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.'),
1252 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
1253 '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.'),
1254 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
1255 'Key_writes' => __('The number of physical writes of a key block to disk.'),
1256 '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.'),
1257 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
1258 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
1259 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
1260 'Open_files' => __('The number of files that are open.'),
1261 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
1262 'Open_tables' => __('The number of tables that are open.'),
1263 '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.'),
1264 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
1265 'Qcache_hits' => __('The number of cache hits.'),
1266 'Qcache_inserts' => __('The number of queries added to the cache.'),
1267 '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.'),
1268 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
1269 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
1270 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
1271 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
1272 '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.'),
1273 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
1274 '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.)'),
1275 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
1276 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
1277 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
1278 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
1279 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
1280 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
1281 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
1282 '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.'),
1283 'Sort_range' => __('The number of sorts that were done with ranges.'),
1284 'Sort_rows' => __('The number of sorted rows.'),
1285 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
1286 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
1287 '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.'),
1288 '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.'),
1289 'Threads_connected' => __('The number of currently open connections.'),
1290 '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.)'),
1291 'Threads_running' => __('The number of threads that are not sleeping.')
1295 * define some alerts
1297 // name => max value before alert
1298 $alerts = array(
1299 // lower is better
1300 // variable => max value
1301 'Aborted_clients' => 0,
1302 'Aborted_connects' => 0,
1304 'Binlog_cache_disk_use' => 0,
1306 'Created_tmp_disk_tables' => 0,
1308 'Handler_read_rnd' => 0,
1309 'Handler_read_rnd_next' => 0,
1311 'Innodb_buffer_pool_pages_dirty' => 0,
1312 'Innodb_buffer_pool_reads' => 0,
1313 'Innodb_buffer_pool_wait_free' => 0,
1314 'Innodb_log_waits' => 0,
1315 'Innodb_row_lock_time_avg' => 10, // ms
1316 'Innodb_row_lock_time_max' => 50, // ms
1317 'Innodb_row_lock_waits' => 0,
1319 'Slow_queries' => 0,
1320 'Delayed_errors' => 0,
1321 'Select_full_join' => 0,
1322 'Select_range_check' => 0,
1323 'Sort_merge_passes' => 0,
1324 'Opened_tables' => 0,
1325 'Table_locks_waited' => 0,
1326 'Qcache_lowmem_prunes' => 0,
1328 'Qcache_free_blocks' => isset($server_status['Qcache_total_blocks']) ? $server_status['Qcache_total_blocks'] / 5 : 0,
1329 'Slow_launch_threads' => 0,
1331 // depends on Key_read_requests
1332 // normaly lower then 1:0.01
1333 'Key_reads' => isset($server_status['Key_read_requests']) ? (0.01 * $server_status['Key_read_requests']) : 0,
1334 // depends on Key_write_requests
1335 // normaly nearly 1:1
1336 'Key_writes' => isset($server_status['Key_write_requests']) ? (0.9 * $server_status['Key_write_requests']) : 0,
1338 'Key_buffer_fraction' => 0.5,
1340 // alert if more than 95% of thread cache is in use
1341 'Threads_cached' => isset($server_variables['thread_cache_size']) ? 0.95 * $server_variables['thread_cache_size'] : 0
1343 // higher is better
1344 // variable => min value
1345 //'Handler read key' => '> ',
1349 <table class="data sortable noclick" id="serverstatusvariables">
1350 <col class="namecol" />
1351 <col class="valuecol" />
1352 <col class="descrcol" />
1353 <thead>
1354 <tr>
1355 <th><?php echo __('Variable'); ?></th>
1356 <th><?php echo __('Value'); ?></th>
1357 <th><?php echo __('Description'); ?></th>
1358 </tr>
1359 </thead>
1360 <tbody>
1361 <?php
1363 $odd_row = false;
1364 foreach ($server_status as $name => $value) {
1365 $odd_row = !$odd_row;
1367 <tr class="<?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_'.$allocationMap[$name]:''; ?>">
1368 <th class="name"><?php echo htmlspecialchars(str_replace('_',' ',$name)) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1369 </th>
1370 <td class="value"><span class="formatted"><?php
1371 if (isset($alerts[$name])) {
1372 if ($value > $alerts[$name]) {
1373 echo '<span class="attention">';
1374 } else {
1375 echo '<span class="allfine">';
1378 if ('%' === substr($name, -1, 1)) {
1379 echo PMA_formatNumber($value, 0, 2) . ' %';
1380 } elseif (strpos($name,'Uptime')!==FALSE) {
1381 echo PMA_timespanFormat($value);
1382 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1383 echo PMA_formatNumber($value, 3, 1);
1384 } elseif (is_numeric($value) && $value == (int) $value) {
1385 echo PMA_formatNumber($value, 3, 0);
1386 } elseif (is_numeric($value)) {
1387 echo PMA_formatNumber($value, 3, 1);
1388 } else {
1389 echo htmlspecialchars($value);
1391 if (isset($alerts[$name])) {
1392 echo '</span>';
1394 ?></span><span style="display:none;" class="original"><?php echo $value; ?></span>
1395 </td>
1396 <td class="descr">
1397 <?php
1398 if (isset($strShowStatus[$name ])) {
1399 echo $strShowStatus[$name];
1402 if (isset($links[$name])) {
1403 foreach ($links[$name] as $link_name => $link_url) {
1404 if ('doc' == $link_name) {
1405 echo PMA_showMySQLDocu($link_url, $link_url);
1406 } else {
1407 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1408 "\n";
1411 unset($link_url, $link_name);
1414 </td>
1415 </tr>
1416 <?php
1419 </tbody>
1420 </table>
1421 <?php
1424 function printMonitor()
1426 global $server_status, $server_db_isLocal;
1428 <div class="monitorLinks">
1429 <a href="#pauseCharts">
1430 <img src="themes/dot.gif" class="icon ic_play" alt="" />
1431 <?php echo __('Start Monitor'); ?>
1432 </a>
1433 <a href="#settingsPopup" rel="popupLink" style="display:none;">
1434 <img src="themes/dot.gif" class="icon ic_s_cog" alt="" />
1435 <?php echo __('Settings'); ?>
1436 </a>
1437 <?php if (!PMA_DRIZZLE) { ?>
1438 <a href="#monitorInstructionsDialog">
1439 <img src="themes/dot.gif" class="icon ic_b_help" alt="" />
1440 <?php echo __('Instructions/Setup'); ?>
1441 </a>
1442 <?php } ?>
1443 <a href="#endChartEditMode" style="display:none;">
1444 <img src="themes/dot.gif" class="icon ic_s_okay" alt="" />
1445 <?php echo __('Done rearranging/editing charts'); ?>
1446 </a>
1447 </div>
1449 <div class="popupContent settingsPopup">
1450 <a href="#addNewChart">
1451 <img src="themes/dot.gif" class="icon ic_b_chart" alt="" />
1452 <?php echo __('Add chart'); ?>
1453 </a>
1454 <a href="#rearrangeCharts"><img class="icon ic_b_tblops" src="themes/dot.gif" width="16" height="16" alt=""> <?php echo __('Rearrange/edit charts'); ?></a>
1455 <div class="clearfloat paddingtop"></div>
1456 <div class="floatleft">
1457 <?php echo __('Refresh rate').'<br />'; refreshList('gridChartRefresh', 5, Array(2,3,4,5,10,20,40,60,120,300,600,1200)); ?><br>
1458 </div>
1459 <div class="floatleft">
1460 <?php echo __('Chart columns'); ?> <br />
1461 <select name="chartColumns">
1462 <option>1</option>
1463 <option>2</option>
1464 <option>3</option>
1465 <option>4</option>
1466 <option>5</option>
1467 <option>6</option>
1468 <option>7</option>
1469 <option>8</option>
1470 <option>9</option>
1471 <option>10</option>
1472 </select>
1473 </div>
1475 <div class="clearfloat paddingtop">
1476 <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/>
1477 <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>
1478 </div>
1479 </div>
1481 <div id="monitorInstructionsDialog" title="<?php echo __('Monitor Instructions'); ?>" style="display:none;">
1482 <?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%'); ?>
1483 <?php if(PMA_MYSQL_INT_VERSION < 50106) { ?>
1485 <img class="icon ic_s_attention" src="themes/dot.gif" alt="">
1486 <?php
1487 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.');
1489 </p>
1490 <?php
1491 } else {
1493 <p></p>
1494 <img class="ajaxIcon" src="<?php echo $GLOBALS['pmaThemeImage']; ?>ajax_clock_small.gif" alt="Loading">
1495 <div class="ajaxContent"></div>
1496 <div class="monitorUse" style="display:none;">
1497 <p></p>
1498 <?php
1499 echo __('<b>Using the monitor:</b><br/> 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. <p>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.</p>');
1502 <img class="icon ic_s_attention" src="themes/dot.gif" alt="">
1503 <?php
1504 echo __('<b>Please note:</b> 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.');
1506 </p>
1507 </div>
1508 <?php } ?>
1509 </div>
1511 <div id="addChartDialog" title="Add chart" style="display:none;">
1512 <div id="tabGridVariables">
1513 <p><input type="text" name="chartTitle" value="<?php echo __('Chart Title'); ?>" /></p>
1514 <?php if ($server_db_isLocal) { ?>
1515 <input type="radio" name="chartType" value="cpu" id="chartCPU">
1516 <label for="chartCPU"><?php echo __('CPU Usage'); ?></label><br/>
1518 <input type="radio" name="chartType" value="memory" id="chartMemory">
1519 <label for="chartMemory"><?php echo __('Memory Usage'); ?></label><br/>
1521 <input type="radio" name="chartType" value="swap" id="chartSwap">
1522 <label for="chartSwap"><?php echo __('Swap Usage'); ?></label><br/>
1523 <?php } ?>
1524 <input type="radio" name="chartType" value="variable" id="chartStatusVar" checked="checked">
1525 <label for="chartStatusVar"><?php echo __('Status variable(s)'); ?></label><br/>
1526 <div id="chartVariableSettings">
1527 <label for="chartSeries"><?php echo __('Select series:'); ?></label><br>
1528 <select id="chartSeries" name="varChartList" size="1">
1529 <option><?php echo __('Commonly monitored'); ?></option>
1530 <option>Processes</option>
1531 <option>Questions</option>
1532 <option>Connections</option>
1533 <option>Bytes_sent</option>
1534 <option>Bytes_received</option>
1535 <option>Threads_connected</option>
1536 <option>Created_tmp_disk_tables</option>
1537 <option>Handler_read_first</option>
1538 <option>Innodb_buffer_pool_wait_free</option>
1539 <option>Key_reads</option>
1540 <option>Open_tables</option>
1541 <option>Select_full_join</option>
1542 <option>Slow_queries</option>
1543 </select><br>
1544 <label for="variableInput"><?php echo __('or type variable name:'); ?> </label>
1545 <input type="text" name="variableInput" id="variableInput" />
1546 <p></p>
1547 <input type="checkbox" name="differentialValue" id="differentialValue" value="differential" checked="checked" />
1548 <label for="differentialValue"><?php echo __('Display as differential value'); ?></label><br>
1549 <input type="checkbox" id="useDivisor" name="useDivisor" value="1" />
1550 <label for="useDivisor"><?php echo __('Apply a divisor'); ?></label>
1551 <span class="divisorInput" style="display:none;">
1552 <input type="text" name="valueDivisor" size="4" value="1">
1553 (<a href="#kibDivisor"><?php echo __('KiB'); ?></a>, <a href="#mibDivisor"><?php echo __('MiB'); ?></a>)
1554 </span><br>
1556 <input type="checkbox" id="useUnit" name="useUnit" value="1" />
1557 <label for="useUnit"><?php echo __('Append unit to data values'); ?></label>
1559 <span class="unitInput" style="display:none;">
1560 <input type="text" name="valueUnit" size="4" value="">
1561 </span>
1563 <a href="#submitAddSeries"><b><?php echo __('Add this series'); ?></b></a>
1564 <span id="clearSeriesLink" style="display:none;">
1565 | <a href="#submitClearSeries"><?php echo __('Clear series'); ?></a>
1566 </span>
1567 </p>
1568 <?php echo __('Series in Chart:'); ?><br/>
1569 <span id="seriesPreview">
1570 <i><?php echo __('None'); ?></i>
1571 </span>
1572 </div>
1573 </div>
1574 </div>
1576 <!-- For generic use -->
1577 <div id="emptyDialog" title="Dialog" style="display:none;">
1578 </div>
1580 <?php if (!PMA_DRIZZLE) { ?>
1581 <div id="logAnalyseDialog" title="<?php echo __('Log statistics'); ?>" style="display:none;">
1582 <p> <?php echo __('Selected time range:'); ?>
1583 <input type="text" name="dateStart" class="datetimefield" value="" /> -
1584 <input type="text" name="dateEnd" class="datetimefield" value="" /></p>
1585 <input type="checkbox" id="limitTypes" value="1" checked="checked" />
1586 <label for="limitTypes">
1587 <?php echo __('Only retrieve SELECT,INSERT,UPDATE and DELETE Statements'); ?>
1588 </label>
1589 <br/>
1590 <input type="checkbox" id="removeVariables" value="1" checked="checked" />
1591 <label for="removeVariables">
1592 <?php echo __('Remove variable data in INSERT statements for better grouping'); ?>
1593 </label>
1595 <?php echo __('<p>Choose from which log you want the statistics to be generated from.</p> Results are grouped by query text.'); ?>
1596 </div>
1598 <div id="queryAnalyzerDialog" title="<?php echo __('Query analyzer'); ?>" style="display:none;">
1599 <textarea id="sqlquery"> </textarea>
1600 <p></p>
1601 <div class="placeHolder"></div>
1602 </div>
1603 <?php } ?>
1605 <table border="0" class="clearfloat" id="chartGrid">
1607 </table>
1608 <div id="logTable">
1609 <br/>
1610 </div>
1612 <script type="text/javascript">
1613 variableNames = [ <?php
1614 $i=0;
1615 foreach ($server_status as $name=>$value) {
1616 if (is_numeric($value)) {
1617 if ($i++ > 0) echo ", ";
1618 echo "'".$name."'";
1621 ?> ];
1622 </script>
1623 <?php
1626 /* Builds a <select> list for refresh rates */
1627 function refreshList($name,$defaultRate=5, $refreshRates=Array(1, 2, 5, 10, 20, 40, 60, 120, 300, 600))
1630 <select name="<?php echo $name; ?>">
1631 <?php
1632 foreach ($refreshRates as $rate) {
1633 $selected = ($rate == $defaultRate)?' selected="selected"':'';
1635 if ($rate<60)
1636 echo '<option value="'.$rate.'"'.$selected.'>'.sprintf(_ngettext('%d second', '%d seconds', $rate), $rate).'</option>';
1637 else
1638 echo '<option value="'.$rate.'"'.$selected.'>'.sprintf(_ngettext('%d minute', '%d minutes', $rate/60), $rate/60).'</option>';
1641 </select>
1642 <?php
1646 * cleanup of some deprecated values
1648 * @param array &$server_status
1650 function cleanDeprecated(&$server_status)
1652 $deprecated = array(
1653 'Com_prepare_sql' => 'Com_stmt_prepare',
1654 'Com_execute_sql' => 'Com_stmt_execute',
1655 'Com_dealloc_sql' => 'Com_stmt_close',
1658 foreach ($deprecated as $old => $new) {
1659 if (isset($server_status[$old]) && isset($server_status[$new])) {
1660 unset($server_status[$old]);
1666 * Sends the footer
1668 require './libraries/footer.inc.php';