Add some missing @return tags in tests
[phpmyadmin.git] / server_status.php
blob9eb493c4939607cabd7a2b8ac218951e22c1bcac
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * displays status variables with descriptions and some hints an optmizing
5 * + reset status variables
7 * @package phpMyAdmin
8 */
10 /**
11 * no need for variables importing
12 * @ignore
14 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
15 define('PMA_NO_VARIABLES_IMPORT', true);
18 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true)
19 $GLOBALS['is_header_sent'] = true;
21 require_once './libraries/common.inc.php';
23 /**
24 * Ajax request
27 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
28 // Send with correct charset
29 header('Content-Type: text/html; charset=UTF-8');
31 // real-time charting data
32 if (isset($_REQUEST['chart_data'])) {
33 switch($_REQUEST['type']) {
34 // Process and Connections realtime chart
35 case 'proc':
36 $c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1);
37 $result = PMA_DBI_query('SHOW PROCESSLIST');
38 $num_procs = PMA_DBI_num_rows($result);
40 $ret = array(
41 'x' => microtime(true)*1000,
42 'y_proc' => $num_procs,
43 'y_conn' => $c['Connections']
46 exit(json_encode($ret));
48 // Query realtime chart
49 case 'queries':
50 $queries = PMA_DBI_fetch_result(
51 "SHOW GLOBAL STATUS
52 WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions')
53 AND Value > 0'", 0, 1);
54 cleanDeprecated($queries);
55 // admin commands are not queries
56 unset($queries['Com_admin_commands']);
57 $questions = $queries['Questions'];
58 unset($queries['Questions']);
60 //$sum=array_sum($queries);
61 $ret = array(
62 'x' => microtime(true)*1000,
63 'y' => $questions,
64 'pointInfo' => $queries
67 exit(json_encode($ret));
69 // Traffic realtime chart
70 case 'traffic':
71 $traffic = PMA_DBI_fetch_result(
72 "SHOW GLOBAL STATUS
73 WHERE Variable_name = 'Bytes_received'
74 OR Variable_name = 'Bytes_sent'", 0, 1);
76 $ret = array(
77 'x' => microtime(true)*1000,
78 'y_sent' => $traffic['Bytes_sent'],
79 'y_received' => $traffic['Bytes_received']
82 exit(json_encode($ret));
84 // Data for the monitor
85 case 'chartgrid':
86 $ret = json_decode($_REQUEST['requiredData'], true);
87 $statusVars = array();
88 $serverVars = array();
89 $sysinfo = $cpuload = $memory = 0;
90 $pName = '';
92 /* Accumulate all required variables and data */
93 // For each chart
94 foreach ($ret as $chart_id => $chartNodes) {
95 // For each data series
96 foreach ($chartNodes as $node_id => $nodeDataPoints) {
97 // For each data point in the series (usually just 1)
98 foreach ($nodeDataPoints as $point_id => $dataPoint) {
99 $pName = $dataPoint['name'];
101 switch ($dataPoint['type']) {
102 /* We only collect the status and server variables here to
103 * read them all in one query, and only afterwards assign them.
104 * Also do some white list filtering on the names
106 case 'servervar':
107 if (!preg_match('/[^a-zA-Z_]+/', $pName))
108 $serverVars[] = $pName;
109 break;
111 case 'statusvar':
112 if (!preg_match('/[^a-zA-Z_]+/', $pName))
113 $statusVars[] = $pName;
114 break;
116 case 'proc':
117 $result = PMA_DBI_query('SHOW PROCESSLIST');
118 $ret[$chart_id][$node_id][$point_id]['value'] = PMA_DBI_num_rows($result);
119 break;
121 case 'cpu':
122 if (!$sysinfo) {
123 require_once('libraries/sysinfo.lib.php');
124 $sysinfo = getSysInfo();
126 if (!$cpuload)
127 $cpuload = $sysinfo->loadavg();
129 if (PHP_OS == 'Linux') {
130 $ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle'];
131 $ret[$chart_id][$node_id][$point_id]['busy'] = $cpuload['busy'];
132 } else
133 $ret[$chart_id][$node_id][$point_id]['value'] = $cpuload['loadavg'];
135 break;
137 case 'memory':
138 if (!$sysinfo) {
139 require_once('libraries/sysinfo.lib.php');
140 $sysinfo = getSysInfo();
142 if (!$memory)
143 $memory = $sysinfo->memory();
145 $ret[$chart_id][$node_id][$point_id]['value'] = $memory[$pName];
146 break;
152 // Retrieve all required status variables
153 if (count($statusVars)) {
154 $statusVarValues = PMA_DBI_fetch_result(
155 "SHOW GLOBAL STATUS
156 WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1);
157 } else {
158 $statusVarValues = array();
161 // Retrieve all required server variables
162 if (count($serverVars)) {
163 $serverVarValues = PMA_DBI_fetch_result(
164 "SHOW GLOBAL VARIABLES
165 WHERE Variable_name='" . implode("' OR Variable_name='", $serverVars) . "'", 0, 1);
166 } else {
167 $serverVarValues = array();
170 // ...and now assign them
171 foreach ($ret as $chart_id => $chartNodes) {
172 foreach ($chartNodes as $node_id => $nodeDataPoints) {
173 foreach ($nodeDataPoints as $point_id => $dataPoint) {
174 switch($dataPoint['type']) {
175 case 'statusvar':
176 $ret[$chart_id][$node_id][$point_id]['value'] = $statusVarValues[$dataPoint['name']];
177 break;
178 case 'servervar':
179 $ret[$chart_id][$node_id][$point_id]['value'] = $serverVarValues[$dataPoint['name']];
180 break;
186 $ret['x'] = microtime(true)*1000;
188 exit(json_encode($ret));
192 if (isset($_REQUEST['log_data'])) {
193 if(PMA_MYSQL_INT_VERSION < 50106) exit('""');
195 $start = intval($_REQUEST['time_start']);
196 $end = intval($_REQUEST['time_end']);
198 if ($_REQUEST['type'] == 'slow') {
199 $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, '.
200 'SUM(rows_sent) AS rows_sent, SUM(rows_examined) AS rows_examined, db, sql_text, COUNT(sql_text) AS \'#\' '.
201 'FROM `mysql`.`slow_log` WHERE start_time > FROM_UNIXTIME(' . $start . ') '.
202 'AND start_time < FROM_UNIXTIME(' . $end . ') GROUP BY sql_text';
204 $result = PMA_DBI_try_query($q);
206 $return = array('rows' => array(), 'sum' => array());
207 $type = '';
209 while ($row = PMA_DBI_fetch_assoc($result)) {
210 $type = strtolower(substr($row['sql_text'], 0, strpos($row['sql_text'], ' ')));
212 switch($type) {
213 case 'insert':
214 case 'update':
215 // Cut off big inserts and updates, but append byte count therefor
216 if(strlen($row['sql_text']) > 220)
217 $row['sql_text'] = substr($row['sql_text'], 0, 200) . '... [' .
218 implode(' ', PMA_formatByteDown(strlen($row['sql_text']), 2, 2)) . ']';
220 break;
221 default:
222 break;
225 if(!isset($return['sum'][$type])) $return['sum'][$type] = 0;
226 $return['sum'][$type] += $row['#'];
227 $return['rows'][] = $row;
230 $return['sum']['TOTAL'] = array_sum($return['sum']);
231 $return['numRows'] = count($return['rows']);
233 PMA_DBI_free_result($result);
235 exit(json_encode($return));
238 if($_REQUEST['type'] == 'general') {
239 $limitTypes = (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes'])
240 ? 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ' : '';
242 $q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, server_id, argument, count(argument) as \'#\' '.
243 'FROM `mysql`.`general_log` WHERE command_type=\'Query\' '.
244 'AND event_time > FROM_UNIXTIME(' . $start . ') AND event_time < FROM_UNIXTIME(' . $end . ') '.
245 $limitTypes . 'GROUP by argument'; // HAVING count > 1';
247 $result = PMA_DBI_try_query($q);
249 $return = array('rows' => array(), 'sum' => array());
250 $type = '';
251 $insertTables = array();
252 $insertTablesFirst = -1;
253 $i = 0;
254 $removeVars = isset($_REQUEST['removeVariables']) && $_REQUEST['removeVariables'];
256 while ($row = PMA_DBI_fetch_assoc($result)) {
257 preg_match('/^(\w+)\s/', $row['argument'], $match);
258 $type = strtolower($match[1]);
260 if(!isset($return['sum'][$type])) $return['sum'][$type] = 0;
261 $return['sum'][$type] += $row['#'];
263 switch($type) {
264 case 'insert':
265 // Group inserts if selected
266 if($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i', $row['argument'], $matches)) {
267 $insertTables[$matches[2]]++;
268 if ($insertTables[$matches[2]] > 1) {
269 $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
271 // Add a ... to the end of this query to indicate that there's been other queries
272 if($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.')
273 $return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
275 // Group this value, thus do not add to the result list
276 continue 2;
277 } else {
278 $insertTablesFirst = $i;
279 $insertTables[$matches[2]] += $row['#'] - 1;
282 // No break here
284 case 'update':
285 // Cut off big inserts and updates, but append byte count therefor
286 if(strlen($row['argument']) > 220)
287 $row['argument'] = substr($row['argument'], 0, 200) . '... [' .
288 implode(' ', PMA_formatByteDown(strlen($row['argument'])), 2, 2) . ']';
290 break;
292 default: break;
295 $return['rows'][] = $row;
296 $i++;
299 $return['sum']['TOTAL'] = array_sum($return['sum']);
300 $return['numRows'] = count($return['rows']);
302 PMA_DBI_free_result($result);
304 exit(json_encode($return));
308 if (isset($_REQUEST['logging_vars'])) {
309 if(isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) {
310 $value = PMA_sqlAddslashes($_REQUEST['varValue']);
311 if(!is_numeric($value)) $value="'" . $value . "'";
313 if(! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName']))
314 PMA_DBI_query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value);
318 $loggingVars = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES WHERE Variable_name IN ("general_log","slow_query_log","long_query_time","log_output")', 0, 1);
319 exit(json_encode($loggingVars));
322 if(isset($_REQUEST['query_analyzer'])) {
323 $return = array();
325 if(strlen($_REQUEST['database']))
326 PMA_DBI_select_db($_REQUEST['database']);
328 if ($profiling = PMA_profilingSupported())
329 PMA_DBI_query('SET PROFILING=1;');
331 // Do not cache query
332 $query = preg_replace('/^(\s*SELECT)/i', '\\1 SQL_NO_CACHE', $_REQUEST['query']);
334 $result = PMA_DBI_try_query($query);
335 $return['affectedRows'] = $GLOBALS['cached_affected_rows'];
337 $result = PMA_DBI_try_query('EXPLAIN ' . $query);
338 while ($row = PMA_DBI_fetch_assoc($result)) {
339 $return['explain'][] = $row;
342 // In case an error happened
343 $return['error'] = PMA_DBI_getError();
345 PMA_DBI_free_result($result);
347 if($profiling) {
348 $return['profiling'] = array();
349 $result = PMA_DBI_try_query('SELECT seq,state,duration FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID=1 ORDER BY seq');
350 while ($row = PMA_DBI_fetch_assoc($result)) {
351 $return['profiling'][]= $row;
353 PMA_DBI_free_result($result);
356 exit(json_encode($return));
359 if(isset($_REQUEST['advisor'])) {
360 include('libraries/Advisor.class.php');
361 $advisor = new Advisor();
362 exit(json_encode($advisor->run()));
368 * Replication library
370 require './libraries/replication.inc.php';
371 require_once './libraries/replication_gui.lib.php';
374 * JS Includes
377 $GLOBALS['js_include'][] = 'server_status.js';
378 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
379 $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
380 $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
381 // Charting
382 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
383 /* Files required for chart exporting */
384 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
385 /* < IE 9 doesn't support canvas natively */
386 if(PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
387 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
389 $GLOBALS['js_include'][] = 'canvg/canvg.js';
392 * flush status variables if requested
394 if (isset($_REQUEST['flush'])) {
395 $_flush_commands = array(
396 'STATUS',
397 'TABLES',
398 'QUERY CACHE',
401 if (in_array($_REQUEST['flush'], $_flush_commands)) {
402 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
404 unset($_flush_commands);
408 * Kills a selected process
410 if (!empty($_REQUEST['kill'])) {
411 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
412 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
413 } else {
414 $message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
416 $message->addParam($_REQUEST['kill']);
417 //$message->display();
423 * get status from server
425 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
428 * for some calculations we require also some server settings
430 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
433 * cleanup of some deprecated values
435 cleanDeprecated($server_status);
438 * calculate some values
440 // Key_buffer_fraction
441 if (isset($server_status['Key_blocks_unused'])
442 && isset($server_variables['key_cache_block_size'])
443 && isset($server_variables['key_buffer_size'])) {
444 $server_status['Key_buffer_fraction_%'] =
446 - $server_status['Key_blocks_unused']
447 * $server_variables['key_cache_block_size']
448 / $server_variables['key_buffer_size']
449 * 100;
450 } elseif (isset($server_status['Key_blocks_used'])
451 && isset($server_variables['key_buffer_size'])) {
452 $server_status['Key_buffer_fraction_%'] =
453 $server_status['Key_blocks_used']
454 * 1024
455 / $server_variables['key_buffer_size'];
458 // Ratio for key read/write
459 if (isset($server_status['Key_writes'])
460 && isset($server_status['Key_write_requests'])
461 && $server_status['Key_write_requests'] > 0) {
462 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
465 if (isset($server_status['Key_reads'])
466 && isset($server_status['Key_read_requests'])
467 && $server_status['Key_read_requests'] > 0) {
468 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
471 // Threads_cache_hitrate
472 if (isset($server_status['Threads_created'])
473 && isset($server_status['Connections'])
474 && $server_status['Connections'] > 0) {
476 $server_status['Threads_cache_hitrate_%'] =
477 100 - $server_status['Threads_created'] / $server_status['Connections'] * 100;
481 * split variables in sections
483 $allocations = array(
484 // variable name => section
485 // variable names match when they begin with the given string
487 'Com_' => 'com',
488 'Innodb_' => 'innodb',
489 'Ndb_' => 'ndb',
490 'Handler_' => 'handler',
491 'Qcache_' => 'qcache',
492 'Threads_' => 'threads',
493 'Slow_launch_threads' => 'threads',
495 'Binlog_cache_' => 'binlog_cache',
496 'Created_tmp_' => 'created_tmp',
497 'Key_' => 'key',
499 'Delayed_' => 'delayed',
500 'Not_flushed_delayed_rows' => 'delayed',
502 'Flush_commands' => 'query',
503 'Last_query_cost' => 'query',
504 'Slow_queries' => 'query',
505 'Queries' => 'query',
506 'Prepared_stmt_count' => 'query',
508 'Select_' => 'select',
509 'Sort_' => 'sort',
511 'Open_tables' => 'table',
512 'Opened_tables' => 'table',
513 'Open_table_definitions' => 'table',
514 'Opened_table_definitions' => 'table',
515 'Table_locks_' => 'table',
517 'Rpl_status' => 'repl',
518 'Slave_' => 'repl',
520 'Tc_' => 'tc',
522 'Ssl_' => 'ssl',
524 'Open_files' => 'files',
525 'Open_streams' => 'files',
526 'Opened_files' => 'files',
529 $sections = array(
530 // section => section name (description)
531 'com' => 'Com',
532 'query' => __('SQL query'),
533 'innodb' => 'InnoDB',
534 'ndb' => 'NDB',
535 'handler' => __('Handler'),
536 'qcache' => __('Query cache'),
537 'threads' => __('Threads'),
538 'binlog_cache' => __('Binary log'),
539 'created_tmp' => __('Temporary data'),
540 'delayed' => __('Delayed inserts'),
541 'key' => __('Key cache'),
542 'select' => __('Joins'),
543 'repl' => __('Replication'),
544 'sort' => __('Sorting'),
545 'table' => __('Tables'),
546 'tc' => __('Transaction coordinator'),
547 'files' => __('Files'),
548 'ssl' => 'SSL',
552 * define some needfull links/commands
554 // variable or section name => (name => url)
555 $links = array();
557 $links['table'][__('Flush (close) all tables')]
558 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
559 $links['table'][__('Show open tables')]
560 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
561 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
563 if ($server_master_status) {
564 $links['repl'][__('Show slave hosts')]
565 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
566 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
567 $links['repl'][__('Show master status')] = '#replication_master';
569 if ($server_slave_status) {
570 $links['repl'][__('Show slave status')] = '#replication_slave';
573 $links['repl']['doc'] = 'replication';
575 $links['qcache'][__('Flush query cache')]
576 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
577 PMA_generate_common_url();
578 $links['qcache']['doc'] = 'query_cache';
580 //$links['threads'][__('Show processes')]
581 // = 'server_processlist.php?' . PMA_generate_common_url();
582 $links['threads']['doc'] = 'mysql_threads';
584 $links['key']['doc'] = 'myisam_key_cache';
586 $links['binlog_cache']['doc'] = 'binary_log';
588 $links['Slow_queries']['doc'] = 'slow_query_log';
590 $links['innodb'][__('Variables')]
591 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
592 $links['innodb'][__('InnoDB Status')]
593 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
594 PMA_generate_common_url();
595 $links['innodb']['doc'] = 'innodb';
598 // Variable to contain all com_ variables
599 $used_queries = array();
601 // Variable to map variable names to their respective section name (used for js category filtering)
602 $allocationMap = array();
604 // sort vars into arrays
605 foreach ($server_status as $name => $value) {
606 foreach ($allocations as $filter => $section) {
607 if (strpos($name, $filter) !== false) {
608 $allocationMap[$name] = $section;
609 if ($section == 'com' && $value > 0) $used_queries[$name] = $value;
610 break; // Only exits inner loop
615 if(PMA_DRIZZLE) {
616 $used_queries = PMA_DBI_fetch_result('SELECT * FROM data_dictionary.global_statements', 0, 1);
617 unset($used_queries['admin_commands']);
618 } else {
619 // admin commands are not queries (e.g. they include COM_PING, which is excluded from $server_status['Questions'])
620 unset($used_queries['Com_admin_commands']);
623 /* Ajax request refresh */
624 if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
625 switch($_REQUEST['show']) {
626 case 'query_statistics':
627 printQueryStatistics();
628 exit();
629 case 'server_traffic':
630 printServerTraffic();
631 exit();
632 case 'variables_table':
633 // Prints the variables table
634 printVariablesTable();
635 exit();
637 default:
638 break;
642 $server_db_isLocal = strtolower($cfg['Server']['host']) == 'localhost'
643 || $cfg['Server']['host'] == '127.0.0.1'
644 || $cfg['Server']['host'] == '::1';
646 PMA_AddJSCode('pma_token = \'' . $_SESSION[' PMA_token '] . "';\n" .
647 'url_query = \'' . str_replace('&amp;', '&', PMA_generate_common_url($db)) . "';\n" .
648 'server_time_diff = new Date().getTime() - ' . (microtime(true)*1000) . ";\n" .
649 'server_os = \'' . PHP_OS . "';\n" .
650 'is_superuser = ' . (PMA_isSuperuser() ? 'true' : 'false') . ";\n" .
651 'server_db_isLocal = ' . ($server_db_isLocal ? 'true' : 'false') . ";\n" .
652 'profiling_docu = \'' . PMA_showMySQLDocu('general-thread-states', 'general-thread-states') . "';\n" .
653 'explain_docu = \'' . PMA_showMySQLDocu('explain-output', 'explain-output') . ";'\n");
656 * start output
660 * Does the common work
662 require './libraries/server_common.inc.php';
667 * Displays the links
669 require './libraries/server_links.inc.php';
672 <div id="serverstatus">
673 <h2><?php
675 * Displays the sub-page heading
677 if ($GLOBALS['cfg']['MainPageIconic']) {
678 echo '<img class="icon ic_s_status" src="themes/dot.gif" width="16" height="16" alt="" />';
681 echo __('Runtime Information');
683 ?></h2>
684 <div id="serverStatusTabs">
685 <ul>
686 <li><a href="#statustabs_traffic"><?php echo __('Server'); ?></a></li>
687 <li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
688 <li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
689 <li><a href="#statustabs_charting"><?php echo __('Monitor'); ?></a></li>
690 <li><a href="#statustabs_advisor"><?php echo __('Advisor'); ?></a></li>
691 </ul>
693 <div id="statustabs_traffic">
694 <div class="buttonlinks">
695 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&amp;' . PMA_generate_common_url(); ?>" >
696 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
697 <?php echo __('Refresh'); ?>
698 </a>
699 <span class="refreshList" style="display:none;">
700 <label for="id_trafficChartRefresh"><?php echo __('Refresh rate: '); ?></label>
701 <?php refreshList('trafficChartRefresh'); ?>
702 </span>
704 <a class="tabChart livetrafficLink" href="#">
705 <?php echo __('Live traffic chart'); ?>
706 </a>
707 <a class="tabChart liveconnectionsLink" href="#">
708 <?php echo __('Live conn./process chart'); ?>
709 </a>
710 </div>
711 <div class="tabInnerContent">
712 <?php printServerTraffic(); ?>
713 </div>
714 </div>
715 <div id="statustabs_queries">
716 <div class="buttonlinks">
717 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
718 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
719 <?php echo __('Refresh'); ?>
720 </a>
721 <span class="refreshList" style="display:none;">
722 <label for="id_queryChartRefresh"><?php echo __('Refresh rate: '); ?></label>
723 <?php refreshList('queryChartRefresh'); ?>
724 </span>
725 <a class="tabChart livequeriesLink" href="#">
726 <?php echo __('Live query chart'); ?>
727 </a>
728 </div>
729 <div class="tabInnerContent">
730 <?php printQueryStatistics(); ?>
731 </div>
732 </div>
733 <div id="statustabs_allvars">
734 <fieldset id="tableFilter">
735 <div class="buttonlinks">
736 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
737 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
738 <?php echo __('Refresh'); ?>
739 </a>
740 </div>
741 <legend>Filters</legend>
742 <div class="formelement">
743 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
744 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
745 </div>
746 <div class="formelement">
747 <input type="checkbox" name="filterAlert" id="filterAlert" />
748 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
749 </div>
750 <div class="formelement">
751 <select id="filterCategory" name="filterCategory">
752 <option value=''><?php echo __('Filter by category...'); ?></option>
753 <?php
754 foreach ($sections as $section_id => $section_name) {
756 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
757 <?php
761 </select>
762 </div>
763 <div class="formelement">
764 <input type="checkbox" name="dontFormat" id="dontFormat" />
765 <label for="dontFormat"><?php echo __('Show unformatted values'); ?></label>
766 </div>
767 </fieldset>
768 <div id="linkSuggestions" class="defaultLinks" style="display:none">
769 <p class="notice"><?php echo __('Related links:'); ?>
770 <?php
771 foreach ($links as $section_name => $section_links) {
772 echo '<span class="status_' . $section_name . '"> ';
773 $i=0;
774 foreach ($section_links as $link_name => $link_url) {
775 if ($i > 0) echo ', ';
776 if ('doc' == $link_name) {
777 echo PMA_showMySQLDocu($link_url, $link_url);
778 } else {
779 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
781 $i++;
783 echo '</span>';
785 unset($link_url, $link_name, $i);
787 </p>
788 </div>
789 <div class="tabInnerContent">
790 <?php printVariablesTable(); ?>
791 </div>
792 </div>
794 <div id="statustabs_charting">
795 <?php printMonitor(); ?>
796 </div>
798 <div id="statustabs_advisor">
799 <div class="tabLinks">
800 <img src="themes/dot.gif" class="icon ic_play" alt="" /> <a href="#startAnalyzer"><?php echo __('Run analyzer'); ?></a>
801 <img src="themes/dot.gif" class="icon ic_b_help" alt="" /> <a href="#openAdvisorInstructions"><?php echo __('Instructions'); ?></a>
802 </div>
803 <div class="tabInnerContent clearfloat">
804 </div>
805 <div id="advisorInstructionsDialog" style="display:none;">
806 <?php
807 echo '<p>';
808 echo __('The Advisor system can provide recommendations on server variables by analyzing the server status variables.');
809 echo '</p> <p>';
810 echo __('Do note however that this system provides recommendations based on simple calculations and by rule of thumb which may not necessarily apply to your system.');
811 echo '</p> <p>';
812 echo __('Prior to changing any of the configuration, be sure to know what you are changing (by reading the documentation) and how to undo the change. Wrong tuning can have a very negative effect on performance.');
813 echo '</p> <p>';
814 echo __('The best way to tune your system would be to change only one setting at a time, observe or benchmark your database, and undo the change if there was no clearly measurable improvement.');
815 echo '</p>';
817 </div>
818 </div>
819 </div>
820 </div>
822 <?php
824 function printQueryStatistics()
826 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
828 $hour_factor = 3600 / $server_status['Uptime'];
830 $total_queries = array_sum($used_queries);
833 <h3 id="serverstatusqueries">
834 <?php
835 /* l10n: Questions is the name of a MySQL Status variable */
836 echo sprintf(__('Questions since startup: %s'), PMA_formatNumber($total_queries, 0)) . ' ';
837 echo PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_Questions');
839 <br />
840 <span>
841 <?php
842 echo '&oslash; ' . __('per hour') . ': ';
843 echo PMA_formatNumber($total_queries * $hour_factor, 0);
844 echo '<br />';
846 echo '&oslash; ' . __('per minute') . ': ';
847 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
848 echo '<br />';
850 if ($total_queries / $server_status['Uptime'] >= 1) {
851 echo '&oslash; ' . __('per second') . ': ';
852 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
855 </span>
856 </h3>
857 <?php
859 // reverse sort by value to show most used statements first
860 arsort($used_queries);
862 $odd_row = true;
863 $count_displayed_rows = 0;
864 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
868 <table id="serverstatusqueriesdetails" class="data sortable noclick">
869 <col class="namecol" />
870 <col class="valuecol" span="3" />
871 <thead>
872 <tr><th><?php echo __('Statements'); ?></th>
873 <th><?php
874 /* l10n: # = Amount of queries */
875 echo __('#');
877 </th>
878 <th>&oslash; <?php echo __('per hour'); ?></th>
879 <th>%</th>
880 </tr>
881 </thead>
882 <tbody>
884 <?php
885 $chart_json = array();
886 $query_sum = array_sum($used_queries);
887 $other_sum = 0;
888 foreach ($used_queries as $name => $value) {
889 $odd_row = !$odd_row;
891 // For the percentage column, use Questions - Connections, because
892 // the number of connections is not an item of the Query types
893 // but is included in Questions. Then the total of the percentages is 100.
894 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
896 // Group together values that make out less than 2% into "Other", but only if we have more than 6 fractions already
897 if ($value < $query_sum * 0.02 && count($chart_json)>6)
898 $other_sum += $value;
899 else $chart_json[$name] = $value;
901 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
902 <th class="name"><?php echo htmlspecialchars($name); ?></th>
903 <td class="value"><?php echo htmlspecialchars(PMA_formatNumber($value, 5, 0, true)); ?></td>
904 <td class="value"><?php echo
905 htmlspecialchars(PMA_formatNumber($value * $hour_factor, 4, 1, true)); ?></td>
906 <td class="value"><?php echo
907 htmlspecialchars(PMA_formatNumber($value * $perc_factor, 0, 2)); ?>%</td>
908 </tr>
909 <?php
912 </tbody>
913 </table>
915 <div id="serverstatusquerieschart">
916 <span style="display:none;">
917 <?php
918 if ($other_sum > 0)
919 $chart_json[__('Other')] = $other_sum;
921 echo json_encode($chart_json);
923 </span>
924 </div>
925 <?php
928 function printServerTraffic()
930 global $server_status, $PMA_PHP_SELF;
931 global $server_master_status, $server_slave_status, $replication_types;
933 $hour_factor = 3600 / $server_status['Uptime'];
936 * starttime calculation
938 $start_time = PMA_DBI_fetch_value(
939 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
942 <h3><?php
943 echo sprintf(
944 __('Network traffic since startup: %s'),
945 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
948 </h3>
951 <?php
952 echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'),
953 PMA_timespanFormat($server_status['Uptime']),
954 PMA_localisedDate($start_time)) . "\n";
956 </p>
958 <?php
959 if ($server_master_status || $server_slave_status) {
960 echo '<p class="notice">';
961 if ($server_master_status && $server_slave_status) {
962 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
963 } elseif ($server_master_status) {
964 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
965 } elseif ($server_slave_status) {
966 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
968 echo ' ';
969 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
970 echo '</p>';
973 /* if the server works as master or slave in replication process, display useful information */
974 if ($server_master_status || $server_slave_status)
977 <hr class="clearfloat" />
979 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
980 <?php
982 foreach ($replication_types as $type)
984 if (${"server_{$type}_status"}) {
985 PMA_replication_print_status_table($type);
988 unset($types);
992 <table id="serverstatustraffic" class="data noclick">
993 <thead>
994 <tr>
995 <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>
996 <th>&oslash; <?php echo __('per hour'); ?></th>
997 </tr>
998 </thead>
999 <tbody>
1000 <tr class="odd">
1001 <th class="name"><?php echo __('Received'); ?></th>
1002 <td class="value"><?php echo
1003 implode(' ',
1004 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
1005 <td class="value"><?php echo
1006 implode(' ',
1007 PMA_formatByteDown(
1008 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
1009 </tr>
1010 <tr class="even">
1011 <th class="name"><?php echo __('Sent'); ?></th>
1012 <td class="value"><?php echo
1013 implode(' ',
1014 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
1015 <td class="value"><?php echo
1016 implode(' ',
1017 PMA_formatByteDown(
1018 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
1019 </tr>
1020 <tr class="odd">
1021 <th class="name"><?php echo __('Total'); ?></th>
1022 <td class="value"><?php echo
1023 implode(' ',
1024 PMA_formatByteDown(
1025 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
1026 ); ?></td>
1027 <td class="value"><?php echo
1028 implode(' ',
1029 PMA_formatByteDown(
1030 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
1031 * $hour_factor, 3, 1)
1032 ); ?></td>
1033 </tr>
1034 </tbody>
1035 </table>
1037 <table id="serverstatusconnections" class="data noclick">
1038 <thead>
1039 <tr>
1040 <th colspan="2"><?php echo __('Connections'); ?></th>
1041 <th>&oslash; <?php echo __('per hour'); ?></th>
1042 <th>%</th>
1043 </tr>
1044 </thead>
1045 <tbody>
1046 <tr class="odd">
1047 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
1048 <td class="value"><?php echo
1049 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
1050 <td class="value">--- </td>
1051 <td class="value">--- </td>
1052 </tr>
1053 <tr class="even">
1054 <th class="name"><?php echo __('Failed attempts'); ?></th>
1055 <td class="value"><?php echo
1056 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
1057 <td class="value"><?php echo
1058 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
1059 4, 2, true); ?></td>
1060 <td class="value"><?php echo
1061 $server_status['Connections'] > 0
1062 ? PMA_formatNumber(
1063 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
1064 0, 2, true) . '%'
1065 : '--- '; ?></td>
1066 </tr>
1067 <tr class="odd">
1068 <th class="name"><?php echo __('Aborted'); ?></th>
1069 <td class="value"><?php echo
1070 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
1071 <td class="value"><?php echo
1072 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
1073 4, 2, true); ?></td>
1074 <td class="value"><?php echo
1075 $server_status['Connections'] > 0
1076 ? PMA_formatNumber(
1077 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
1078 0, 2, true) . '%'
1079 : '--- '; ?></td>
1080 </tr>
1081 <tr class="even">
1082 <th class="name"><?php echo __('Total'); ?></th>
1083 <td class="value"><?php echo
1084 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
1085 <td class="value"><?php echo
1086 PMA_formatNumber($server_status['Connections'] * $hour_factor,
1087 4, 2); ?></td>
1088 <td class="value"><?php echo
1089 PMA_formatNumber(100, 0, 2); ?>%</td>
1090 </tr>
1091 </tbody>
1092 </table>
1093 <?php
1095 $url_params = array();
1097 if (! empty($_REQUEST['full'])) {
1098 $sql_query = 'SHOW FULL PROCESSLIST';
1099 $url_params['full'] = 1;
1100 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
1101 } else {
1102 $sql_query = 'SHOW PROCESSLIST';
1103 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
1105 $result = PMA_DBI_query($sql_query);
1108 * Displays the page
1111 <table id="tableprocesslist" class="data clearfloat noclick">
1112 <thead>
1113 <tr>
1114 <th><?php echo __('Processes'); ?></th>
1115 <th><?php echo __('ID'); ?></th>
1116 <th><?php echo __('User'); ?></th>
1117 <th><?php echo __('Host'); ?></th>
1118 <th><?php echo __('Database'); ?></th>
1119 <th><?php echo __('Command'); ?></th>
1120 <th><?php echo __('Time'); ?></th>
1121 <th><?php echo __('Status'); ?></th>
1122 <th><?php
1123 echo __('SQL query');
1124 if (! PMA_DRIZZLE) { ?>
1125 <a href="<?php echo $full_text_link; ?>"
1126 title="<?php echo empty($full) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>">
1127 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (empty($_REQUEST['full']) ? 'full' : 'partial'); ?>text.png"
1128 alt="<?php echo empty($_REQUEST['full']) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>" />
1129 </a>
1130 <?php } ?>
1131 </th>
1132 </tr>
1133 </thead>
1134 <tbody>
1135 <?php
1136 $odd_row = true;
1137 while ($process = PMA_DBI_fetch_assoc($result)) {
1138 if (PMA_DRIZZLE) {
1139 // Drizzle uses uppercase keys
1140 foreach ($process as $k => $v) {
1141 $k = $k !== 'DB'
1142 ? ucfirst(strtolower($k))
1143 : 'db';
1144 $process[$k] = $v;
1147 $url_params['kill'] = $process['Id'];
1148 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
1150 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
1151 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
1152 <td class="value"><?php echo $process['Id']; ?></td>
1153 <td><?php echo $process['User']; ?></td>
1154 <td><?php echo $process['Host']; ?></td>
1155 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
1156 <td><?php echo $process['Command']; ?></td>
1157 <td class="value"><?php echo $process['Time']; ?></td>
1158 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
1159 <td>
1160 <?php
1161 if (empty($process['Info'])) {
1162 echo '---';
1163 } else {
1164 if (empty($_REQUEST['full']) && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
1165 echo htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
1166 } else {
1167 echo PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
1171 </td>
1172 </tr>
1173 <?php
1174 $odd_row = ! $odd_row;
1177 </tbody>
1178 </table>
1179 <?php
1182 function printVariablesTable()
1184 global $server_status, $server_variables, $allocationMap, $links;
1186 * Messages are built using the message name
1188 $strShowStatus = array(
1189 'Aborted_clients' => __('The number of connections that were aborted because the client died without closing the connection properly.'),
1190 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
1191 '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.'),
1192 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
1193 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
1194 '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.'),
1195 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
1196 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
1197 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
1198 '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.'),
1199 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
1200 'Flush_commands' => __('The number of executed FLUSH statements.'),
1201 'Handler_commit' => __('The number of internal COMMIT statements.'),
1202 'Handler_delete' => __('The number of times a row was deleted from a table.'),
1203 '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.'),
1204 '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.'),
1205 '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.'),
1206 '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.'),
1207 '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.'),
1208 '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.'),
1209 '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.'),
1210 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
1211 'Handler_update' => __('The number of requests to update a row in a table.'),
1212 'Handler_write' => __('The number of requests to insert a row in a table.'),
1213 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
1214 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
1215 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
1216 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
1217 '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.'),
1218 '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.'),
1219 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
1220 '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.'),
1221 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
1222 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
1223 '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.'),
1224 '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.'),
1225 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
1226 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
1227 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
1228 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
1229 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
1230 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
1231 'Innodb_data_reads' => __('The total number of data reads.'),
1232 'Innodb_data_writes' => __('The total number of data writes.'),
1233 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
1234 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
1235 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
1236 '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.'),
1237 'Innodb_log_write_requests' => __('The number of log write requests.'),
1238 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
1239 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
1240 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
1241 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
1242 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
1243 'Innodb_pages_created' => __('The number of pages created.'),
1244 '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.'),
1245 'Innodb_pages_read' => __('The number of pages read.'),
1246 'Innodb_pages_written' => __('The number of pages written.'),
1247 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
1248 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
1249 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
1250 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
1251 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
1252 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
1253 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
1254 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
1255 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
1256 '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.'),
1257 '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.'),
1258 '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.'),
1259 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
1260 '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.'),
1261 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
1262 'Key_writes' => __('The number of physical writes of a key block to disk.'),
1263 '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.'),
1264 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
1265 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
1266 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
1267 'Open_files' => __('The number of files that are open.'),
1268 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
1269 'Open_tables' => __('The number of tables that are open.'),
1270 '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.'),
1271 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
1272 'Qcache_hits' => __('The number of cache hits.'),
1273 'Qcache_inserts' => __('The number of queries added to the cache.'),
1274 '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.'),
1275 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
1276 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
1277 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
1278 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
1279 '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.'),
1280 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
1281 '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.)'),
1282 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
1283 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
1284 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
1285 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
1286 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
1287 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
1288 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
1289 '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.'),
1290 'Sort_range' => __('The number of sorts that were done with ranges.'),
1291 'Sort_rows' => __('The number of sorted rows.'),
1292 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
1293 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
1294 '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.'),
1295 '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.'),
1296 'Threads_connected' => __('The number of currently open connections.'),
1297 '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.)'),
1298 'Threads_running' => __('The number of threads that are not sleeping.')
1302 * define some alerts
1304 // name => max value before alert
1305 $alerts = array(
1306 // lower is better
1307 // variable => max value
1308 'Aborted_clients' => 0,
1309 'Aborted_connects' => 0,
1311 'Binlog_cache_disk_use' => 0,
1313 'Created_tmp_disk_tables' => 0,
1315 'Handler_read_rnd' => 0,
1316 'Handler_read_rnd_next' => 0,
1318 'Innodb_buffer_pool_pages_dirty' => 0,
1319 'Innodb_buffer_pool_reads' => 0,
1320 'Innodb_buffer_pool_wait_free' => 0,
1321 'Innodb_log_waits' => 0,
1322 'Innodb_row_lock_time_avg' => 10, // ms
1323 'Innodb_row_lock_time_max' => 50, // ms
1324 'Innodb_row_lock_waits' => 0,
1326 'Slow_queries' => 0,
1327 'Delayed_errors' => 0,
1328 'Select_full_join' => 0,
1329 'Select_range_check' => 0,
1330 'Sort_merge_passes' => 0,
1331 'Opened_tables' => 0,
1332 'Table_locks_waited' => 0,
1333 'Qcache_lowmem_prunes' => 0,
1335 'Qcache_free_blocks' => $server_status['Qcache_total_blocks'] / 5,
1336 'Slow_launch_threads' => 0,
1338 // depends on Key_read_requests
1339 // normaly lower then 1:0.01
1340 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
1341 // depends on Key_write_requests
1342 // normaly nearly 1:1
1343 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
1345 'Key_buffer_fraction' => 0.5,
1347 // alert if more than 95% of thread cache is in use
1348 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
1350 // higher is better
1351 // variable => min value
1352 //'Handler read key' => '> ',
1356 <table class="data sortable noclick" id="serverstatusvariables">
1357 <col class="namecol" />
1358 <col class="valuecol" />
1359 <col class="descrcol" />
1360 <thead>
1361 <tr>
1362 <th><?php echo __('Variable'); ?></th>
1363 <th><?php echo __('Value'); ?></th>
1364 <th><?php echo __('Description'); ?></th>
1365 </tr>
1366 </thead>
1367 <tbody>
1368 <?php
1370 $odd_row = false;
1371 foreach ($server_status as $name => $value) {
1372 $odd_row = !$odd_row;
1374 <tr class="<?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_' . $allocationMap[$name]:''; ?>">
1375 <th class="name"><?php echo htmlspecialchars(str_replace('_', ' ', $name)) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1376 </th>
1377 <td class="value"><span class="formatted"><?php
1378 if (isset($alerts[$name])) {
1379 if ($value > $alerts[$name]) {
1380 echo '<span class="attention">';
1381 } else {
1382 echo '<span class="allfine">';
1385 if ('%' === substr($name, -1, 1)) {
1386 echo htmlspecialchars(PMA_formatNumber($value, 0, 2)) . ' %';
1387 } elseif (strpos($name, 'Uptime')!==FALSE) {
1388 echo htmlspecialchars(PMA_timespanFormat($value));
1389 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1390 echo htmlspecialchars(PMA_formatNumber($value, 3, 1));
1391 } elseif (is_numeric($value) && $value == (int) $value) {
1392 echo htmlspecialchars(PMA_formatNumber($value, 3, 0));
1393 } elseif (is_numeric($value)) {
1394 echo htmlspecialchars(PMA_formatNumber($value, 3, 1));
1395 } else {
1396 echo htmlspecialchars($value);
1398 if (isset($alerts[$name])) {
1399 echo '</span>';
1401 ?></span><span style="display:none;" class="original"><?php echo $value; ?></span>
1402 </td>
1403 <td class="descr">
1404 <?php
1405 if (isset($strShowStatus[$name ])) {
1406 echo $strShowStatus[$name];
1409 if (isset($links[$name])) {
1410 foreach ($links[$name] as $link_name => $link_url) {
1411 if ('doc' == $link_name) {
1412 echo PMA_showMySQLDocu($link_url, $link_url);
1413 } else {
1414 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1415 "\n";
1418 unset($link_url, $link_name);
1421 </td>
1422 </tr>
1423 <?php
1426 </tbody>
1427 </table>
1428 <?php
1431 function printMonitor()
1433 global $server_status, $server_db_isLocal;
1435 <div class="tabLinks" style="display:none;">
1436 <a href="#pauseCharts">
1437 <img src="themes/dot.gif" class="icon ic_play" alt="" />
1438 <?php echo __('Start Monitor'); ?>
1439 </a>
1440 <a href="#settingsPopup" rel="popupLink" style="display:none;">
1441 <img src="themes/dot.gif" class="icon ic_s_cog" alt="" />
1442 <?php echo __('Settings'); ?>
1443 </a>
1444 <a href="#monitorInstructionsDialog">
1445 <img src="themes/dot.gif" class="icon ic_b_help" alt="" />
1446 <?php echo __('Instructions/Setup'); ?>
1447 </a>
1448 <a href="#endChartEditMode" style="display:none;">
1449 <img src="themes/dot.gif" class="icon ic_s_okay" alt="" />
1450 <?php echo __('Done rearranging/editing charts'); ?>
1451 </a>
1452 </div>
1454 <div class="popupContent settingsPopup">
1455 <a href="#addNewChart">
1456 <img src="themes/dot.gif" class="icon ic_b_chart" alt="" />
1457 <?php echo __('Add chart'); ?>
1458 </a>
1459 <a href="#rearrangeCharts"><img class="icon ic_b_tblops" src="themes/dot.gif" width="16" height="16" alt="" /><?php echo __('Rearrange/edit charts'); ?></a>
1460 <div class="clearfloat paddingtop"></div>
1461 <div class="floatleft">
1462 <?php
1463 echo __('Refresh rate') . '<br />';
1464 refreshList('gridChartRefresh', 5, Array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200));
1465 ?><br />
1466 </div>
1467 <div class="floatleft">
1468 <?php echo __('Chart columns'); ?> <br />
1469 <select name="chartColumns">
1470 <option>1</option>
1471 <option>2</option>
1472 <option>3</option>
1473 <option>4</option>
1474 <option>5</option>
1475 <option>6</option>
1476 <option>7</option>
1477 <option>8</option>
1478 <option>9</option>
1479 <option>10</option>
1480 </select>
1481 </div>
1483 <div class="clearfloat paddingtop">
1484 <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/>
1485 <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>
1486 </div>
1487 </div>
1489 <div id="monitorInstructionsDialog" title="<?php echo __('Monitor Instructions'); ?>" style="display:none;">
1490 <?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%'); ?>
1491 <?php if(PMA_MYSQL_INT_VERSION < 50106) { ?>
1493 <img class="icon ic_s_attention" src="themes/dot.gif" alt="" />
1494 <?php
1495 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.');
1497 </p>
1498 <?php
1499 } else {
1501 <p></p>
1502 <img class="ajaxIcon" src="<?php echo $GLOBALS['pmaThemeImage']; ?>ajax_clock_small.gif" alt="Loading" />
1503 <div class="ajaxContent"></div>
1504 <div class="monitorUse" style="display:none;">
1505 <p></p>
1506 <?php
1507 echo '<strong>';
1508 echo __('Using the monitor:');
1509 echo '</strong><p>';
1510 echo __('Ok, you are good to go! Once you click \'Start monitor\' your browser will refresh all displayed charts in a regular interval. You may add charts and change the refresh rate under \'Settings\', or remove any chart using the cog icon on each respective chart.');
1511 echo '</p><p>';
1512 echo __('To display queries from the logs, select the relevant time span on any chart by holding down the left mouse button and panning over the chart. Once confirmed, this will load a table of grouped queries, there you may click on any occuring SELECT statements to further analyze them.');
1513 echo '</p>';
1516 <img class="icon ic_s_attention" src="themes/dot.gif" alt="" />
1517 <?php
1518 echo '<strong>';
1519 echo __('Please note:');
1520 echo '</strong><br />';
1521 echo __('Enabling the general_log may increase the server load by 5-15%. Also be aware that generating statistics from the logs is a load intensive task, so it is advisable to select only a small time span and to disable the general_log and empty its table once monitoring is not required any more.');
1523 </p>
1524 </div>
1525 <?php } ?>
1526 </div>
1528 <div id="addChartDialog" title="Add chart" style="display:none;">
1529 <div id="tabGridVariables">
1530 <p><input type="text" name="chartTitle" value="<?php echo __('Chart Title'); ?>" /></p>
1532 <input type="radio" name="chartType" value="preset" id="chartPreset" />
1533 <label for="chartPreset"><?php echo __('Preset chart'); ?></label>
1534 <select name="presetCharts"></select><br/>
1536 <input type="radio" name="chartType" value="variable" id="chartStatusVar" checked="checked" />
1537 <label for="chartStatusVar"><?php echo __('Status variable(s)'); ?></label><br/>
1538 <div id="chartVariableSettings">
1539 <label for="chartSeries"><?php echo __('Select series:'); ?></label><br />
1540 <select id="chartSeries" name="varChartList" size="1">
1541 <option><?php echo __('Commonly monitored'); ?></option>
1542 <option>Processes</option>
1543 <option>Questions</option>
1544 <option>Connections</option>
1545 <option>Bytes_sent</option>
1546 <option>Bytes_received</option>
1547 <option>Threads_connected</option>
1548 <option>Created_tmp_disk_tables</option>
1549 <option>Handler_read_first</option>
1550 <option>Innodb_buffer_pool_wait_free</option>
1551 <option>Key_reads</option>
1552 <option>Open_tables</option>
1553 <option>Select_full_join</option>
1554 <option>Slow_queries</option>
1555 </select><br />
1556 <label for="variableInput"><?php echo __('or type variable name:'); ?> </label>
1557 <input type="text" name="variableInput" id="variableInput" />
1558 <p></p>
1559 <input type="checkbox" name="differentialValue" id="differentialValue" value="differential" checked="checked" />
1560 <label for="differentialValue"><?php echo __('Display as differential value'); ?></label><br />
1561 <input type="checkbox" id="useDivisor" name="useDivisor" value="1" />
1562 <label for="useDivisor"><?php echo __('Apply a divisor'); ?></label>
1563 <span class="divisorInput" style="display:none;">
1564 <input type="text" name="valueDivisor" size="4" value="1" />
1565 (<a href="#kibDivisor"><?php echo __('KiB'); ?></a>, <a href="#mibDivisor"><?php echo __('MiB'); ?></a>)
1566 </span><br />
1568 <input type="checkbox" id="useUnit" name="useUnit" value="1" />
1569 <label for="useUnit"><?php echo __('Append unit to data values'); ?></label>
1571 <span class="unitInput" style="display:none;">
1572 <input type="text" name="valueUnit" size="4" value="" />
1573 </span>
1575 <a href="#submitAddSeries"><b><?php echo __('Add this series'); ?></b></a>
1576 <span id="clearSeriesLink" style="display:none;">
1577 | <a href="#submitClearSeries"><?php echo __('Clear series'); ?></a>
1578 </span>
1579 </p>
1580 <?php echo __('Series in Chart:'); ?><br/>
1581 <span id="seriesPreview">
1582 <i><?php echo __('None'); ?></i>
1583 </span>
1584 </div>
1585 </div>
1586 </div>
1588 <!-- For generic use -->
1589 <div id="emptyDialog" title="Dialog" style="display:none;">
1590 </div>
1592 <div id="logAnalyseDialog" title="<?php echo __('Log statistics'); ?>" style="display:none;">
1593 <p> <?php echo __('Selected time range:'); ?>
1594 <input type="text" name="dateStart" class="datetimefield" value="" /> -
1595 <input type="text" name="dateEnd" class="datetimefield" value="" /></p>
1596 <input type="checkbox" id="limitTypes" value="1" checked="checked" />
1597 <label for="limitTypes">
1598 <?php echo __('Only retrieve SELECT,INSERT,UPDATE and DELETE Statements'); ?>
1599 </label>
1600 <br/>
1601 <input type="checkbox" id="removeVariables" value="1" checked="checked" />
1602 <label for="removeVariables">
1603 <?php echo __('Remove variable data in INSERT statements for better grouping'); ?>
1604 </label>
1606 <?php
1607 echo '<p>';
1608 echo __('Choose from which log you want the statistics to be generated from.');
1609 echo '</p><p>';
1610 echo __('Results are grouped by query text.');
1611 echo '</p>';
1613 </div>
1615 <div id="queryAnalyzerDialog" title="<?php echo __('Query analyzer'); ?>" style="display:none;">
1616 <textarea id="sqlquery"> </textarea>
1617 <p></p>
1618 <div class="placeHolder"></div>
1619 </div>
1621 <table border="0" class="clearfloat" id="chartGrid">
1623 </table>
1624 <div id="logTable">
1625 <br/>
1626 </div>
1628 <script type="text/javascript">
1629 variableNames = [ <?php
1630 $i=0;
1631 foreach ($server_status as $name=>$value) {
1632 if (is_numeric($value)) {
1633 if ($i++ > 0) echo ", ";
1634 echo "'" . $name . "'";
1637 ?> ];
1638 </script>
1639 <?php
1642 /* Builds a <select> list for refresh rates */
1643 function refreshList($name, $defaultRate=5, $refreshRates=Array(1, 2, 5, 10, 20, 40, 60, 120, 300, 600))
1646 <select name="<?php echo $name; ?>" id="id_<?php echo $name; ?>">
1647 <?php
1648 foreach ($refreshRates as $rate) {
1649 $selected = ($rate == $defaultRate)?' selected="selected"':'';
1651 if ($rate<60)
1652 echo '<option value="' . $rate . '"' . $selected . '>' . sprintf(_ngettext('%d second', '%d seconds', $rate), $rate) . '</option>';
1653 else
1654 echo '<option value="' . $rate . '"' . $selected . '>' . sprintf(_ngettext('%d minute', '%d minutes', $rate/60), $rate/60) . '</option>';
1657 </select>
1658 <?php
1662 * cleanup of some deprecated values
1664 * @param array &$server_status
1666 function cleanDeprecated(&$server_status)
1668 $deprecated = array(
1669 'Com_prepare_sql' => 'Com_stmt_prepare',
1670 'Com_execute_sql' => 'Com_stmt_execute',
1671 'Com_dealloc_sql' => 'Com_stmt_close',
1674 foreach ($deprecated as $old => $new) {
1675 if (isset($server_status[$old]) && isset($server_status[$new])) {
1676 unset($server_status[$old]);
1682 * Sends the footer
1684 require './libraries/footer.inc.php';