Remove stray code
[phpmyadmin.git] / server_status.php
blob30c3c5a850ed71598fd444ebb1e99e808a8f686a
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;
22 require_once './libraries/common.inc.php';
24 /**
25 * Ajax request
28 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
29 // Send with correct charset
30 header('Content-Type: text/html; charset=UTF-8');
32 // real-time charting data
33 if (isset($_REQUEST['chart_data'])) {
34 switch($_REQUEST['type']) {
35 // Process and Connections realtime chart
36 case 'proc':
37 $c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1);
38 $result = PMA_DBI_query('SHOW PROCESSLIST');
39 $num_procs = PMA_DBI_num_rows($result);
41 $ret = array(
42 'x' => microtime(true) * 1000,
43 'y_proc' => $num_procs,
44 'y_conn' => $c['Connections']
47 exit(json_encode($ret));
49 // Query realtime chart
50 case 'queries':
51 $queries = PMA_DBI_fetch_result(
52 "SHOW GLOBAL STATUS
53 WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions')
54 AND Value > 0'", 0, 1);
55 cleanDeprecated($queries);
56 // admin commands are not queries
57 unset($queries['Com_admin_commands']);
58 $questions = $queries['Questions'];
59 unset($queries['Questions']);
61 //$sum=array_sum($queries);
62 $ret = array(
63 'x' => microtime(true) * 1000,
64 'y' => $questions,
65 'pointInfo' => $queries
68 exit(json_encode($ret));
70 // Traffic realtime chart
71 case 'traffic':
72 $traffic = PMA_DBI_fetch_result(
73 "SHOW GLOBAL STATUS
74 WHERE Variable_name = 'Bytes_received'
75 OR Variable_name = 'Bytes_sent'", 0, 1);
77 $ret = array(
78 'x' => microtime(true) * 1000,
79 'y_sent' => $traffic['Bytes_sent'],
80 'y_received' => $traffic['Bytes_received']
83 exit(json_encode($ret));
85 // Data for the monitor
86 case 'chartgrid':
87 $ret = json_decode($_REQUEST['requiredData'], true);
88 $statusVars = array();
89 $serverVars = array();
90 $sysinfo = $cpuload = $memory = 0;
91 $pName = '';
93 /* Accumulate all required variables and data */
94 // For each chart
95 foreach ($ret as $chart_id => $chartNodes) {
96 // For each data series
97 foreach ($chartNodes as $node_id => $nodeDataPoints) {
98 // For each data point in the series (usually just 1)
99 foreach ($nodeDataPoints as $point_id => $dataPoint) {
100 $pName = $dataPoint['name'];
102 switch ($dataPoint['type']) {
103 /* We only collect the status and server variables here to
104 * read them all in one query, and only afterwards assign them.
105 * Also do some white list filtering on the names
107 case 'servervar':
108 if (!preg_match('/[^a-zA-Z_]+/', $pName)) {
109 $serverVars[] = $pName;
111 break;
113 case 'statusvar':
114 if (!preg_match('/[^a-zA-Z_]+/', $pName)) {
115 $statusVars[] = $pName;
117 break;
119 case 'proc':
120 $result = PMA_DBI_query('SHOW PROCESSLIST');
121 $ret[$chart_id][$node_id][$point_id]['value'] = PMA_DBI_num_rows($result);
122 break;
124 case 'cpu':
125 if (!$sysinfo) {
126 require_once('libraries/sysinfo.lib.php');
127 $sysinfo = getSysInfo();
129 if (!$cpuload) {
130 $cpuload = $sysinfo->loadavg();
133 if (PHP_OS == 'Linux') {
134 $ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle'];
135 $ret[$chart_id][$node_id][$point_id]['busy'] = $cpuload['busy'];
136 } else
137 $ret[$chart_id][$node_id][$point_id]['value'] = $cpuload['loadavg'];
139 break;
141 case 'memory':
142 if (!$sysinfo) {
143 require_once('libraries/sysinfo.lib.php');
144 $sysinfo = getSysInfo();
146 if (!$memory) {
147 $memory = $sysinfo->memory();
150 $ret[$chart_id][$node_id][$point_id]['value'] = $memory[$pName];
151 break;
152 } /* switch */
153 } /* foreach */
154 } /* foreach */
155 } /* foreach */
157 // Retrieve all required status variables
158 if (count($statusVars)) {
159 $statusVarValues = PMA_DBI_fetch_result(
160 "SHOW GLOBAL STATUS
161 WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1);
162 } else {
163 $statusVarValues = array();
166 // Retrieve all required server variables
167 if (count($serverVars)) {
168 $serverVarValues = PMA_DBI_fetch_result(
169 "SHOW GLOBAL VARIABLES
170 WHERE Variable_name='" . implode("' OR Variable_name='", $serverVars) . "'", 0, 1);
171 } else {
172 $serverVarValues = array();
175 // ...and now assign them
176 foreach ($ret as $chart_id => $chartNodes) {
177 foreach ($chartNodes as $node_id => $nodeDataPoints) {
178 foreach ($nodeDataPoints as $point_id => $dataPoint) {
179 switch($dataPoint['type']) {
180 case 'statusvar':
181 $ret[$chart_id][$node_id][$point_id]['value'] = $statusVarValues[$dataPoint['name']];
182 break;
183 case 'servervar':
184 $ret[$chart_id][$node_id][$point_id]['value'] = $serverVarValues[$dataPoint['name']];
185 break;
191 $ret['x'] = microtime(true) * 1000;
193 exit(json_encode($ret));
197 if (isset($_REQUEST['log_data'])) {
198 if (PMA_MYSQL_INT_VERSION < 50106) {
199 /* FIXME: why this? */
200 exit('""');
203 $start = intval($_REQUEST['time_start']);
204 $end = intval($_REQUEST['time_end']);
206 if ($_REQUEST['type'] == 'slow') {
207 $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, '.
208 'SUM(rows_sent) AS rows_sent, SUM(rows_examined) AS rows_examined, db, sql_text, COUNT(sql_text) AS \'#\' '.
209 'FROM `mysql`.`slow_log` WHERE start_time > FROM_UNIXTIME(' . $start . ') '.
210 'AND start_time < FROM_UNIXTIME(' . $end . ') GROUP BY sql_text';
212 $result = PMA_DBI_try_query($q);
214 $return = array('rows' => array(), 'sum' => array());
215 $type = '';
217 while ($row = PMA_DBI_fetch_assoc($result)) {
218 $type = strtolower(substr($row['sql_text'], 0, strpos($row['sql_text'], ' ')));
220 switch($type) {
221 case 'insert':
222 case 'update':
223 // Cut off big inserts and updates, but append byte count therefor
224 if (strlen($row['sql_text']) > 220) {
225 $row['sql_text'] = substr($row['sql_text'], 0, 200)
226 . '... ['
227 . implode(' ', PMA_formatByteDown(strlen($row['sql_text']), 2, 2))
228 . ']';
230 break;
231 default:
232 break;
235 if (!isset($return['sum'][$type])) {
236 $return['sum'][$type] = 0;
238 $return['sum'][$type] += $row['#'];
239 $return['rows'][] = $row;
242 $return['sum']['TOTAL'] = array_sum($return['sum']);
243 $return['numRows'] = count($return['rows']);
245 PMA_DBI_free_result($result);
247 exit(json_encode($return));
250 if ($_REQUEST['type'] == 'general') {
251 $limitTypes = (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes'])
252 ? 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ' : '';
254 $q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, server_id, argument, count(argument) as \'#\' '.
255 'FROM `mysql`.`general_log` WHERE command_type=\'Query\' '.
256 'AND event_time > FROM_UNIXTIME(' . $start . ') AND event_time < FROM_UNIXTIME(' . $end . ') '.
257 $limitTypes . 'GROUP by argument'; // HAVING count > 1';
259 $result = PMA_DBI_try_query($q);
261 $return = array('rows' => array(), 'sum' => array());
262 $type = '';
263 $insertTables = array();
264 $insertTablesFirst = -1;
265 $i = 0;
266 $removeVars = isset($_REQUEST['removeVariables']) && $_REQUEST['removeVariables'];
268 while ($row = PMA_DBI_fetch_assoc($result)) {
269 preg_match('/^(\w+)\s/', $row['argument'], $match);
270 $type = strtolower($match[1]);
272 if (!isset($return['sum'][$type])) {
273 $return['sum'][$type] = 0;
275 $return['sum'][$type] += $row['#'];
277 switch($type) {
278 case 'insert':
279 // Group inserts if selected
280 if ($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i', $row['argument'], $matches)) {
281 $insertTables[$matches[2]]++;
282 if ($insertTables[$matches[2]] > 1) {
283 $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
285 // Add a ... to the end of this query to indicate that there's been other queries
286 if ($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.') {
287 $return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
290 // Group this value, thus do not add to the result list
291 continue 2;
292 } else {
293 $insertTablesFirst = $i;
294 $insertTables[$matches[2]] += $row['#'] - 1;
297 // No break here
299 case 'update':
300 // Cut off big inserts and updates, but append byte count therefor
301 if (strlen($row['argument']) > 220) {
302 $row['argument'] = substr($row['argument'], 0, 200)
303 . '... ['
304 . implode(' ', PMA_formatByteDown(strlen($row['argument'])), 2, 2)
305 . ']';
307 break;
309 default: break;
312 $return['rows'][] = $row;
313 $i++;
316 $return['sum']['TOTAL'] = array_sum($return['sum']);
317 $return['numRows'] = count($return['rows']);
319 PMA_DBI_free_result($result);
321 exit(json_encode($return));
325 if (isset($_REQUEST['logging_vars'])) {
326 if (isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) {
327 $value = PMA_sqlAddslashes($_REQUEST['varValue']);
328 if (!is_numeric($value)) {
329 $value="'" . $value . "'";
332 if (! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName'])) {
333 PMA_DBI_query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value);
338 $loggingVars = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES WHERE Variable_name IN ("general_log","slow_query_log","long_query_time","log_output")', 0, 1);
339 exit(json_encode($loggingVars));
342 if (isset($_REQUEST['query_analyzer'])) {
343 $return = array();
345 if (strlen($_REQUEST['database'])) {
346 PMA_DBI_select_db($_REQUEST['database']);
349 if ($profiling = PMA_profilingSupported()) {
350 PMA_DBI_query('SET PROFILING=1;');
353 // Do not cache query
354 $query = preg_replace('/^(\s*SELECT)/i', '\\1 SQL_NO_CACHE', $_REQUEST['query']);
356 $result = PMA_DBI_try_query($query);
357 $return['affectedRows'] = $GLOBALS['cached_affected_rows'];
359 $result = PMA_DBI_try_query('EXPLAIN ' . $query);
360 while ($row = PMA_DBI_fetch_assoc($result)) {
361 $return['explain'][] = $row;
364 // In case an error happened
365 $return['error'] = PMA_DBI_getError();
367 PMA_DBI_free_result($result);
369 if ($profiling) {
370 $return['profiling'] = array();
371 $result = PMA_DBI_try_query('SELECT seq,state,duration FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID=1 ORDER BY seq');
372 while ($row = PMA_DBI_fetch_assoc($result)) {
373 $return['profiling'][]= $row;
375 PMA_DBI_free_result($result);
378 exit(json_encode($return));
381 if (isset($_REQUEST['advisor'])) {
382 include('libraries/Advisor.class.php');
383 $advisor = new Advisor();
384 exit(json_encode($advisor->run()));
390 * Replication library
392 require './libraries/replication.inc.php';
393 require_once './libraries/replication_gui.lib.php';
396 * JS Includes
399 $GLOBALS['js_include'][] = 'server_status.js';
400 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
401 $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
402 $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
403 // Charting
404 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
405 /* Files required for chart exporting */
406 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
407 /* < IE 9 doesn't support canvas natively */
408 if(PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
409 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
411 $GLOBALS['js_include'][] = 'canvg/canvg.js';
414 * flush status variables if requested
416 if (isset($_REQUEST['flush'])) {
417 $_flush_commands = array(
418 'STATUS',
419 'TABLES',
420 'QUERY CACHE',
423 if (in_array($_REQUEST['flush'], $_flush_commands)) {
424 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
426 unset($_flush_commands);
430 * Kills a selected process
432 if (!empty($_REQUEST['kill'])) {
433 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
434 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
435 } else {
436 $message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
438 $message->addParam($_REQUEST['kill']);
439 //$message->display();
445 * get status from server
447 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
450 * for some calculations we require also some server settings
452 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
455 * cleanup of some deprecated values
457 cleanDeprecated($server_status);
460 * calculate some values
462 // Key_buffer_fraction
463 if (isset($server_status['Key_blocks_unused'])
464 && isset($server_variables['key_cache_block_size'])
465 && isset($server_variables['key_buffer_size'])) {
466 $server_status['Key_buffer_fraction_%'] =
468 - $server_status['Key_blocks_unused']
469 * $server_variables['key_cache_block_size']
470 / $server_variables['key_buffer_size']
471 * 100;
472 } elseif (isset($server_status['Key_blocks_used'])
473 && isset($server_variables['key_buffer_size'])) {
474 $server_status['Key_buffer_fraction_%'] =
475 $server_status['Key_blocks_used']
476 * 1024
477 / $server_variables['key_buffer_size'];
480 // Ratio for key read/write
481 if (isset($server_status['Key_writes'])
482 && isset($server_status['Key_write_requests'])
483 && $server_status['Key_write_requests'] > 0) {
484 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
487 if (isset($server_status['Key_reads'])
488 && isset($server_status['Key_read_requests'])
489 && $server_status['Key_read_requests'] > 0) {
490 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
493 // Threads_cache_hitrate
494 if (isset($server_status['Threads_created'])
495 && isset($server_status['Connections'])
496 && $server_status['Connections'] > 0) {
498 $server_status['Threads_cache_hitrate_%'] =
499 100 - $server_status['Threads_created'] / $server_status['Connections'] * 100;
503 * split variables in sections
505 $allocations = array(
506 // variable name => section
507 // variable names match when they begin with the given string
509 'Com_' => 'com',
510 'Innodb_' => 'innodb',
511 'Ndb_' => 'ndb',
512 'Handler_' => 'handler',
513 'Qcache_' => 'qcache',
514 'Threads_' => 'threads',
515 'Slow_launch_threads' => 'threads',
517 'Binlog_cache_' => 'binlog_cache',
518 'Created_tmp_' => 'created_tmp',
519 'Key_' => 'key',
521 'Delayed_' => 'delayed',
522 'Not_flushed_delayed_rows' => 'delayed',
524 'Flush_commands' => 'query',
525 'Last_query_cost' => 'query',
526 'Slow_queries' => 'query',
527 'Queries' => 'query',
528 'Prepared_stmt_count' => 'query',
530 'Select_' => 'select',
531 'Sort_' => 'sort',
533 'Open_tables' => 'table',
534 'Opened_tables' => 'table',
535 'Open_table_definitions' => 'table',
536 'Opened_table_definitions' => 'table',
537 'Table_locks_' => 'table',
539 'Rpl_status' => 'repl',
540 'Slave_' => 'repl',
542 'Tc_' => 'tc',
544 'Ssl_' => 'ssl',
546 'Open_files' => 'files',
547 'Open_streams' => 'files',
548 'Opened_files' => 'files',
551 $sections = array(
552 // section => section name (description)
553 'com' => 'Com',
554 'query' => __('SQL query'),
555 'innodb' => 'InnoDB',
556 'ndb' => 'NDB',
557 'handler' => __('Handler'),
558 'qcache' => __('Query cache'),
559 'threads' => __('Threads'),
560 'binlog_cache' => __('Binary log'),
561 'created_tmp' => __('Temporary data'),
562 'delayed' => __('Delayed inserts'),
563 'key' => __('Key cache'),
564 'select' => __('Joins'),
565 'repl' => __('Replication'),
566 'sort' => __('Sorting'),
567 'table' => __('Tables'),
568 'tc' => __('Transaction coordinator'),
569 'files' => __('Files'),
570 'ssl' => 'SSL',
574 * define some needfull links/commands
576 // variable or section name => (name => url)
577 $links = array();
579 $links['table'][__('Flush (close) all tables')]
580 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
581 $links['table'][__('Show open tables')]
582 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
583 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
585 if ($server_master_status) {
586 $links['repl'][__('Show slave hosts')]
587 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
588 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
589 $links['repl'][__('Show master status')] = '#replication_master';
591 if ($server_slave_status) {
592 $links['repl'][__('Show slave status')] = '#replication_slave';
595 $links['repl']['doc'] = 'replication';
597 $links['qcache'][__('Flush query cache')]
598 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
599 PMA_generate_common_url();
600 $links['qcache']['doc'] = 'query_cache';
602 //$links['threads'][__('Show processes')]
603 // = 'server_processlist.php?' . PMA_generate_common_url();
604 $links['threads']['doc'] = 'mysql_threads';
606 $links['key']['doc'] = 'myisam_key_cache';
608 $links['binlog_cache']['doc'] = 'binary_log';
610 $links['Slow_queries']['doc'] = 'slow_query_log';
612 $links['innodb'][__('Variables')]
613 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
614 $links['innodb'][__('InnoDB Status')]
615 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
616 PMA_generate_common_url();
617 $links['innodb']['doc'] = 'innodb';
620 // Variable to contain all com_ variables
621 $used_queries = array();
623 // Variable to map variable names to their respective section name
624 // (used for js category filtering)
625 $allocationMap = array();
627 // sort vars into arrays
628 foreach ($server_status as $name => $value) {
629 foreach ($allocations as $filter => $section) {
630 if (strpos($name, $filter) !== false) {
631 $allocationMap[$name] = $section;
632 if ($section == 'com' && $value > 0) {
633 $used_queries[$name] = $value;
635 break; // Only exits inner loop
640 if(PMA_DRIZZLE) {
641 $used_queries = PMA_DBI_fetch_result(
642 'SELECT * FROM data_dictionary.global_statements',
646 unset($used_queries['admin_commands']);
647 } else {
648 // admin commands are not queries (e.g. they include COM_PING,
649 // which is excluded from $server_status['Questions'])
650 unset($used_queries['Com_admin_commands']);
653 /* Ajax request refresh */
654 if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
655 switch($_REQUEST['show']) {
656 case 'query_statistics':
657 printQueryStatistics();
658 exit();
659 case 'server_traffic':
660 printServerTraffic();
661 exit();
662 case 'variables_table':
663 // Prints the variables table
664 printVariablesTable();
665 exit();
667 default:
668 break;
672 $server_db_isLocal = strtolower($cfg['Server']['host']) == 'localhost'
673 || $cfg['Server']['host'] == '127.0.0.1'
674 || $cfg['Server']['host'] == '::1';
676 PMA_AddJSVar('pma_token', $_SESSION[' PMA_token ']);
677 PMA_AddJSVar('url_query', str_replace('&amp;', '&', PMA_generate_common_url($db)));
678 PMA_AddJSVar('server_time_diff', 'new Date().getTime() - ' . (microtime(true) * 1000));
679 PMA_AddJSVar('server_os', PHP_OS);
680 PMA_AddJSVar('is_superuser', PMA_isSuperuser() ? true : false);
681 PMA_AddJSVar('server_db_isLocal', $server_db_isLocal ? true : false);
682 PMA_AddJSVar('profiling_docu', PMA_showMySQLDocu('general-thread-states', 'general-thread-states'));
683 PMA_AddJSVar('explain_docu', PMA_showMySQLDocu('explain-output', 'explain-output'));
686 * start output
690 * Does the common work
692 require './libraries/server_common.inc.php';
697 * Displays the links
699 require './libraries/server_links.inc.php';
702 <div id="serverstatus">
703 <h2><?php
705 * Displays the sub-page heading
707 if ($GLOBALS['cfg']['MainPageIconic']) {
708 echo '<img class="icon ic_s_status" src="themes/dot.gif" width="16" height="16" alt="" />';
711 echo __('Runtime Information');
713 ?></h2>
714 <div id="serverStatusTabs">
715 <ul>
716 <li><a href="#statustabs_traffic"><?php echo __('Server'); ?></a></li>
717 <li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
718 <li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
719 <li class="jsfeature"><a href="#statustabs_charting"><?php echo __('Monitor'); ?></a></li>
720 <li class="jsfeature"><a href="#statustabs_advisor"><?php echo __('Advisor'); ?></a></li>
721 </ul>
723 <div id="statustabs_traffic" class="clearfloat">
724 <div class="buttonlinks jsfeature">
725 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&amp;' . PMA_generate_common_url(); ?>" >
726 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
727 <?php echo __('Refresh'); ?>
728 </a>
729 <span class="refreshList" style="display:none;">
730 <label for="id_trafficChartRefresh"><?php echo __('Refresh rate: '); ?></label>
731 <?php refreshList('trafficChartRefresh'); ?>
732 </span>
734 <a class="tabChart livetrafficLink" href="#">
735 <?php echo __('Live traffic chart'); ?>
736 </a>
737 <a class="tabChart liveconnectionsLink" href="#">
738 <?php echo __('Live conn./process chart'); ?>
739 </a>
740 </div>
741 <div class="tabInnerContent">
742 <?php printServerTraffic(); ?>
743 </div>
744 </div>
745 <div id="statustabs_queries" class="clearfloat">
746 <div class="buttonlinks jsfeature">
747 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
748 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
749 <?php echo __('Refresh'); ?>
750 </a>
751 <span class="refreshList" style="display:none;">
752 <label for="id_queryChartRefresh"><?php echo __('Refresh rate: '); ?></label>
753 <?php refreshList('queryChartRefresh'); ?>
754 </span>
755 <a class="tabChart livequeriesLink" href="#">
756 <?php echo __('Live query chart'); ?>
757 </a>
758 </div>
759 <div class="tabInnerContent">
760 <?php printQueryStatistics(); ?>
761 </div>
762 </div>
763 <div id="statustabs_allvars" class="clearfloat">
764 <fieldset id="tableFilter" class="jsfeature">
765 <div class="buttonlinks">
766 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
767 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
768 <?php echo __('Refresh'); ?>
769 </a>
770 </div>
771 <legend>Filters</legend>
772 <div class="formelement">
773 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
774 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
775 </div>
776 <div class="formelement">
777 <input type="checkbox" name="filterAlert" id="filterAlert" />
778 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
779 </div>
780 <div class="formelement">
781 <select id="filterCategory" name="filterCategory">
782 <option value=''><?php echo __('Filter by category...'); ?></option>
783 <?php
784 foreach ($sections as $section_id => $section_name) {
786 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
787 <?php
791 </select>
792 </div>
793 <div class="formelement">
794 <input type="checkbox" name="dontFormat" id="dontFormat" />
795 <label for="dontFormat"><?php echo __('Show unformatted values'); ?></label>
796 </div>
797 </fieldset>
798 <div id="linkSuggestions" class="defaultLinks" style="display:none">
799 <p class="notice"><?php echo __('Related links:'); ?>
800 <?php
801 foreach ($links as $section_name => $section_links) {
802 echo '<span class="status_' . $section_name . '"> ';
803 $i=0;
804 foreach ($section_links as $link_name => $link_url) {
805 if ($i > 0) {
806 echo ', ';
808 if ('doc' == $link_name) {
809 echo PMA_showMySQLDocu($link_url, $link_url);
810 } else {
811 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
813 $i++;
815 echo '</span>';
817 unset($link_url, $link_name, $i);
819 </p>
820 </div>
821 <div class="tabInnerContent">
822 <?php printVariablesTable(); ?>
823 </div>
824 </div>
826 <div id="statustabs_charting" class="jsfeature">
827 <?php printMonitor(); ?>
828 </div>
830 <div id="statustabs_advisor" class="jsfeature">
831 <div class="tabLinks">
832 <img src="themes/dot.gif" class="icon ic_play" alt="" /> <a href="#startAnalyzer"><?php echo __('Run analyzer'); ?></a>
833 <img src="themes/dot.gif" class="icon ic_b_help" alt="" /> <a href="#openAdvisorInstructions"><?php echo __('Instructions'); ?></a>
834 </div>
835 <div class="tabInnerContent clearfloat">
836 </div>
837 <div id="advisorInstructionsDialog" style="display:none;">
838 <?php
839 echo '<p>';
840 echo __('The Advisor system can provide recommendations on server variables by analyzing the server status variables.');
841 echo '</p> <p>';
842 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.');
843 echo '</p> <p>';
844 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.');
845 echo '</p> <p>';
846 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.');
847 echo '</p>';
849 </div>
850 </div>
851 </div>
852 </div>
854 <?php
856 function printQueryStatistics()
858 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
860 $hour_factor = 3600 / $server_status['Uptime'];
862 $total_queries = array_sum($used_queries);
865 <h3 id="serverstatusqueries">
866 <?php
867 /* l10n: Questions is the name of a MySQL Status variable */
868 echo sprintf(__('Questions since startup: %s'), PMA_formatNumber($total_queries, 0)) . ' ';
869 echo PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_Questions');
871 <br />
872 <span>
873 <?php
874 echo '&oslash; ' . __('per hour') . ': ';
875 echo PMA_formatNumber($total_queries * $hour_factor, 0);
876 echo '<br />';
878 echo '&oslash; ' . __('per minute') . ': ';
879 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
880 echo '<br />';
882 if ($total_queries / $server_status['Uptime'] >= 1) {
883 echo '&oslash; ' . __('per second') . ': ';
884 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
887 </span>
888 </h3>
889 <?php
891 // reverse sort by value to show most used statements first
892 arsort($used_queries);
894 $odd_row = true;
895 $count_displayed_rows = 0;
896 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
900 <table id="serverstatusqueriesdetails" class="data sortable noclick">
901 <col class="namecol" />
902 <col class="valuecol" span="3" />
903 <thead>
904 <tr><th><?php echo __('Statements'); ?></th>
905 <th><?php
906 /* l10n: # = Amount of queries */
907 echo __('#');
909 </th>
910 <th>&oslash; <?php echo __('per hour'); ?></th>
911 <th>%</th>
912 </tr>
913 </thead>
914 <tbody>
916 <?php
917 $chart_json = array();
918 $query_sum = array_sum($used_queries);
919 $other_sum = 0;
920 foreach ($used_queries as $name => $value) {
921 $odd_row = !$odd_row;
923 // For the percentage column, use Questions - Connections, because
924 // the number of connections is not an item of the Query types
925 // but is included in Questions. Then the total of the percentages is 100.
926 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
928 // Group together values that make out less than 2% into "Other", but only if we have more than 6 fractions already
929 if ($value < $query_sum * 0.02 && count($chart_json)>6) {
930 $other_sum += $value;
931 } else {
932 $chart_json[$name] = $value;
935 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
936 <th class="name"><?php echo htmlspecialchars($name); ?></th>
937 <td class="value"><?php echo htmlspecialchars(PMA_formatNumber($value, 5, 0, true)); ?></td>
938 <td class="value"><?php echo
939 htmlspecialchars(PMA_formatNumber($value * $hour_factor, 4, 1, true)); ?></td>
940 <td class="value"><?php echo
941 htmlspecialchars(PMA_formatNumber($value * $perc_factor, 0, 2)); ?>%</td>
942 </tr>
943 <?php
946 </tbody>
947 </table>
949 <div id="serverstatusquerieschart">
950 <span style="display:none;">
951 <?php
952 if ($other_sum > 0) {
953 $chart_json[__('Other')] = $other_sum;
956 echo json_encode($chart_json);
958 </span>
959 </div>
960 <?php
963 function printServerTraffic()
965 global $server_status, $PMA_PHP_SELF;
966 global $server_master_status, $server_slave_status, $replication_types;
968 $hour_factor = 3600 / $server_status['Uptime'];
971 * starttime calculation
973 $start_time = PMA_DBI_fetch_value(
974 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
977 <h3><?php
978 echo sprintf(
979 __('Network traffic since startup: %s'),
980 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
983 </h3>
986 <?php
987 echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'),
988 PMA_timespanFormat($server_status['Uptime']),
989 PMA_localisedDate($start_time)) . "\n";
991 </p>
993 <?php
994 if ($server_master_status || $server_slave_status) {
995 echo '<p class="notice">';
996 if ($server_master_status && $server_slave_status) {
997 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
998 } elseif ($server_master_status) {
999 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
1000 } elseif ($server_slave_status) {
1001 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
1003 echo ' ';
1004 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
1005 echo '</p>';
1008 /* if the server works as master or slave in replication process, display useful information */
1009 if ($server_master_status || $server_slave_status) {
1011 <hr class="clearfloat" />
1013 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
1014 <?php
1016 foreach ($replication_types as $type)
1018 if (${"server_{$type}_status"}) {
1019 PMA_replication_print_status_table($type);
1022 unset($types);
1026 <table id="serverstatustraffic" class="data noclick">
1027 <thead>
1028 <tr>
1029 <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>
1030 <th>&oslash; <?php echo __('per hour'); ?></th>
1031 </tr>
1032 </thead>
1033 <tbody>
1034 <tr class="odd">
1035 <th class="name"><?php echo __('Received'); ?></th>
1036 <td class="value"><?php echo
1037 implode(' ',
1038 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
1039 <td class="value"><?php echo
1040 implode(' ',
1041 PMA_formatByteDown(
1042 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
1043 </tr>
1044 <tr class="even">
1045 <th class="name"><?php echo __('Sent'); ?></th>
1046 <td class="value"><?php echo
1047 implode(' ',
1048 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
1049 <td class="value"><?php echo
1050 implode(' ',
1051 PMA_formatByteDown(
1052 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
1053 </tr>
1054 <tr class="odd">
1055 <th class="name"><?php echo __('Total'); ?></th>
1056 <td class="value"><?php echo
1057 implode(' ',
1058 PMA_formatByteDown(
1059 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
1060 ); ?></td>
1061 <td class="value"><?php echo
1062 implode(' ',
1063 PMA_formatByteDown(
1064 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
1065 * $hour_factor, 3, 1)
1066 ); ?></td>
1067 </tr>
1068 </tbody>
1069 </table>
1071 <table id="serverstatusconnections" class="data noclick">
1072 <thead>
1073 <tr>
1074 <th colspan="2"><?php echo __('Connections'); ?></th>
1075 <th>&oslash; <?php echo __('per hour'); ?></th>
1076 <th>%</th>
1077 </tr>
1078 </thead>
1079 <tbody>
1080 <tr class="odd">
1081 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
1082 <td class="value"><?php echo
1083 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
1084 <td class="value">--- </td>
1085 <td class="value">--- </td>
1086 </tr>
1087 <tr class="even">
1088 <th class="name"><?php echo __('Failed attempts'); ?></th>
1089 <td class="value"><?php echo
1090 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
1091 <td class="value"><?php echo
1092 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
1093 4, 2, true); ?></td>
1094 <td class="value"><?php echo
1095 $server_status['Connections'] > 0
1096 ? PMA_formatNumber(
1097 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
1098 0, 2, true) . '%'
1099 : '--- '; ?></td>
1100 </tr>
1101 <tr class="odd">
1102 <th class="name"><?php echo __('Aborted'); ?></th>
1103 <td class="value"><?php echo
1104 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
1105 <td class="value"><?php echo
1106 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
1107 4, 2, true); ?></td>
1108 <td class="value"><?php echo
1109 $server_status['Connections'] > 0
1110 ? PMA_formatNumber(
1111 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
1112 0, 2, true) . '%'
1113 : '--- '; ?></td>
1114 </tr>
1115 <tr class="even">
1116 <th class="name"><?php echo __('Total'); ?></th>
1117 <td class="value"><?php echo
1118 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
1119 <td class="value"><?php echo
1120 PMA_formatNumber($server_status['Connections'] * $hour_factor,
1121 4, 2); ?></td>
1122 <td class="value"><?php echo
1123 PMA_formatNumber(100, 0, 2); ?>%</td>
1124 </tr>
1125 </tbody>
1126 </table>
1127 <?php
1129 $url_params = array();
1131 if (! empty($_REQUEST['full'])) {
1132 $sql_query = 'SHOW FULL PROCESSLIST';
1133 $url_params['full'] = 1;
1134 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
1135 } else {
1136 $sql_query = 'SHOW PROCESSLIST';
1137 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
1139 $result = PMA_DBI_query($sql_query);
1142 * Displays the page
1145 <table id="tableprocesslist" class="data clearfloat noclick">
1146 <thead>
1147 <tr>
1148 <th><?php echo __('Processes'); ?></th>
1149 <th><?php echo __('ID'); ?></th>
1150 <th><?php echo __('User'); ?></th>
1151 <th><?php echo __('Host'); ?></th>
1152 <th><?php echo __('Database'); ?></th>
1153 <th><?php echo __('Command'); ?></th>
1154 <th><?php echo __('Time'); ?></th>
1155 <th><?php echo __('Status'); ?></th>
1156 <th><?php
1157 echo __('SQL query');
1158 if (! PMA_DRIZZLE) {
1160 <a href="<?php echo $full_text_link; ?>"
1161 title="<?php echo empty($full) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>">
1162 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (empty($_REQUEST['full']) ? 'full' : 'partial'); ?>text.png"
1163 alt="<?php echo empty($_REQUEST['full']) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>" />
1164 </a>
1165 <?php } ?>
1166 </th>
1167 </tr>
1168 </thead>
1169 <tbody>
1170 <?php
1171 $odd_row = true;
1172 while ($process = PMA_DBI_fetch_assoc($result)) {
1173 if (PMA_DRIZZLE) {
1174 // Drizzle uses uppercase keys
1175 foreach ($process as $k => $v) {
1176 $k = $k !== 'DB'
1177 ? ucfirst(strtolower($k))
1178 : 'db';
1179 $process[$k] = $v;
1182 $url_params['kill'] = $process['Id'];
1183 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
1185 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
1186 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
1187 <td class="value"><?php echo $process['Id']; ?></td>
1188 <td><?php echo $process['User']; ?></td>
1189 <td><?php echo $process['Host']; ?></td>
1190 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
1191 <td><?php echo $process['Command']; ?></td>
1192 <td class="value"><?php echo $process['Time']; ?></td>
1193 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
1194 <td>
1195 <?php
1196 if (empty($process['Info'])) {
1197 echo '---';
1198 } else {
1199 if (empty($_REQUEST['full']) && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
1200 echo htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
1201 } else {
1202 echo PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
1206 </td>
1207 </tr>
1208 <?php
1209 $odd_row = ! $odd_row;
1212 </tbody>
1213 </table>
1214 <?php
1217 function printVariablesTable()
1219 global $server_status, $server_variables, $allocationMap, $links;
1221 * Messages are built using the message name
1223 $strShowStatus = array(
1224 'Aborted_clients' => __('The number of connections that were aborted because the client died without closing the connection properly.'),
1225 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
1226 '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.'),
1227 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
1228 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
1229 '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.'),
1230 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
1231 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
1232 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
1233 '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.'),
1234 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
1235 'Flush_commands' => __('The number of executed FLUSH statements.'),
1236 'Handler_commit' => __('The number of internal COMMIT statements.'),
1237 'Handler_delete' => __('The number of times a row was deleted from a table.'),
1238 '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.'),
1239 '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.'),
1240 '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.'),
1241 '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.'),
1242 '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.'),
1243 '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.'),
1244 '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.'),
1245 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
1246 'Handler_update' => __('The number of requests to update a row in a table.'),
1247 'Handler_write' => __('The number of requests to insert a row in a table.'),
1248 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
1249 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
1250 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
1251 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
1252 '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.'),
1253 '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.'),
1254 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
1255 '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.'),
1256 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
1257 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
1258 '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.'),
1259 '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.'),
1260 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
1261 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
1262 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
1263 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
1264 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
1265 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
1266 'Innodb_data_reads' => __('The total number of data reads.'),
1267 'Innodb_data_writes' => __('The total number of data writes.'),
1268 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
1269 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
1270 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
1271 '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.'),
1272 'Innodb_log_write_requests' => __('The number of log write requests.'),
1273 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
1274 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
1275 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
1276 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
1277 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
1278 'Innodb_pages_created' => __('The number of pages created.'),
1279 '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.'),
1280 'Innodb_pages_read' => __('The number of pages read.'),
1281 'Innodb_pages_written' => __('The number of pages written.'),
1282 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
1283 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
1284 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
1285 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
1286 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
1287 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
1288 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
1289 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
1290 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
1291 '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.'),
1292 '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.'),
1293 '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.'),
1294 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
1295 '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.'),
1296 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
1297 'Key_writes' => __('The number of physical writes of a key block to disk.'),
1298 '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.'),
1299 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
1300 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
1301 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
1302 'Open_files' => __('The number of files that are open.'),
1303 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
1304 'Open_tables' => __('The number of tables that are open.'),
1305 '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.'),
1306 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
1307 'Qcache_hits' => __('The number of cache hits.'),
1308 'Qcache_inserts' => __('The number of queries added to the cache.'),
1309 '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.'),
1310 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
1311 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
1312 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
1313 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
1314 '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.'),
1315 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
1316 '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.)'),
1317 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
1318 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
1319 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
1320 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
1321 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
1322 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
1323 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
1324 '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.'),
1325 'Sort_range' => __('The number of sorts that were done with ranges.'),
1326 'Sort_rows' => __('The number of sorted rows.'),
1327 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
1328 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
1329 '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.'),
1330 '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.'),
1331 'Threads_connected' => __('The number of currently open connections.'),
1332 '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.)'),
1333 'Threads_running' => __('The number of threads that are not sleeping.')
1337 * define some alerts
1339 // name => max value before alert
1340 $alerts = array(
1341 // lower is better
1342 // variable => max value
1343 'Aborted_clients' => 0,
1344 'Aborted_connects' => 0,
1346 'Binlog_cache_disk_use' => 0,
1348 'Created_tmp_disk_tables' => 0,
1350 'Handler_read_rnd' => 0,
1351 'Handler_read_rnd_next' => 0,
1353 'Innodb_buffer_pool_pages_dirty' => 0,
1354 'Innodb_buffer_pool_reads' => 0,
1355 'Innodb_buffer_pool_wait_free' => 0,
1356 'Innodb_log_waits' => 0,
1357 'Innodb_row_lock_time_avg' => 10, // ms
1358 'Innodb_row_lock_time_max' => 50, // ms
1359 'Innodb_row_lock_waits' => 0,
1361 'Slow_queries' => 0,
1362 'Delayed_errors' => 0,
1363 'Select_full_join' => 0,
1364 'Select_range_check' => 0,
1365 'Sort_merge_passes' => 0,
1366 'Opened_tables' => 0,
1367 'Table_locks_waited' => 0,
1368 'Qcache_lowmem_prunes' => 0,
1370 'Qcache_free_blocks' => $server_status['Qcache_total_blocks'] / 5,
1371 'Slow_launch_threads' => 0,
1373 // depends on Key_read_requests
1374 // normaly lower then 1:0.01
1375 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
1376 // depends on Key_write_requests
1377 // normaly nearly 1:1
1378 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
1380 'Key_buffer_fraction' => 0.5,
1382 // alert if more than 95% of thread cache is in use
1383 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
1385 // higher is better
1386 // variable => min value
1387 //'Handler read key' => '> ',
1391 <table class="data sortable noclick" id="serverstatusvariables">
1392 <col class="namecol" />
1393 <col class="valuecol" />
1394 <col class="descrcol" />
1395 <thead>
1396 <tr>
1397 <th><?php echo __('Variable'); ?></th>
1398 <th><?php echo __('Value'); ?></th>
1399 <th><?php echo __('Description'); ?></th>
1400 </tr>
1401 </thead>
1402 <tbody>
1403 <?php
1405 $odd_row = false;
1406 foreach ($server_status as $name => $value) {
1407 $odd_row = !$odd_row;
1409 <tr class="<?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_' . $allocationMap[$name]:''; ?>">
1410 <th class="name"><?php echo htmlspecialchars(str_replace('_', ' ', $name)) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1411 </th>
1412 <td class="value"><span class="formatted"><?php
1413 if (isset($alerts[$name])) {
1414 if ($value > $alerts[$name]) {
1415 echo '<span class="attention">';
1416 } else {
1417 echo '<span class="allfine">';
1420 if ('%' === substr($name, -1, 1)) {
1421 echo htmlspecialchars(PMA_formatNumber($value, 0, 2)) . ' %';
1422 } elseif (strpos($name, 'Uptime')!==FALSE) {
1423 echo htmlspecialchars(PMA_timespanFormat($value));
1424 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1425 echo htmlspecialchars(PMA_formatNumber($value, 3, 1));
1426 } elseif (is_numeric($value) && $value == (int) $value) {
1427 echo htmlspecialchars(PMA_formatNumber($value, 3, 0));
1428 } elseif (is_numeric($value)) {
1429 echo htmlspecialchars(PMA_formatNumber($value, 3, 1));
1430 } else {
1431 echo htmlspecialchars($value);
1433 if (isset($alerts[$name])) {
1434 echo '</span>';
1436 ?></span><span style="display:none;" class="original"><?php echo $value; ?></span>
1437 </td>
1438 <td class="descr">
1439 <?php
1440 if (isset($strShowStatus[$name ])) {
1441 echo $strShowStatus[$name];
1444 if (isset($links[$name])) {
1445 foreach ($links[$name] as $link_name => $link_url) {
1446 if ('doc' == $link_name) {
1447 echo PMA_showMySQLDocu($link_url, $link_url);
1448 } else {
1449 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1450 "\n";
1453 unset($link_url, $link_name);
1456 </td>
1457 </tr>
1458 <?php
1461 </tbody>
1462 </table>
1463 <?php
1466 function printMonitor()
1468 global $server_status, $server_db_isLocal;
1470 <div class="tabLinks" style="display:none;">
1471 <a href="#pauseCharts">
1472 <img src="themes/dot.gif" class="icon ic_play" alt="" />
1473 <?php echo __('Start Monitor'); ?>
1474 </a>
1475 <a href="#settingsPopup" rel="popupLink" style="display:none;">
1476 <img src="themes/dot.gif" class="icon ic_s_cog" alt="" />
1477 <?php echo __('Settings'); ?>
1478 </a>
1479 <a href="#monitorInstructionsDialog">
1480 <img src="themes/dot.gif" class="icon ic_b_help" alt="" />
1481 <?php echo __('Instructions/Setup'); ?>
1482 </a>
1483 <a href="#endChartEditMode" style="display:none;">
1484 <img src="themes/dot.gif" class="icon ic_s_okay" alt="" />
1485 <?php echo __('Done rearranging/editing charts'); ?>
1486 </a>
1487 </div>
1489 <div class="popupContent settingsPopup">
1490 <a href="#addNewChart">
1491 <img src="themes/dot.gif" class="icon ic_b_chart" alt="" />
1492 <?php echo __('Add chart'); ?>
1493 </a>
1494 <a href="#rearrangeCharts"><img class="icon ic_b_tblops" src="themes/dot.gif" width="16" height="16" alt="" /><?php echo __('Rearrange/edit charts'); ?></a>
1495 <div class="clearfloat paddingtop"></div>
1496 <div class="floatleft">
1497 <?php
1498 echo __('Refresh rate') . '<br />';
1499 refreshList('gridChartRefresh', 5, Array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200));
1500 ?><br />
1501 </div>
1502 <div class="floatleft">
1503 <?php echo __('Chart columns'); ?> <br />
1504 <select name="chartColumns">
1505 <option>1</option>
1506 <option>2</option>
1507 <option>3</option>
1508 <option>4</option>
1509 <option>5</option>
1510 <option>6</option>
1511 <option>7</option>
1512 <option>8</option>
1513 <option>9</option>
1514 <option>10</option>
1515 </select>
1516 </div>
1518 <div class="clearfloat paddingtop">
1519 <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/>
1520 <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>
1521 </div>
1522 </div>
1524 <div id="monitorInstructionsDialog" title="<?php echo __('Monitor Instructions'); ?>" style="display:none;">
1525 <?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%'); ?>
1526 <?php if (PMA_MYSQL_INT_VERSION < 50106) { ?>
1528 <img class="icon ic_s_attention" src="themes/dot.gif" alt="" />
1529 <?php
1530 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.');
1532 </p>
1533 <?php
1534 } else {
1536 <p></p>
1537 <img class="ajaxIcon" src="<?php echo $GLOBALS['pmaThemeImage']; ?>ajax_clock_small.gif" alt="Loading" />
1538 <div class="ajaxContent"></div>
1539 <div class="monitorUse" style="display:none;">
1540 <p></p>
1541 <?php
1542 echo '<strong>';
1543 echo __('Using the monitor:');
1544 echo '</strong><p>';
1545 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.');
1546 echo '</p><p>';
1547 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.');
1548 echo '</p>';
1551 <img class="icon ic_s_attention" src="themes/dot.gif" alt="" />
1552 <?php
1553 echo '<strong>';
1554 echo __('Please note:');
1555 echo '</strong><br />';
1556 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.');
1558 </p>
1559 </div>
1560 <?php } ?>
1561 </div>
1563 <div id="addChartDialog" title="Add chart" style="display:none;">
1564 <div id="tabGridVariables">
1565 <p><input type="text" name="chartTitle" value="<?php echo __('Chart Title'); ?>" /></p>
1567 <input type="radio" name="chartType" value="preset" id="chartPreset" />
1568 <label for="chartPreset"><?php echo __('Preset chart'); ?></label>
1569 <select name="presetCharts"></select><br/>
1571 <input type="radio" name="chartType" value="variable" id="chartStatusVar" checked="checked" />
1572 <label for="chartStatusVar"><?php echo __('Status variable(s)'); ?></label><br/>
1573 <div id="chartVariableSettings">
1574 <label for="chartSeries"><?php echo __('Select series:'); ?></label><br />
1575 <select id="chartSeries" name="varChartList" size="1">
1576 <option><?php echo __('Commonly monitored'); ?></option>
1577 <option>Processes</option>
1578 <option>Questions</option>
1579 <option>Connections</option>
1580 <option>Bytes_sent</option>
1581 <option>Bytes_received</option>
1582 <option>Threads_connected</option>
1583 <option>Created_tmp_disk_tables</option>
1584 <option>Handler_read_first</option>
1585 <option>Innodb_buffer_pool_wait_free</option>
1586 <option>Key_reads</option>
1587 <option>Open_tables</option>
1588 <option>Select_full_join</option>
1589 <option>Slow_queries</option>
1590 </select><br />
1591 <label for="variableInput"><?php echo __('or type variable name:'); ?> </label>
1592 <input type="text" name="variableInput" id="variableInput" />
1593 <p></p>
1594 <input type="checkbox" name="differentialValue" id="differentialValue" value="differential" checked="checked" />
1595 <label for="differentialValue"><?php echo __('Display as differential value'); ?></label><br />
1596 <input type="checkbox" id="useDivisor" name="useDivisor" value="1" />
1597 <label for="useDivisor"><?php echo __('Apply a divisor'); ?></label>
1598 <span class="divisorInput" style="display:none;">
1599 <input type="text" name="valueDivisor" size="4" value="1" />
1600 (<a href="#kibDivisor"><?php echo __('KiB'); ?></a>, <a href="#mibDivisor"><?php echo __('MiB'); ?></a>)
1601 </span><br />
1603 <input type="checkbox" id="useUnit" name="useUnit" value="1" />
1604 <label for="useUnit"><?php echo __('Append unit to data values'); ?></label>
1606 <span class="unitInput" style="display:none;">
1607 <input type="text" name="valueUnit" size="4" value="" />
1608 </span>
1610 <a href="#submitAddSeries"><b><?php echo __('Add this series'); ?></b></a>
1611 <span id="clearSeriesLink" style="display:none;">
1612 | <a href="#submitClearSeries"><?php echo __('Clear series'); ?></a>
1613 </span>
1614 </p>
1615 <?php echo __('Series in Chart:'); ?><br/>
1616 <span id="seriesPreview">
1617 <i><?php echo __('None'); ?></i>
1618 </span>
1619 </div>
1620 </div>
1621 </div>
1623 <!-- For generic use -->
1624 <div id="emptyDialog" title="Dialog" style="display:none;">
1625 </div>
1627 <div id="logAnalyseDialog" title="<?php echo __('Log statistics'); ?>" style="display:none;">
1628 <p> <?php echo __('Selected time range:'); ?>
1629 <input type="text" name="dateStart" class="datetimefield" value="" /> -
1630 <input type="text" name="dateEnd" class="datetimefield" value="" /></p>
1631 <input type="checkbox" id="limitTypes" value="1" checked="checked" />
1632 <label for="limitTypes">
1633 <?php echo __('Only retrieve SELECT,INSERT,UPDATE and DELETE Statements'); ?>
1634 </label>
1635 <br/>
1636 <input type="checkbox" id="removeVariables" value="1" checked="checked" />
1637 <label for="removeVariables">
1638 <?php echo __('Remove variable data in INSERT statements for better grouping'); ?>
1639 </label>
1641 <?php
1642 echo '<p>';
1643 echo __('Choose from which log you want the statistics to be generated from.');
1644 echo '</p><p>';
1645 echo __('Results are grouped by query text.');
1646 echo '</p>';
1648 </div>
1650 <div id="queryAnalyzerDialog" title="<?php echo __('Query analyzer'); ?>" style="display:none;">
1651 <textarea id="sqlquery"> </textarea>
1652 <p></p>
1653 <div class="placeHolder"></div>
1654 </div>
1656 <table border="0" class="clearfloat" id="chartGrid">
1658 </table>
1659 <div id="logTable">
1660 <br/>
1661 </div>
1663 <script type="text/javascript">
1664 variableNames = [ <?php
1665 $i=0;
1666 foreach ($server_status as $name=>$value) {
1667 if (is_numeric($value)) {
1668 if ($i++ > 0) {
1669 echo ", ";
1671 echo "'" . $name . "'";
1674 ?> ];
1675 </script>
1676 <?php
1679 /* Builds a <select> list for refresh rates */
1680 function refreshList($name, $defaultRate=5, $refreshRates=Array(1, 2, 5, 10, 20, 40, 60, 120, 300, 600))
1683 <select name="<?php echo $name; ?>" id="id_<?php echo $name; ?>">
1684 <?php
1685 foreach ($refreshRates as $rate) {
1686 $selected = ($rate == $defaultRate)?' selected="selected"':'';
1688 if ($rate<60) {
1689 echo '<option value="' . $rate . '"' . $selected . '>' . sprintf(_ngettext('%d second', '%d seconds', $rate), $rate) . '</option>';
1690 } else {
1691 echo '<option value="' . $rate . '"' . $selected . '>' . sprintf(_ngettext('%d minute', '%d minutes', $rate/60), $rate/60) . '</option>';
1695 </select>
1696 <?php
1700 * cleanup of some deprecated values
1702 * @param array &$server_status
1704 function cleanDeprecated(&$server_status)
1706 $deprecated = array(
1707 'Com_prepare_sql' => 'Com_stmt_prepare',
1708 'Com_execute_sql' => 'Com_stmt_execute',
1709 'Com_dealloc_sql' => 'Com_stmt_close',
1712 foreach ($deprecated as $old => $new) {
1713 if (isset($server_status[$old]) && isset($server_status[$new])) {
1714 unset($server_status[$old]);
1720 * Sends the footer
1722 require './libraries/footer.inc.php';