Missing docblock
[phpmyadmin/ammaryasirr.git] / server_status.php
blob58922d15ea77974151803f5eeb7a3b65896bb673
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 $queries = PMA_DBI_fetch_result(
49 "SHOW GLOBAL STATUS
50 WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions')
51 AND Value > 0'", 0, 1);
52 cleanDeprecated($queries);
53 // admin commands are not queries
54 unset($queries['Com_admin_commands']);
55 $questions = $queries['Questions'];
56 unset($queries['Questions']);
58 //$sum=array_sum($queries);
59 $ret = array(
60 'x' => microtime(true)*1000,
61 'y' => $questions,
62 'pointInfo' => $queries
65 exit(json_encode($ret));
67 case 'traffic':
68 $traffic = PMA_DBI_fetch_result(
69 "SHOW GLOBAL STATUS
70 WHERE Variable_name = 'Bytes_received'
71 OR Variable_name = 'Bytes_sent'", 0, 1);
73 $ret = array(
74 'x' => microtime(true)*1000,
75 'y_sent' => $traffic['Bytes_sent'],
76 'y_received' => $traffic['Bytes_received']
79 exit(json_encode($ret));
81 case 'chartgrid':
82 $ret = json_decode($_REQUEST['requiredData'], true);
83 $statusVars = array();
84 $sysinfo = $cpuload = $memory = 0;
86 foreach ($ret as $chart_id => $chartNodes) {
87 foreach ($chartNodes as $node_id => $node) {
88 switch ($node['dataType']) {
89 case 'statusvar':
90 // Some white list filtering
91 if (!preg_match('/[^a-zA-Z_]+/',$node['dataPoint']))
92 $statusVars[] = $node['dataPoint'];
93 break;
95 case 'proc':
96 $result = PMA_DBI_query('SHOW PROCESSLIST');
97 $ret[$chart_id][$node_id]['y'] = PMA_DBI_num_rows($result);
98 break;
100 case 'cpu':
101 if (!$sysinfo) {
102 require_once('libraries/sysinfo.lib.php');
103 $sysinfo = getSysInfo();
105 if (!$cpuload)
106 $cpuload = $sysinfo->loadavg();
108 if (PHP_OS == 'Linux') {
109 $ret[$chart_id][$node_id]['idle'] = $cpuload['idle'];
110 $ret[$chart_id][$node_id]['busy'] = $cpuload['busy'];
111 } else
112 $ret[$chart_id][$node_id]['y'] = $cpuload['loadavg'];
114 break;
116 case 'memory':
117 if (!$sysinfo) {
118 require_once('libraries/sysinfo.lib.php');
119 $sysinfo = getSysInfo();
121 if (!$memory)
122 $memory = $sysinfo->memory();
124 $ret[$chart_id][$node_id]['y'] = $memory[$node['dataPoint']];
125 break;
130 $vars = PMA_DBI_fetch_result(
131 "SHOW GLOBAL STATUS
132 WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1);
134 foreach ($ret as $chart_id => $chartNodes) {
135 foreach ($chartNodes as $node_id => $node) {
136 if ($node['dataType'] == 'statusvar')
137 $ret[$chart_id][$node_id]['y'] = $vars[$node['dataPoint']];
141 $ret['x'] = microtime(true)*1000;
143 exit(json_encode($ret));
147 if (isset($_REQUEST['log_data'])) {
148 if(PMA_MYSQL_INT_VERSION < 50106) exit('""');
150 $start = intval($_REQUEST['time_start']);
151 $end = intval($_REQUEST['time_end']);
153 if ($_REQUEST['type'] == 'slow') {
154 $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, '.
155 'SUM(rows_sent) AS rows_sent, SUM(rows_examined) AS rows_examined, db, sql_text, COUNT(sql_text) AS \'#\' '.
156 'FROM `mysql`.`slow_log` WHERE start_time > FROM_UNIXTIME('.$start.') '.
157 'AND start_time < FROM_UNIXTIME('.$end.') GROUP BY sql_text';
159 $result = PMA_DBI_try_query($q);
161 $return = array('rows' => array(), 'sum' => array());
162 $type = '';
164 while ($row = PMA_DBI_fetch_assoc($result)) {
165 $type = strtolower(substr($row['sql_text'],0,strpos($row['sql_text'],' ')));
167 switch($type) {
168 case 'insert':
169 case 'update':
170 // Cut off big inserts and updates, but append byte count therefor
171 if(strlen($row['sql_text']) > 220)
172 $row['sql_text'] = substr($row['sql_text'],0,200) . '... [' .
173 implode(' ',PMA_formatByteDown(strlen($row['sql_text']), 2, 2)).']';
175 break;
176 default:
177 break;
180 if(!isset($return['sum'][$type])) $return['sum'][$type] = 0;
181 $return['sum'][$type] += $row['#'];
182 $return['rows'][] = $row;
185 $return['sum']['TOTAL'] = array_sum($return['sum']);
186 $return['numRows'] = count($return['rows']);
188 PMA_DBI_free_result($result);
190 exit(json_encode($return));
193 if($_REQUEST['type'] == 'general') {
194 $limitTypes = (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes'])
195 ? 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ' : '';
197 $q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, server_id, argument, count(argument) as \'#\' '.
198 'FROM `mysql`.`general_log` WHERE command_type=\'Query\' '.
199 'AND event_time > FROM_UNIXTIME('.$start.') AND event_time < FROM_UNIXTIME('.$end.') '.
200 $limitTypes . 'GROUP by argument'; // HAVING count > 1';
202 $result = PMA_DBI_try_query($q);
204 $return = array('rows' => array(), 'sum' => array());
205 $type = '';
206 $insertTables = array();
207 $insertTablesFirst = -1;
208 $i = 0;
209 $removeVars = isset($_REQUEST['removeVariables']) && $_REQUEST['removeVariables'];
211 while ($row = PMA_DBI_fetch_assoc($result)) {
212 preg_match('/^(\w+)\s/',$row['argument'],$match);
213 $type = strtolower($match[1]);
215 if(!isset($return['sum'][$type])) $return['sum'][$type] = 0;
216 $return['sum'][$type] += $row['#'];
218 switch($type) {
219 case 'insert':
220 // Group inserts if selected
221 if($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i',$row['argument'],$matches)) {
222 $insertTables[$matches[2]]++;
223 if ($insertTables[$matches[2]] > 1) {
224 $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
226 // Add a ... to the end of this query to indicate that there's been other queries
227 if($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.')
228 $return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
230 // Group this value, thus do not add to the result list
231 continue 2;
232 } else {
233 $insertTablesFirst = $i;
234 $insertTables[$matches[2]] += $row['#'] - 1;
237 // No break here
239 case 'update':
240 // Cut off big inserts and updates, but append byte count therefor
241 if(strlen($row['argument']) > 220)
242 $row['argument'] = substr($row['argument'],0,200) . '... [' .
243 implode(' ',PMA_formatByteDown(strlen($row['argument'])), 2, 2).']';
245 break;
247 default: break;
250 $return['rows'][] = $row;
251 $i++;
254 $return['sum']['TOTAL'] = array_sum($return['sum']);
255 $return['numRows'] = count($return['rows']);
257 PMA_DBI_free_result($result);
259 exit(json_encode($return));
263 if (isset($_REQUEST['logging_vars'])) {
264 if(isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) {
265 $value = PMA_sqlAddslashes($_REQUEST['varValue']);
266 if(!is_numeric($value)) $value="'".$value."'";
268 if(! preg_match("/[^a-zA-Z0-9_]+/",$_REQUEST['varName']))
269 PMA_DBI_query('SET GLOBAL '.$_REQUEST['varName'].' = '.$value);
273 $loggingVars = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES WHERE Variable_name IN ("general_log","slow_query_log","long_query_time","log_output")', 0, 1);
274 exit(json_encode($loggingVars));
277 if(isset($_REQUEST['query_analyzer'])) {
278 $return = array();
280 if(strlen($_REQUEST['database']))
281 PMA_DBI_select_db($_REQUEST['database']);
283 if ($profiling = PMA_profilingSupported())
284 PMA_DBI_query('SET PROFILING=1;');
286 // Do not cache query
287 $query = preg_replace('/^(\s*SELECT)/i','\\1 SQL_NO_CACHE',$_REQUEST['query']);
289 $result = PMA_DBI_try_query($query);
290 $return['affectedRows'] = $GLOBALS['cached_affected_rows'];
292 $result = PMA_DBI_try_query('EXPLAIN ' . $query);
293 while ($row = PMA_DBI_fetch_assoc($result)) {
294 $return['explain'][] = $row;
297 // In case an error happened
298 $return['error'] = PMA_DBI_getError();
300 PMA_DBI_free_result($result);
302 if($profiling) {
303 $return['profiling'] = array();
304 $result = PMA_DBI_try_query('SELECT seq,state,duration FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID=1 ORDER BY seq');
305 while ($row = PMA_DBI_fetch_assoc($result)) {
306 $return['profiling'][]= $row;
308 PMA_DBI_free_result($result);
311 exit(json_encode($return));
314 if(isset($_REQUEST['advisor'])) {
315 include('libraries/advisor.lib.php');
316 $advisor = new Advisor();
317 exit(json_encode($advisor->run()));
323 * Replication library
325 require './libraries/replication.inc.php';
326 require_once './libraries/replication_gui.lib.php';
329 * JS Includes
332 $GLOBALS['js_include'][] = 'server_status.js';
333 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
334 $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
335 $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
336 $GLOBALS['js_include'][] = 'jquery/jquery.json-2.2.js';
337 $GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
338 $GLOBALS['js_include'][] = 'jquery/jquery.sortableTable.js';
339 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
340 // Charting
341 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
342 /* Files required for chart exporting */
343 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
344 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
345 $GLOBALS['js_include'][] = 'canvg/canvg.js';
346 $GLOBALS['js_include'][] = 'canvg/rgbcolor.js';
347 $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js';
348 $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js';
351 * flush status variables if requested
353 if (isset($_REQUEST['flush'])) {
354 $_flush_commands = array(
355 'STATUS',
356 'TABLES',
357 'QUERY CACHE',
360 if (in_array($_REQUEST['flush'], $_flush_commands)) {
361 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
363 unset($_flush_commands);
367 * Kills a selected process
369 if (!empty($_REQUEST['kill'])) {
370 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
371 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
372 } else {
373 $message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
375 $message->addParam($_REQUEST['kill']);
376 //$message->display();
382 * get status from server
384 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
387 * for some calculations we require also some server settings
389 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
392 * cleanup of some deprecated values
394 cleanDeprecated($server_status);
397 * calculate some values
399 // Key_buffer_fraction
400 if (isset($server_status['Key_blocks_unused'])
401 && isset($server_variables['key_cache_block_size'])
402 && isset($server_variables['key_buffer_size'])) {
403 $server_status['Key_buffer_fraction_%'] =
405 - $server_status['Key_blocks_unused']
406 * $server_variables['key_cache_block_size']
407 / $server_variables['key_buffer_size']
408 * 100;
409 } elseif (isset($server_status['Key_blocks_used'])
410 && isset($server_variables['key_buffer_size'])) {
411 $server_status['Key_buffer_fraction_%'] =
412 $server_status['Key_blocks_used']
413 * 1024
414 / $server_variables['key_buffer_size'];
417 // Ratio for key read/write
418 if (isset($server_status['Key_writes'])
419 && isset($server_status['Key_write_requests'])
420 && $server_status['Key_write_requests'] > 0) {
421 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
424 if (isset($server_status['Key_reads'])
425 && isset($server_status['Key_read_requests'])
426 && $server_status['Key_read_requests'] > 0) {
427 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
430 // Threads_cache_hitrate
431 if (isset($server_status['Threads_created'])
432 && isset($server_status['Connections'])
433 && $server_status['Connections'] > 0) {
435 $server_status['Threads_cache_hitrate_%'] =
436 100 - $server_status['Threads_created'] / $server_status['Connections'] * 100;
440 * split variables in sections
442 $allocations = array(
443 // variable name => section
444 // variable names match when they begin with the given string
446 'Com_' => 'com',
447 'Innodb_' => 'innodb',
448 'Ndb_' => 'ndb',
449 'Handler_' => 'handler',
450 'Qcache_' => 'qcache',
451 'Threads_' => 'threads',
452 'Slow_launch_threads' => 'threads',
454 'Binlog_cache_' => 'binlog_cache',
455 'Created_tmp_' => 'created_tmp',
456 'Key_' => 'key',
458 'Delayed_' => 'delayed',
459 'Not_flushed_delayed_rows' => 'delayed',
461 'Flush_commands' => 'query',
462 'Last_query_cost' => 'query',
463 'Slow_queries' => 'query',
464 'Queries' => 'query',
465 'Prepared_stmt_count' => 'query',
467 'Select_' => 'select',
468 'Sort_' => 'sort',
470 'Open_tables' => 'table',
471 'Opened_tables' => 'table',
472 'Open_table_definitions' => 'table',
473 'Opened_table_definitions' => 'table',
474 'Table_locks_' => 'table',
476 'Rpl_status' => 'repl',
477 'Slave_' => 'repl',
479 'Tc_' => 'tc',
481 'Ssl_' => 'ssl',
483 'Open_files' => 'files',
484 'Open_streams' => 'files',
485 'Opened_files' => 'files',
488 $sections = array(
489 // section => section name (description)
490 'com' => 'Com',
491 'query' => __('SQL query'),
492 'innodb' => 'InnoDB',
493 'ndb' => 'NDB',
494 'handler' => __('Handler'),
495 'qcache' => __('Query cache'),
496 'threads' => __('Threads'),
497 'binlog_cache' => __('Binary log'),
498 'created_tmp' => __('Temporary data'),
499 'delayed' => __('Delayed inserts'),
500 'key' => __('Key cache'),
501 'select' => __('Joins'),
502 'repl' => __('Replication'),
503 'sort' => __('Sorting'),
504 'table' => __('Tables'),
505 'tc' => __('Transaction coordinator'),
506 'files' => __('Files'),
507 'ssl' => 'SSL',
511 * define some needfull links/commands
513 // variable or section name => (name => url)
514 $links = array();
516 $links['table'][__('Flush (close) all tables')]
517 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
518 $links['table'][__('Show open tables')]
519 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
520 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
522 if ($server_master_status) {
523 $links['repl'][__('Show slave hosts')]
524 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
525 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
526 $links['repl'][__('Show master status')] = '#replication_master';
528 if ($server_slave_status) {
529 $links['repl'][__('Show slave status')] = '#replication_slave';
532 $links['repl']['doc'] = 'replication';
534 $links['qcache'][__('Flush query cache')]
535 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
536 PMA_generate_common_url();
537 $links['qcache']['doc'] = 'query_cache';
539 //$links['threads'][__('Show processes')]
540 // = 'server_processlist.php?' . PMA_generate_common_url();
541 $links['threads']['doc'] = 'mysql_threads';
543 $links['key']['doc'] = 'myisam_key_cache';
545 $links['binlog_cache']['doc'] = 'binary_log';
547 $links['Slow_queries']['doc'] = 'slow_query_log';
549 $links['innodb'][__('Variables')]
550 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
551 $links['innodb'][__('InnoDB Status')]
552 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
553 PMA_generate_common_url();
554 $links['innodb']['doc'] = 'innodb';
557 // Variable to contain all com_ variables
558 $used_queries = array();
560 // Variable to map variable names to their respective section name (used for js category filtering)
561 $allocationMap = array();
563 // sort vars into arrays
564 foreach ($server_status as $name => $value) {
565 foreach ($allocations as $filter => $section) {
566 if (strpos($name, $filter) !== false) {
567 $allocationMap[$name] = $section;
568 if ($section == 'com' && $value > 0) $used_queries[$name] = $value;
569 break; // Only exits inner loop
574 if(PMA_DRIZZLE) {
575 $used_queries = PMA_DBI_fetch_result('SELECT * FROM data_dictionary.global_statements', 0, 1);
576 unset($used_queries['admin_commands']);
577 } else {
578 // admin commands are not queries (e.g. they include COM_PING, which is excluded from $server_status['Questions'])
579 unset($used_queries['Com_admin_commands']);
582 /* Ajax request refresh */
583 if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
584 switch($_REQUEST['show']) {
585 case 'query_statistics':
586 printQueryStatistics();
587 exit();
588 case 'server_traffic':
589 printServerTraffic();
590 exit();
591 case 'variables_table':
592 // Prints the variables table
593 printVariablesTable();
594 exit();
596 default:
597 break;
602 * start output
606 * Does the common work
608 require './libraries/server_common.inc.php';
612 * Displays the links
614 require './libraries/server_links.inc.php';
616 $server = 1;
617 if (isset($_REQUEST['server']) && intval($_REQUEST['server'])) $server = intval($_REQUEST['server']);
619 $server_db_isLocal = strtolower($cfg['Servers'][$server]['host']) == 'localhost'
620 || $cfg['Servers'][$server]['host'] == '127.0.0.1'
621 || $cfg['Servers'][$server]['host'] == '::1';
624 <script type="text/javascript">
625 pma_token = '<?php echo $_SESSION[' PMA_token ']; ?>';
626 url_query = '<?php echo str_replace('&amp;','&',$url_query);?>';
627 server_time_diff = new Date().getTime() - <?php echo microtime(true)*1000; ?>;
628 server_os = '<?php echo PHP_OS; ?>';
629 is_superuser = <?php echo PMA_isSuperuser()?'true':'false'; ?>;
630 server_db_isLocal = <?php echo ($server_db_isLocal)?'true':'false'; ?>;
631 profiling_docu = '<?php echo PMA_showMySQLDocu('general-thread-states','general-thread-states'); ?>';
632 explain_docu = '<?php echo PMA_showMySQLDocu('explain-output', 'explain-output'); ?>';
633 </script>
634 <div id="serverstatus">
635 <h2><?php
637 * Displays the sub-page heading
639 if ($GLOBALS['cfg']['MainPageIconic']) {
640 echo '<img class="icon ic_s_status" src="themes/dot.gif" width="16" height="16" alt="" />';
643 echo __('Runtime Information');
645 ?></h2>
646 <div id="serverStatusTabs">
647 <ul>
648 <li><a href="#statustabs_traffic"><?php echo __('Server'); ?></a></li>
649 <li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
650 <li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
651 <li><a href="#statustabs_charting"><?php echo __('Monitor'); ?></a></li>
652 <li><a href="#statustabs_advisor"><?php echo __('Advisor'); ?></a></li>
653 </ul>
655 <div id="statustabs_traffic">
656 <div class="buttonlinks">
657 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&amp;' . PMA_generate_common_url(); ?>" >
658 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
659 <?php echo __('Refresh'); ?>
660 </a>
661 <span class="refreshList" style="display:none;">
662 <label for="trafficChartRefresh"><?php echo __('Refresh rate: '); ?></label>
663 <?php refreshList('trafficChartRefresh'); ?>
664 </span>
666 <a class="tabChart livetrafficLink" href="#">
667 <?php echo __('Live traffic chart'); ?>
668 </a>
669 <a class="tabChart liveconnectionsLink" href="#">
670 <?php echo __('Live conn./process chart'); ?>
671 </a>
672 </div>
673 <div class="tabInnerContent">
674 <?php printServerTraffic(); ?>
675 </div>
676 </div>
677 <div id="statustabs_queries">
678 <div class="buttonlinks">
679 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
680 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
681 <?php echo __('Refresh'); ?>
682 </a>
683 <span class="refreshList" style="display:none;">
684 <label for="queryChartRefresh"><?php echo __('Refresh rate: '); ?></label>
685 <?php refreshList('queryChartRefresh'); ?>
686 </span>
687 <a class="tabChart livequeriesLink" href="#">
688 <?php echo __('Live query chart'); ?>
689 </a>
690 </div>
691 <div class="tabInnerContent">
692 <?php printQueryStatistics(); ?>
693 </div>
694 </div>
695 <div id="statustabs_allvars">
696 <fieldset id="tableFilter">
697 <div class="buttonlinks">
698 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
699 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
700 <?php echo __('Refresh'); ?>
701 </a>
702 </div>
703 <legend>Filters</legend>
704 <div class="formelement">
705 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
706 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
707 </div>
708 <div class="formelement">
709 <input type="checkbox" name="filterAlert" id="filterAlert">
710 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
711 </div>
712 <div class="formelement">
713 <select id="filterCategory" name="filterCategory">
714 <option value=''><?php echo __('Filter by category...'); ?></option>
715 <?php
716 foreach ($sections as $section_id => $section_name) {
718 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
719 <?php
723 </select>
724 </div>
725 <div class="formelement">
726 <input type="checkbox" name="dontFormat" id="dontFormat">
727 <label for="dontFormat"><?php echo __('Show unformatted values'); ?></label>
728 </div>
729 </fieldset>
730 <div id="linkSuggestions" class="defaultLinks" style="display:none">
731 <p class="notice"><?php echo __('Related links:'); ?>
732 <?php
733 foreach ($links as $section_name => $section_links) {
734 echo '<span class="status_'.$section_name.'"> ';
735 $i=0;
736 foreach ($section_links as $link_name => $link_url) {
737 if ($i > 0) echo ', ';
738 if ('doc' == $link_name) {
739 echo PMA_showMySQLDocu($link_url, $link_url);
740 } else {
741 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
743 $i++;
745 echo '</span>';
747 unset($link_url, $link_name, $i);
749 </p>
750 </div>
751 <div class="tabInnerContent">
752 <?php printVariablesTable(); ?>
753 </div>
754 </div>
756 <div id="statustabs_charting">
757 <?php printMonitor(); ?>
758 </div>
760 <div id="statustabs_advisor">
761 <p><a href="#startAnalyzer">Start analyzer</a> | <a href="#openAdvisorInstructions">Instructions</a></p>
762 <div class="tabInnerContent">
763 </div>
764 <div id="advisorInstructionsDialog" style="display:none;">
765 <?php echo __('The Advisor system can provide recommendations on server variables by analyzing the server status variables.
766 Do note however that this system provides recommendations based on fairly simple calculations and by rule of thumb and
767 may not necessarily work for your system.
768 Prior to changing any of the configuration, be sure to know what you are changing and how to undo the change. Wrong tuning
769 can have a very negative effect on performance.
770 The best way to tune the system would be to change only one setting at a time, observe or benchmark your database, and
771 undo the change if there was no clearly measurable improvement.'); ?>
772 </div>
773 </div>
774 </div>
775 </div>
777 <?php
779 function printQueryStatistics()
781 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
783 $hour_factor = 3600 / $server_status['Uptime'];
785 $total_queries = array_sum($used_queries);
788 <h3 id="serverstatusqueries">
789 <?php
790 /* l10n: Questions is the name of a MySQL Status variable */
791 echo sprintf(__('Questions since startup: %s'),PMA_formatNumber($total_queries, 0)) . ' ';
792 echo PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_Questions');
794 <br>
795 <span>
796 <?php
797 echo '&oslash; '.__('per hour').': ';
798 echo PMA_formatNumber($total_queries * $hour_factor, 0);
799 echo '<br>';
801 echo '&oslash; '.__('per minute').': ';
802 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
803 echo '<br>';
805 if ($total_queries / $server_status['Uptime'] >= 1) {
806 echo '&oslash; '.__('per second').': ';
807 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
810 </span>
811 </h3>
812 <?php
814 // reverse sort by value to show most used statements first
815 arsort($used_queries);
817 $odd_row = true;
818 $count_displayed_rows = 0;
819 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
823 <table id="serverstatusqueriesdetails" class="data sortable noclick">
824 <col class="namecol" />
825 <col class="valuecol" span="3" />
826 <thead>
827 <tr><th><?php echo __('Statements'); ?></th>
828 <th><?php
829 /* l10n: # = Amount of queries */
830 echo __('#');
832 <th>&oslash; <?php echo __('per hour'); ?></th>
833 <th>%</th>
834 </tr>
835 </thead>
836 <tbody>
838 <?php
839 $chart_json = array();
840 $query_sum = array_sum($used_queries);
841 $other_sum = 0;
842 foreach ($used_queries as $name => $value) {
843 $odd_row = !$odd_row;
845 // For the percentage column, use Questions - Connections, because
846 // the number of connections is not an item of the Query types
847 // but is included in Questions. Then the total of the percentages is 100.
848 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
850 // Group together values that make out less than 2% into "Other", but only if we have more than 6 fractions already
851 if ($value < $query_sum * 0.02 && count($chart_json)>6)
852 $other_sum += $value;
853 else $chart_json[$name] = $value;
855 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
856 <th class="name"><?php echo htmlspecialchars($name); ?></th>
857 <td class="value"><?php echo PMA_formatNumber($value, 5, 0, true); ?></td>
858 <td class="value"><?php echo
859 PMA_formatNumber($value * $hour_factor, 4, 1, true); ?></td>
860 <td class="value"><?php echo
861 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
862 </tr>
863 <?php
866 </tbody>
867 </table>
869 <div id="serverstatusquerieschart">
870 <span style="display:none;">
871 <?php
872 if ($other_sum > 0)
873 $chart_json[__('Other')] = $other_sum;
875 echo json_encode($chart_json);
877 </span>
878 </div>
879 <?php
882 function printServerTraffic()
884 global $server_status,$PMA_PHP_SELF;
885 global $server_master_status, $server_slave_status, $replication_types;
887 $hour_factor = 3600 / $server_status['Uptime'];
890 * starttime calculation
892 $start_time = PMA_DBI_fetch_value(
893 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
896 <h3><?php
897 echo sprintf(
898 __('Network traffic since startup: %s'),
899 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
902 </h3>
905 <?php
906 echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'),
907 PMA_timespanFormat($server_status['Uptime']),
908 PMA_localisedDate($start_time)) . "\n";
910 </p>
912 <?php
913 if ($server_master_status || $server_slave_status) {
914 echo '<p class="notice">';
915 if ($server_master_status && $server_slave_status) {
916 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
917 } elseif ($server_master_status) {
918 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
919 } elseif ($server_slave_status) {
920 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
922 echo ' ';
923 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
924 echo '</p>';
927 /* if the server works as master or slave in replication process, display useful information */
928 if ($server_master_status || $server_slave_status)
931 <hr class="clearfloat" />
933 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
934 <?php
936 foreach ($replication_types as $type)
938 if (${"server_{$type}_status"}) {
939 PMA_replication_print_status_table($type);
942 unset($types);
946 <table id="serverstatustraffic" class="data noclick">
947 <thead>
948 <tr>
949 <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>
950 <th>&oslash; <?php echo __('per hour'); ?></th>
951 </tr>
952 </thead>
953 <tbody>
954 <tr class="odd">
955 <th class="name"><?php echo __('Received'); ?></th>
956 <td class="value"><?php echo
957 implode(' ',
958 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
959 <td class="value"><?php echo
960 implode(' ',
961 PMA_formatByteDown(
962 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
963 </tr>
964 <tr class="even">
965 <th class="name"><?php echo __('Sent'); ?></th>
966 <td class="value"><?php echo
967 implode(' ',
968 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
969 <td class="value"><?php echo
970 implode(' ',
971 PMA_formatByteDown(
972 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
973 </tr>
974 <tr class="odd">
975 <th class="name"><?php echo __('Total'); ?></th>
976 <td class="value"><?php echo
977 implode(' ',
978 PMA_formatByteDown(
979 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
980 ); ?></td>
981 <td class="value"><?php echo
982 implode(' ',
983 PMA_formatByteDown(
984 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
985 * $hour_factor, 3, 1)
986 ); ?></td>
987 </tr>
988 </tbody>
989 </table>
991 <table id="serverstatusconnections" class="data noclick">
992 <thead>
993 <tr>
994 <th colspan="2"><?php echo __('Connections'); ?></th>
995 <th>&oslash; <?php echo __('per hour'); ?></th>
996 <th>%</th>
997 </tr>
998 </thead>
999 <tbody>
1000 <tr class="odd">
1001 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
1002 <td class="value"><?php echo
1003 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
1004 <td class="value">--- </td>
1005 <td class="value">--- </td>
1006 </tr>
1007 <tr class="even">
1008 <th class="name"><?php echo __('Failed attempts'); ?></th>
1009 <td class="value"><?php echo
1010 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
1011 <td class="value"><?php echo
1012 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
1013 4, 2, true); ?></td>
1014 <td class="value"><?php echo
1015 $server_status['Connections'] > 0
1016 ? PMA_formatNumber(
1017 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
1018 0, 2, true) . '%'
1019 : '--- '; ?></td>
1020 </tr>
1021 <tr class="odd">
1022 <th class="name"><?php echo __('Aborted'); ?></th>
1023 <td class="value"><?php echo
1024 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
1025 <td class="value"><?php echo
1026 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
1027 4, 2, true); ?></td>
1028 <td class="value"><?php echo
1029 $server_status['Connections'] > 0
1030 ? PMA_formatNumber(
1031 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
1032 0, 2, true) . '%'
1033 : '--- '; ?></td>
1034 </tr>
1035 <tr class="even">
1036 <th class="name"><?php echo __('Total'); ?></th>
1037 <td class="value"><?php echo
1038 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
1039 <td class="value"><?php echo
1040 PMA_formatNumber($server_status['Connections'] * $hour_factor,
1041 4, 2); ?></td>
1042 <td class="value"><?php echo
1043 PMA_formatNumber(100, 0, 2); ?>%</td>
1044 </tr>
1045 </tbody>
1046 </table>
1047 <?php
1049 $url_params = array();
1051 if (! empty($_REQUEST['full'])) {
1052 $sql_query = 'SHOW FULL PROCESSLIST';
1053 $url_params['full'] = 1;
1054 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
1055 } else {
1056 $sql_query = 'SHOW PROCESSLIST';
1057 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
1059 $result = PMA_DBI_query($sql_query);
1062 * Displays the page
1065 <table id="tableprocesslist" class="data clearfloat noclick">
1066 <thead>
1067 <tr>
1068 <th><?php echo __('Processes'); ?></th>
1069 <th><?php echo __('ID'); ?></th>
1070 <th><?php echo __('User'); ?></th>
1071 <th><?php echo __('Host'); ?></th>
1072 <th><?php echo __('Database'); ?></th>
1073 <th><?php echo __('Command'); ?></th>
1074 <th><?php echo __('Time'); ?></th>
1075 <th><?php echo __('Status'); ?></th>
1076 <th><?php
1077 echo __('SQL query');
1078 if (! PMA_DRIZZLE) { ?>
1079 <a href="<?php echo $full_text_link; ?>"
1080 title="<?php echo empty($full) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>">
1081 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (empty($_REQUEST['full']) ? 'full' : 'partial'); ?>text.png"
1082 alt="<?php echo empty($_REQUEST['full']) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>" />
1083 </a>
1084 <?php } ?>
1085 </th>
1086 </tr>
1087 </thead>
1088 <tbody>
1089 <?php
1090 $odd_row = true;
1091 while ($process = PMA_DBI_fetch_assoc($result)) {
1092 if (PMA_DRIZZLE) {
1093 // Drizzle uses uppercase keys
1094 foreach ($process as $k => $v) {
1095 $k = $k !== 'DB'
1096 ? ucfirst(strtolower($k))
1097 : 'db';
1098 $process[$k] = $v;
1101 $url_params['kill'] = $process['Id'];
1102 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
1104 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
1105 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
1106 <td class="value"><?php echo $process['Id']; ?></td>
1107 <td><?php echo $process['User']; ?></td>
1108 <td><?php echo $process['Host']; ?></td>
1109 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
1110 <td><?php echo $process['Command']; ?></td>
1111 <td class="value"><?php echo $process['Time']; ?></td>
1112 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
1113 <td>
1114 <?php
1115 if (empty($process['Info'])) {
1116 echo '---';
1117 } else {
1118 if (empty($_REQUEST['full']) && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
1119 echo htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
1120 } else {
1121 echo PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
1125 </td>
1126 </tr>
1127 <?php
1128 $odd_row = ! $odd_row;
1131 </tbody>
1132 </table>
1133 <?php
1136 function printVariablesTable()
1138 global $server_status, $server_variables, $allocationMap, $links;
1140 * Messages are built using the message name
1142 $strShowStatus = array(
1143 'Aborted_clients' => __('The number of connections that were aborted because the client died without closing the connection properly.'),
1144 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
1145 '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.'),
1146 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
1147 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
1148 '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.'),
1149 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
1150 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
1151 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
1152 '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.'),
1153 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
1154 'Flush_commands' => __('The number of executed FLUSH statements.'),
1155 'Handler_commit' => __('The number of internal COMMIT statements.'),
1156 'Handler_delete' => __('The number of times a row was deleted from a table.'),
1157 '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.'),
1158 '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.'),
1159 '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.'),
1160 '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.'),
1161 '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.'),
1162 '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.'),
1163 '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.'),
1164 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
1165 'Handler_update' => __('The number of requests to update a row in a table.'),
1166 'Handler_write' => __('The number of requests to insert a row in a table.'),
1167 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
1168 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
1169 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
1170 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
1171 '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.'),
1172 '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.'),
1173 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
1174 '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.'),
1175 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
1176 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
1177 '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.'),
1178 '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.'),
1179 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
1180 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
1181 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
1182 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
1183 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
1184 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
1185 'Innodb_data_reads' => __('The total number of data reads.'),
1186 'Innodb_data_writes' => __('The total number of data writes.'),
1187 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
1188 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
1189 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
1190 '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.'),
1191 'Innodb_log_write_requests' => __('The number of log write requests.'),
1192 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
1193 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
1194 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
1195 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
1196 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
1197 'Innodb_pages_created' => __('The number of pages created.'),
1198 '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.'),
1199 'Innodb_pages_read' => __('The number of pages read.'),
1200 'Innodb_pages_written' => __('The number of pages written.'),
1201 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
1202 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
1203 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
1204 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
1205 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
1206 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
1207 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
1208 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
1209 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
1210 '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.'),
1211 '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.'),
1212 '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.'),
1213 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
1214 '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.'),
1215 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
1216 'Key_writes' => __('The number of physical writes of a key block to disk.'),
1217 '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.'),
1218 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
1219 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
1220 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
1221 'Open_files' => __('The number of files that are open.'),
1222 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
1223 'Open_tables' => __('The number of tables that are open.'),
1224 '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.'),
1225 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
1226 'Qcache_hits' => __('The number of cache hits.'),
1227 'Qcache_inserts' => __('The number of queries added to the cache.'),
1228 '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.'),
1229 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
1230 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
1231 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
1232 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
1233 '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.'),
1234 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
1235 '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.)'),
1236 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
1237 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
1238 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
1239 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
1240 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
1241 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
1242 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
1243 '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.'),
1244 'Sort_range' => __('The number of sorts that were done with ranges.'),
1245 'Sort_rows' => __('The number of sorted rows.'),
1246 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
1247 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
1248 '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.'),
1249 '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.'),
1250 'Threads_connected' => __('The number of currently open connections.'),
1251 '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.)'),
1252 'Threads_running' => __('The number of threads that are not sleeping.')
1256 * define some alerts
1258 // name => max value before alert
1259 $alerts = array(
1260 // lower is better
1261 // variable => max value
1262 'Aborted_clients' => 0,
1263 'Aborted_connects' => 0,
1265 'Binlog_cache_disk_use' => 0,
1267 'Created_tmp_disk_tables' => 0,
1269 'Handler_read_rnd' => 0,
1270 'Handler_read_rnd_next' => 0,
1272 'Innodb_buffer_pool_pages_dirty' => 0,
1273 'Innodb_buffer_pool_reads' => 0,
1274 'Innodb_buffer_pool_wait_free' => 0,
1275 'Innodb_log_waits' => 0,
1276 'Innodb_row_lock_time_avg' => 10, // ms
1277 'Innodb_row_lock_time_max' => 50, // ms
1278 'Innodb_row_lock_waits' => 0,
1280 'Slow_queries' => 0,
1281 'Delayed_errors' => 0,
1282 'Select_full_join' => 0,
1283 'Select_range_check' => 0,
1284 'Sort_merge_passes' => 0,
1285 'Opened_tables' => 0,
1286 'Table_locks_waited' => 0,
1287 'Qcache_lowmem_prunes' => 0,
1289 'Qcache_free_blocks' => $server_status['Qcache_total_blocks'] / 5,
1290 'Slow_launch_threads' => 0,
1292 // depends on Key_read_requests
1293 // normaly lower then 1:0.01
1294 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
1295 // depends on Key_write_requests
1296 // normaly nearly 1:1
1297 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
1299 'Key_buffer_fraction' => 0.5,
1301 // alert if more than 95% of thread cache is in use
1302 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
1304 // higher is better
1305 // variable => min value
1306 //'Handler read key' => '> ',
1310 <table class="data sortable noclick" id="serverstatusvariables">
1311 <col class="namecol" />
1312 <col class="valuecol" />
1313 <col class="descrcol" />
1314 <thead>
1315 <tr>
1316 <th><?php echo __('Variable'); ?></th>
1317 <th><?php echo __('Value'); ?></th>
1318 <th><?php echo __('Description'); ?></th>
1319 </tr>
1320 </thead>
1321 <tbody>
1322 <?php
1324 $odd_row = false;
1325 foreach ($server_status as $name => $value) {
1326 $odd_row = !$odd_row;
1328 <tr class="<?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_'.$allocationMap[$name]:''; ?>">
1329 <th class="name"><?php echo htmlspecialchars(str_replace('_',' ',$name)) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1330 </th>
1331 <td class="value"><span class="formatted"><?php
1332 if (isset($alerts[$name])) {
1333 if ($value > $alerts[$name]) {
1334 echo '<span class="attention">';
1335 } else {
1336 echo '<span class="allfine">';
1339 if ('%' === substr($name, -1, 1)) {
1340 echo PMA_formatNumber($value, 0, 2) . ' %';
1341 } elseif (strpos($name,'Uptime')!==FALSE) {
1342 echo PMA_timespanFormat($value);
1343 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1344 echo PMA_formatNumber($value, 3, 1);
1345 } elseif (is_numeric($value) && $value == (int) $value) {
1346 echo PMA_formatNumber($value, 3, 0);
1347 } elseif (is_numeric($value)) {
1348 echo PMA_formatNumber($value, 3, 1);
1349 } else {
1350 echo htmlspecialchars($value);
1352 if (isset($alerts[$name])) {
1353 echo '</span>';
1355 ?></span><span style="display:none;" class="original"><?php echo $value; ?></span>
1356 </td>
1357 <td class="descr">
1358 <?php
1359 if (isset($strShowStatus[$name ])) {
1360 echo $strShowStatus[$name];
1363 if (isset($links[$name])) {
1364 foreach ($links[$name] as $link_name => $link_url) {
1365 if ('doc' == $link_name) {
1366 echo PMA_showMySQLDocu($link_url, $link_url);
1367 } else {
1368 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1369 "\n";
1372 unset($link_url, $link_name);
1375 </td>
1376 </tr>
1377 <?php
1380 </tbody>
1381 </table>
1382 <?php
1385 function printMonitor()
1387 global $server_status, $server_db_isLocal;
1389 <div class="monitorLinks">
1390 <a href="#pauseCharts">
1391 <img src="themes/dot.gif" class="icon ic_play" alt="" />
1392 <?php echo __('Start Monitor'); ?>
1393 </a>
1394 <a href="#settingsPopup" rel="popupLink" style="display:none;">
1395 <img src="themes/dot.gif" class="icon ic_s_cog" alt="" />
1396 <?php echo __('Settings'); ?>
1397 </a>
1398 <a href="#monitorInstructionsDialog">
1399 <img src="themes/dot.gif" class="icon ic_b_help" alt="" />
1400 <?php echo __('Instructions/Setup'); ?>
1401 </a>
1402 <a href="#endChartEditMode" style="display:none;">
1403 <img src="themes/dot.gif" class="icon ic_s_okay" alt="" />
1404 <?php echo __('Done rearranging/editing charts'); ?>
1405 </a>
1406 </div>
1408 <div class="popupContent settingsPopup">
1409 <a href="#addNewChart">
1410 <img src="themes/dot.gif" class="icon ic_b_chart" alt="" />
1411 <?php echo __('Add chart'); ?>
1412 </a>
1413 <a href="#rearrangeCharts"><img class="icon ic_b_tblops" src="themes/dot.gif" width="16" height="16" alt=""> <?php echo __('Rearrange/edit charts'); ?></a>
1414 <div class="clearfloat paddingtop"></div>
1415 <div class="floatleft">
1416 <?php echo __('Refresh rate').'<br />'; refreshList('gridChartRefresh', 5, Array(2,3,4,5,10,20,40,60,120,300,600,1200)); ?><br>
1417 </div>
1418 <div class="floatleft">
1419 <?php echo __('Chart columns'); ?> <br />
1420 <select name="chartColumns">
1421 <option>1</option>
1422 <option>2</option>
1423 <option>3</option>
1424 <option>4</option>
1425 <option>5</option>
1426 <option>6</option>
1427 <option>7</option>
1428 <option>8</option>
1429 <option>9</option>
1430 <option>10</option>
1431 </select>
1432 </div>
1434 <div class="clearfloat paddingtop">
1435 <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/>
1436 <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>
1437 </div>
1438 </div>
1440 <div id="monitorInstructionsDialog" title="<?php echo __('Monitor Instructions'); ?>" style="display:none;">
1441 <?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%'); ?>
1442 <?php if(PMA_MYSQL_INT_VERSION < 50106) { ?>
1444 <img class="icon ic_s_attention" src="themes/dot.gif" alt="">
1445 <?php
1446 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.');
1448 </p>
1449 <?php
1450 } else {
1452 <p></p>
1453 <img class="ajaxIcon" src="<?php echo $GLOBALS['pmaThemeImage']; ?>ajax_clock_small.gif" alt="Loading">
1454 <div class="ajaxContent"></div>
1455 <div class="monitorUse" style="display:none;">
1456 <p></p>
1457 <?php
1458 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>');
1461 <img class="icon ic_s_attention" src="themes/dot.gif" alt="">
1462 <?php
1463 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.');
1465 </p>
1466 </div>
1467 <?php } ?>
1468 </div>
1470 <div id="addChartDialog" title="Add chart" style="display:none;">
1471 <div id="tabGridVariables">
1472 <p><input type="text" name="chartTitle" value="<?php echo __('Chart Title'); ?>" /></p>
1473 <?php if ($server_db_isLocal) { ?>
1474 <input type="radio" name="chartType" value="cpu" id="chartCPU">
1475 <label for="chartCPU"><?php echo __('CPU Usage'); ?></label><br/>
1477 <input type="radio" name="chartType" value="memory" id="chartMemory">
1478 <label for="chartMemory"><?php echo __('Memory Usage'); ?></label><br/>
1480 <input type="radio" name="chartType" value="swap" id="chartSwap">
1481 <label for="chartSwap"><?php echo __('Swap Usage'); ?></label><br/>
1482 <?php } ?>
1483 <input type="radio" name="chartType" value="variable" id="chartStatusVar" checked="checked">
1484 <label for="chartStatusVar"><?php echo __('Status variable(s)'); ?></label><br/>
1485 <div id="chartVariableSettings">
1486 <label for="chartSeries"><?php echo __('Select series:'); ?></label><br>
1487 <select id="chartSeries" name="varChartList" size="1">
1488 <option><?php echo __('Commonly monitored'); ?></option>
1489 <option>Processes</option>
1490 <option>Questions</option>
1491 <option>Connections</option>
1492 <option>Bytes_sent</option>
1493 <option>Bytes_received</option>
1494 <option>Threads_connected</option>
1495 <option>Created_tmp_disk_tables</option>
1496 <option>Handler_read_first</option>
1497 <option>Innodb_buffer_pool_wait_free</option>
1498 <option>Key_reads</option>
1499 <option>Open_tables</option>
1500 <option>Select_full_join</option>
1501 <option>Slow_queries</option>
1502 </select><br>
1503 <label for="variableInput"><?php echo __('or type variable name:'); ?> </label>
1504 <input type="text" name="variableInput" id="variableInput" />
1505 <p></p>
1506 <input type="checkbox" name="differentialValue" id="differentialValue" value="differential" checked="checked" />
1507 <label for="differentialValue"><?php echo __('Display as differential value'); ?></label><br>
1508 <input type="checkbox" id="useDivisor" name="useDivisor" value="1" />
1509 <label for="useDivisor"><?php echo __('Apply a divisor'); ?></label>
1510 <span class="divisorInput" style="display:none;">
1511 <input type="text" name="valueDivisor" size="4" value="1">
1512 (<a href="#kibDivisor"><?php echo __('KiB'); ?></a>, <a href="#mibDivisor"><?php echo __('MiB'); ?></a>)
1513 </span><br>
1515 <input type="checkbox" id="useUnit" name="useUnit" value="1" />
1516 <label for="useUnit"><?php echo __('Append unit to data values'); ?></label>
1518 <span class="unitInput" style="display:none;">
1519 <input type="text" name="valueUnit" size="4" value="">
1520 </span>
1522 <a href="#submitAddSeries"><b><?php echo __('Add this series'); ?></b></a>
1523 <span id="clearSeriesLink" style="display:none;">
1524 | <a href="#submitClearSeries"><?php echo __('Clear series'); ?></a>
1525 </span>
1526 </p>
1527 <?php echo __('Series in Chart:'); ?><br/>
1528 <span id="seriesPreview">
1529 <i><?php echo __('None'); ?></i>
1530 </span>
1531 </div>
1532 </div>
1533 </div>
1535 <!-- For generic use -->
1536 <div id="emptyDialog" title="Dialog" style="display:none;">
1537 </div>
1539 <div id="logAnalyseDialog" title="<?php echo __('Log statistics'); ?>" style="display:none;">
1540 <p> <?php echo __('Selected time range:'); ?>
1541 <input type="text" name="dateStart" class="datetimefield" value="" /> -
1542 <input type="text" name="dateEnd" class="datetimefield" value="" /></p>
1543 <input type="checkbox" id="limitTypes" value="1" checked="checked" />
1544 <label for="limitTypes">
1545 <?php echo __('Only retrieve SELECT,INSERT,UPDATE and DELETE Statements'); ?>
1546 </label>
1547 <br/>
1548 <input type="checkbox" id="removeVariables" value="1" checked="checked" />
1549 <label for="removeVariables">
1550 <?php echo __('Remove variable data in INSERT statements for better grouping'); ?>
1551 </label>
1553 <?php echo __('<p>Choose from which log you want the statistics to be generated from.</p> Results are grouped by query text.'); ?>
1554 </div>
1556 <div id="queryAnalyzerDialog" title="<?php echo __('Query analyzer'); ?>" style="display:none;">
1557 <textarea id="sqlquery"> </textarea>
1558 <p></p>
1559 <div class="placeHolder"></div>
1560 </div>
1562 <table border="0" class="clearfloat" id="chartGrid">
1564 </table>
1565 <div id="logTable">
1566 <br/>
1567 </div>
1569 <script type="text/javascript">
1570 variableNames = [ <?php
1571 $i=0;
1572 foreach ($server_status as $name=>$value) {
1573 if (is_numeric($value)) {
1574 if ($i++ > 0) echo ", ";
1575 echo "'".$name."'";
1578 ?> ];
1579 </script>
1580 <?php
1583 /* Builds a <select> list for refresh rates */
1584 function refreshList($name,$defaultRate=5, $refreshRates=Array(1, 2, 5, 10, 20, 40, 60, 120, 300, 600))
1587 <select name="<?php echo $name; ?>">
1588 <?php
1589 foreach ($refreshRates as $rate) {
1590 $selected = ($rate == $defaultRate)?' selected="selected"':'';
1592 if ($rate<60)
1593 echo '<option value="'.$rate.'"'.$selected.'>'.sprintf(_ngettext('%d second', '%d seconds', $rate), $rate).'</option>';
1594 else
1595 echo '<option value="'.$rate.'"'.$selected.'>'.sprintf(_ngettext('%d minute', '%d minutes', $rate/60), $rate/60).'</option>';
1598 </select>
1599 <?php
1603 * cleanup of some deprecated values
1605 * @param array &$server_status
1607 function cleanDeprecated(&$server_status)
1609 $deprecated = array(
1610 'Com_prepare_sql' => 'Com_stmt_prepare',
1611 'Com_execute_sql' => 'Com_stmt_execute',
1612 'Com_dealloc_sql' => 'Com_stmt_close',
1615 foreach ($deprecated as $old => $new) {
1616 if (isset($server_status[$old]) && isset($server_status[$new])) {
1617 unset($server_status[$old]);
1623 * Sends the footer
1625 require './libraries/footer.inc.php';