Remove unused function from most export plugins: PMA_exportComment
[phpmyadmin.git] / server_status.php
blob303a87bfe2633d149739d8d6fd48613ad22dc7ef
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 * Function to output refresh rate selection.
26 function PMA_choose_refresh_rate() {
27 echo '<option value="5">' . __('Refresh rate') . '</option>';
28 foreach (array(1, 2, 5, 20, 40, 60, 120, 300, 600) as $rate) {
29 if ($rate % 60 == 0) {
30 $minrate = $rate / 60;
31 echo '<option value="' . $rate . '">' . sprintf(_ngettext('%d minute', '%d minutes', $minrate), $minrate) . '</option>';
32 } else {
33 echo '<option value="' . $rate . '">' . sprintf(_ngettext('%d second', '%d seconds', $rate), $rate) . '</option>';
38 /**
39 * Ajax request
42 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
43 // Send with correct charset
44 header('Content-Type: text/html; charset=UTF-8');
46 // real-time charting data
47 if (isset($_REQUEST['chart_data'])) {
48 switch($_REQUEST['type']) {
49 case 'proc':
50 $c = PMA_DBI_fetch_result('SHOW GLOBAL STATUS WHERE Variable_name="Connections"', 0, 1);
51 $result = PMA_DBI_query('SHOW PROCESSLIST');
52 $num_procs = PMA_DBI_num_rows($result);
54 $ret = array(
55 'x' => microtime(true)*1000,
56 'y_proc' => $num_procs,
57 'y_conn' => $c['Connections']
60 exit(json_encode($ret));
61 case 'queries':
62 $queries = PMA_DBI_fetch_result('SHOW GLOBAL STATUS WHERE Variable_name LIKE "Com_%" AND Value>0', 0, 1);
63 cleanDeprecated($queries);
64 // admin commands are not queries
65 unset($queries['Com_admin_commands']);
67 $sum = array_sum($queries);
68 $ret = array(
69 'x' => microtime(true)*1000,
70 'y' => $sum,
71 'pointInfo' => $queries
74 exit(json_encode($ret));
75 case 'traffic':
76 $traffic = PMA_DBI_fetch_result('SHOW GLOBAL STATUS WHERE Variable_name="Bytes_received" OR Variable_name="Bytes_sent"', 0, 1);
78 $ret = array(
79 'x' => microtime(true)*1000,
80 'y_sent' => $traffic['Bytes_sent'],
81 'y_received' => $traffic['Bytes_received']
84 exit(json_encode($ret));
91 /**
92 * Replication library
94 require './libraries/replication.inc.php';
95 require_once './libraries/replication_gui.lib.php';
97 /**
98 * JS Includes
101 $GLOBALS['js_include'][] = 'server_status.js';
102 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
103 $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
104 $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
105 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
106 /* Files required for chart exporting */
107 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
108 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
109 $GLOBALS['js_include'][] = 'canvg/canvg.js';
110 $GLOBALS['js_include'][] = 'canvg/rgbcolor.js';
114 * flush status variables if requested
116 if (isset($_REQUEST['flush'])) {
117 $_flush_commands = array(
118 'STATUS',
119 'TABLES',
120 'QUERY CACHE',
123 if (in_array($_REQUEST['flush'], $_flush_commands)) {
124 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
126 unset($_flush_commands);
130 * Kills a selected process
132 if (!empty($_REQUEST['kill'])) {
133 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
134 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
135 } else {
136 $message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
138 $message->addParam($_REQUEST['kill']);
139 //$message->display();
145 * get status from server
147 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
150 * for some calculations we require also some server settings
152 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
155 * cleanup of some deprecated values
157 cleanDeprecated($server_status);
160 * calculate some values
162 // Key_buffer_fraction
163 if (isset($server_status['Key_blocks_unused'])
164 && isset($server_variables['key_cache_block_size'])
165 && isset($server_variables['key_buffer_size'])) {
166 $server_status['Key_buffer_fraction_%'] =
168 - $server_status['Key_blocks_unused']
169 * $server_variables['key_cache_block_size']
170 / $server_variables['key_buffer_size']
171 * 100;
172 } elseif (
173 isset($server_status['Key_blocks_used'])
174 && isset($server_variables['key_buffer_size'])) {
175 $server_status['Key_buffer_fraction_%'] =
176 $server_status['Key_blocks_used']
177 * 1024
178 / $server_variables['key_buffer_size'];
181 // Ratio for key read/write
182 if (isset($server_status['Key_writes'])
183 && isset($server_status['Key_write_requests'])
184 && $server_status['Key_write_requests'] > 0)
185 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
187 if (isset($server_status['Key_reads'])
188 && isset($server_status['Key_read_requests'])
189 && $server_status['Key_read_requests'] > 0)
190 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
192 // Threads_cache_hitrate
193 if (isset($server_status['Threads_created'])
194 && isset($server_status['Connections'])
195 && $server_status['Connections'] > 0) {
196 $server_status['Threads_cache_hitrate_%'] =
198 - $server_status['Threads_created']
199 / $server_status['Connections']
200 * 100;
203 // Format Uptime_since_flush_status : show as days, hours, minutes, seconds
204 if (isset($server_status['Uptime_since_flush_status'])) {
205 $server_status['Uptime_since_flush_status'] = PMA_timespanFormat($server_status['Uptime_since_flush_status']);
209 * split variables in sections
211 $allocations = array(
212 // variable name => section
213 // variable names match when they begin with the given string
215 'Com_' => 'com',
216 'Innodb_' => 'innodb',
217 'Ndb_' => 'ndb',
218 'Handler_' => 'handler',
219 'Qcache_' => 'qcache',
220 'Threads_' => 'threads',
221 'Slow_launch_threads' => 'threads',
223 'Binlog_cache_' => 'binlog_cache',
224 'Created_tmp_' => 'created_tmp',
225 'Key_' => 'key',
227 'Delayed_' => 'delayed',
228 'Not_flushed_delayed_rows' => 'delayed',
230 'Flush_commands' => 'query',
231 'Last_query_cost' => 'query',
232 'Slow_queries' => 'query',
233 'Queries' => 'query',
234 'Prepared_stmt_count' => 'query',
236 'Select_' => 'select',
237 'Sort_' => 'sort',
239 'Open_tables' => 'table',
240 'Opened_tables' => 'table',
241 'Open_table_definitions' => 'table',
242 'Opened_table_definitions' => 'table',
243 'Table_locks_' => 'table',
245 'Rpl_status' => 'repl',
246 'Slave_' => 'repl',
248 'Tc_' => 'tc',
250 'Ssl_' => 'ssl',
252 'Open_files' => 'files',
253 'Open_streams' => 'files',
254 'Opened_files' => 'files',
257 $sections = array(
258 // section => section name (description)
259 'com' => 'Com',
260 'query' => __('SQL query'),
261 'innodb' => 'InnoDB',
262 'ndb' => 'NDB',
263 'handler' => __('Handler'),
264 'qcache' => __('Query cache'),
265 'threads' => __('Threads'),
266 'binlog_cache' => __('Binary log'),
267 'created_tmp' => __('Temporary data'),
268 'delayed' => __('Delayed inserts'),
269 'key' => __('Key cache'),
270 'select' => __('Joins'),
271 'repl' => __('Replication'),
272 'sort' => __('Sorting'),
273 'table' => __('Tables'),
274 'tc' => __('Transaction coordinator'),
275 'files' => __('Files'),
276 'ssl' => 'SSL',
280 * define some needfull links/commands
282 // variable or section name => (name => url)
283 $links = array();
285 $links['table'][__('Flush (close) all tables')]
286 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
287 $links['table'][__('Show open tables')]
288 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
289 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
291 if ($server_master_status) {
292 $links['repl'][__('Show slave hosts')]
293 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
294 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
295 $links['repl'][__('Show master status')] = '#replication_master';
297 if ($server_slave_status) {
298 $links['repl'][__('Show slave status')] = '#replication_slave';
301 $links['repl']['doc'] = 'replication';
303 $links['qcache'][__('Flush query cache')]
304 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
305 PMA_generate_common_url();
306 $links['qcache']['doc'] = 'query_cache';
308 //$links['threads'][__('Show processes')]
309 // = 'server_processlist.php?' . PMA_generate_common_url();
310 $links['threads']['doc'] = 'mysql_threads';
312 $links['key']['doc'] = 'myisam_key_cache';
314 $links['binlog_cache']['doc'] = 'binary_log';
316 $links['Slow_queries']['doc'] = 'slow_query_log';
318 $links['innodb'][__('Variables')]
319 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
320 $links['innodb'][__('InnoDB Status')]
321 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
322 PMA_generate_common_url();
323 $links['innodb']['doc'] = 'innodb';
326 // Variable to contain all com_ variables
327 $used_queries = array();
329 // Variable to map variable names to their respective section name (used for js category filtering)
330 $allocationMap = array();
332 // sort vars into arrays
333 foreach ($server_status as $name => $value) {
334 foreach ($allocations as $filter => $section) {
335 if (strpos($name, $filter) !== false) {
336 $allocationMap[$name] = $section;
337 if ($section == 'com' && $value > 0) $used_queries[$name] = $value;
338 break; // Only exits inner loop
343 // admin commands are not queries (e.g. they include COM_PING, which is excluded from $server_status['Questions'])
344 unset($used_queries['Com_admin_commands']);
346 /* Ajax request refresh */
347 if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
348 switch($_REQUEST['show']) {
349 case 'query_statistics':
350 printQueryStatistics();
351 exit();
352 case 'server_traffic':
353 printServerTraffic();
354 exit();
355 case 'variables_table':
356 // Prints the variables table
357 printVariablesTable();
358 exit();
360 default:
361 break;
366 * start output
370 * Does the common work
372 require './libraries/server_common.inc.php';
376 * Displays the links
378 require './libraries/server_links.inc.php';
381 <script type="text/javascript">
382 pma_token = '<?php echo $_SESSION[' PMA_token ']; ?>';
383 url_query = '<?php echo str_replace('&amp;','&',$url_query);?>';
384 pma_theme_image = '<?php echo $GLOBALS['pmaThemeImage']; ?>';
385 </script>
386 <div id="serverstatus">
387 <h2><?php
390 * Displays the sub-page heading
392 if ($GLOBALS['cfg']['MainPageIconic']) {
393 echo '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_status.png" width="16" height="16" alt="" />';
396 echo __('Runtime Information');
398 ?></h2>
399 <div id="serverStatusTabs">
400 <ul>
401 <li><a href="#statustabs_traffic"><?php echo __('Server traffic'); ?></a></li>
402 <li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
403 <li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
404 </ul>
406 <div id="statustabs_traffic">
407 <div class="statuslinks">
408 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&amp;' . PMA_generate_common_url(); ?>" >
409 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
410 <?php echo __('Refresh'); ?>
411 </a>
412 <span class="refreshList" style="display:none;">
413 <label for="trafficChartRefresh"><?php echo __('Refresh rate:'); ?></label>
414 <select name="trafficChartRefresh" style="display:none;">
415 <?php PMA_choose_refresh_rate(); ?>
416 </select>
417 </span>
419 <a class="tabChart livetrafficLink" href="#">
420 <?php echo __('Live traffic chart'); ?>
421 </a>
422 <a class="tabChart liveconnectionsLink" href="#">
423 <?php echo __('Live conn./process chart'); ?>
426 </a>
427 </div>
428 <div class="tabInnerContent">
429 <?php printServerTraffic(); ?>
430 </div>
431 </div>
432 <div id="statustabs_queries">
433 <div class="statuslinks">
434 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
435 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
436 <?php echo __('Refresh'); ?>
437 </a>
438 <span class="refreshList" style="display:none;">
439 <label for="queryChartRefresh"><?php echo __('Refresh rate:'); ?></label>
440 <select name="queryChartRefresh" style="display:none;">
441 <?php PMA_choose_refresh_rate(); ?>
442 </select>
443 </span>
444 <a class="tabChart livequeriesLink" href="#">
445 <?php echo __('Live query chart'); ?>
446 </a>
447 </div>
448 <div class="tabInnerContent">
449 <?php printQueryStatistics(); ?>
450 </div>
451 </div>
452 <div id="statustabs_allvars">
453 <fieldset id="tableFilter">
454 <div class="statuslinks">
455 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
456 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
457 <?php echo __('Refresh'); ?>
458 </a>
459 </div>
460 <legend>Filters</legend>
461 <div class="formelement">
462 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
463 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
464 </div>
465 <div class="formelement">
466 <input type="checkbox" name="filterAlert" id="filterAlert">
467 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
468 </div>
469 <div class="formelement">
470 <select id="filterCategory" name="filterCategory">
471 <option value=''><?php echo __('Filter by category...'); ?></option>
472 <?php
473 foreach($sections as $section_id => $section_name) {
475 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
476 <?php
480 </select>
481 </div>
482 </fieldset>
483 <div id="linkSuggestions" class="defaultLinks" style="display:none">
484 <p><?php echo __('Related links:'); ?>
485 <?php
486 foreach ($links as $section_name => $section_links) {
487 echo '<span class="status_'.$section_name.'"> ';
488 $i=0;
489 foreach ($section_links as $link_name => $link_url) {
490 if ($i > 0) echo ', ';
491 if ('doc' == $link_name) {
492 echo PMA_showMySQLDocu($link_url, $link_url);
493 } else {
494 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
496 $i++;
498 echo '</span>';
500 unset($link_url, $link_name, $i);
502 </p>
503 </div>
504 <div class="tabInnerContent">
505 <?php printVariablesTable(); ?>
506 </div>
507 </div>
508 </div>
509 </div>
511 <?php
513 function printQueryStatistics() {
514 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
516 $hour_factor = 3600 / $server_status['Uptime'];
518 $total_queries = array_sum($used_queries);
521 <h3 id="serverstatusqueries">
522 <?php
523 echo sprintf('Queries since startup: %s',PMA_formatNumber($total_queries, 0));
525 <br>
526 <span>
527 <?php
528 echo '&oslash;'.__('per hour').':';
529 echo PMA_formatNumber($total_queries * $hour_factor, 0);
530 echo '<br>';
532 echo '&oslash;'.__('per minute').':';
533 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
534 echo '<br>';
536 if ($total_queries / $server_status['Uptime'] >= 1) {
537 echo '&oslash;'.__('per second').':';
538 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
540 </span><br>
541 </h3>
542 <?php
545 // reverse sort by value to show most used statements first
546 arsort($used_queries);
548 $odd_row = true;
549 $count_displayed_rows = 0;
550 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
554 <table id="serverstatusqueriesdetails" class="data sortable">
555 <col class="namecol" />
556 <col class="valuecol" span="3" />
557 <thead>
558 <tr><th><?php echo __('Query type'); ?></th>
559 <th><?php
560 /* l10n: # = Amount of queries */
561 echo __('#');
563 <th>&oslash; <?php echo __('per hour'); ?></th>
564 <th>%</th>
565 </tr>
566 </thead>
567 <tbody>
569 <?php
570 $chart_json = array();
571 $query_sum = array_sum($used_queries);
572 $other_sum = 0;
573 foreach ($used_queries as $name => $value) {
574 $odd_row = !$odd_row;
576 // For the percentage column, use Questions - Connections, because
577 // the number of connections is not an item of the Query types
578 // but is included in Questions. Then the total of the percentages is 100.
579 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
581 if ($value < $query_sum * 0.02)
582 $other_sum += $value;
583 else $chart_json[$name] = $value;
585 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
586 <th class="name"><?php echo htmlspecialchars($name); ?></th>
587 <td class="value"><?php echo PMA_formatNumber($value, 5, 0, true); ?></td>
588 <td class="value"><?php echo
589 PMA_formatNumber($value * $hour_factor, 4, 1, true); ?></td>
590 <td class="value"><?php echo
591 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
592 </tr>
593 <?php
596 </tbody>
597 </table>
599 <div id="serverstatusquerieschart">
600 <?php
601 if ($other_sum > 0)
602 $chart_json[__('Other')] = $other_sum;
604 echo json_encode($chart_json);
606 </div>
607 <?php
610 function printServerTraffic() {
611 global $server_status,$PMA_PHP_SELF;
612 global $server_master_status, $server_slave_status, $replication_types;
614 $hour_factor = 3600 / $server_status['Uptime'];
617 * starttime calculation
619 $start_time = PMA_DBI_fetch_value(
620 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
623 <h3><?php
624 echo sprintf(
625 __('Network traffic since startup: %s'),
626 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
629 </h3>
632 <?php
633 echo sprintf(__('This MySQL server has been running for %s. It started up on %s.'),
634 PMA_timespanFormat($server_status['Uptime']),
635 PMA_localisedDate($start_time)) . "\n";
637 </p>
639 <?php
640 if ($server_master_status || $server_slave_status) {
641 echo '<p>';
642 if ($server_master_status && $server_slave_status) {
643 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
644 } elseif ($server_master_status) {
645 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
646 } elseif ($server_slave_status) {
647 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
649 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
650 echo '</p>';
653 /* if the server works as master or slave in replication process, display useful information */
654 if ($server_master_status || $server_slave_status)
657 <hr class="clearfloat" />
659 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
660 <?php
662 foreach ($replication_types as $type)
664 if (${"server_{$type}_status"}) {
665 PMA_replication_print_status_table($type);
668 unset($types);
672 <table id="serverstatustraffic" class="data">
673 <thead>
674 <tr>
675 <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>
676 <th>&oslash; <?php echo __('per hour'); ?></th>
677 </tr>
678 </thead>
679 <tbody>
680 <tr class="noclick odd">
681 <th class="name"><?php echo __('Received'); ?></th>
682 <td class="value"><?php echo
683 implode(' ',
684 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
685 <td class="value"><?php echo
686 implode(' ',
687 PMA_formatByteDown(
688 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
689 </tr>
690 <tr class="noclick even">
691 <th class="name"><?php echo __('Sent'); ?></th>
692 <td class="value"><?php echo
693 implode(' ',
694 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
695 <td class="value"><?php echo
696 implode(' ',
697 PMA_formatByteDown(
698 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
699 </tr>
700 <tr class="noclick odd">
701 <th class="name"><?php echo __('Total'); ?></th>
702 <td class="value"><?php echo
703 implode(' ',
704 PMA_formatByteDown(
705 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
706 ); ?></td>
707 <td class="value"><?php echo
708 implode(' ',
709 PMA_formatByteDown(
710 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
711 * $hour_factor, 3, 1)
712 ); ?></td>
713 </tr>
714 </tbody>
715 </table>
717 <table id="serverstatusconnections" class="data">
718 <thead>
719 <tr>
720 <th colspan="2"><?php echo __('Connections'); ?></th>
721 <th>&oslash; <?php echo __('per hour'); ?></th>
722 <th>%</th>
723 </tr>
724 </thead>
725 <tbody>
726 <tr class="noclick odd">
727 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
728 <td class="value"><?php echo
729 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
730 <td class="value">--- </td>
731 <td class="value">--- </td>
732 </tr>
733 <tr class="noclick even">
734 <th class="name"><?php echo __('Failed attempts'); ?></th>
735 <td class="value"><?php echo
736 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
737 <td class="value"><?php echo
738 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
739 4, 2, true); ?></td>
740 <td class="value"><?php echo
741 $server_status['Connections'] > 0
742 ? PMA_formatNumber(
743 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
744 0, 2, true) . '%'
745 : '--- '; ?></td>
746 </tr>
747 <tr class="noclick odd">
748 <th class="name"><?php echo __('Aborted'); ?></th>
749 <td class="value"><?php echo
750 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
751 <td class="value"><?php echo
752 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
753 4, 2, true); ?></td>
754 <td class="value"><?php echo
755 $server_status['Connections'] > 0
756 ? PMA_formatNumber(
757 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
758 0, 2, true) . '%'
759 : '--- '; ?></td>
760 </tr>
761 <tr class="noclick even">
762 <th class="name"><?php echo __('Total'); ?></th>
763 <td class="value"><?php echo
764 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
765 <td class="value"><?php echo
766 PMA_formatNumber($server_status['Connections'] * $hour_factor,
767 4, 2); ?></td>
768 <td class="value"><?php echo
769 PMA_formatNumber(100, 0, 2); ?>%</td>
770 </tr>
771 </tbody>
772 </table>
773 <?php
775 $url_params = array();
777 if (! empty($_REQUEST['full'])) {
778 $sql_query = 'SHOW FULL PROCESSLIST';
779 $url_params['full'] = 1;
780 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
781 } else {
782 $sql_query = 'SHOW PROCESSLIST';
783 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
785 $result = PMA_DBI_query($sql_query);
788 * Displays the page
791 <table id="tableprocesslist" class="data clearfloat">
792 <thead>
793 <tr>
794 <th><?php echo __('Processes'); ?></th>
795 <th><?php echo __('ID'); ?></th>
796 <th><?php echo __('User'); ?></th>
797 <th><?php echo __('Host'); ?></th>
798 <th><?php echo __('Database'); ?></th>
799 <th><?php echo __('Command'); ?></th>
800 <th><?php echo __('Time'); ?></th>
801 <th><?php echo __('Status'); ?></th>
802 <th><?php
803 echo __('SQL query');
804 if (! PMA_DRIZZLE) { ?>
805 <a href="<?php echo $full_text_link; ?>"
806 title="<?php echo empty($full) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>">
807 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (empty($_REQUEST['full']) ? 'full' : 'partial'); ?>text.png"
808 alt="<?php echo empty($_REQUEST['full']) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>" />
809 </a>
810 <?php } ?>
811 </th>
812 </tr>
813 </thead>
814 <tbody>
815 <?php
816 $odd_row = true;
817 while ($process = PMA_DBI_fetch_assoc($result)) {
818 if (PMA_DRIZZLE) {
819 // Drizzle uses uppercase keys
820 foreach ($process as $k => $v) {
821 $k = $k !== 'DB'
822 ? ucfirst(strtolower($k))
823 : 'db';
824 $process[$k] = $v;
827 $url_params['kill'] = $process['Id'];
828 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
830 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
831 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
832 <td class="value"><?php echo $process['Id']; ?></td>
833 <td><?php echo $process['User']; ?></td>
834 <td><?php echo $process['Host']; ?></td>
835 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
836 <td><?php echo $process['Command']; ?></td>
837 <td class="value"><?php echo $process['Time']; ?></td>
838 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
839 <td><?php echo (empty($process['Info']) ? '---' : PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']))); ?></td>
840 </tr>
841 <?php
842 $odd_row = ! $odd_row;
845 </tbody>
846 </table>
847 <?php
850 function printVariablesTable() {
851 global $server_status, $server_variables, $allocationMap, $links;
853 * Messages are built using the message name
855 $strShowStatus = array(
856 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
857 '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.'),
858 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
859 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
860 '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.'),
861 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
862 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
863 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
864 '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.'),
865 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
866 'Flush_commands' => __('The number of executed FLUSH statements.'),
867 'Handler_commit' => __('The number of internal COMMIT statements.'),
868 'Handler_delete' => __('The number of times a row was deleted from a table.'),
869 '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.'),
870 '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.'),
871 '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.'),
872 '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.'),
873 '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.'),
874 '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.'),
875 '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.'),
876 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
877 'Handler_update' => __('The number of requests to update a row in a table.'),
878 'Handler_write' => __('The number of requests to insert a row in a table.'),
879 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
880 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
881 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
882 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
883 '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.'),
884 '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.'),
885 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
886 '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.'),
887 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
888 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
889 '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.'),
890 '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.'),
891 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
892 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
893 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
894 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
895 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
896 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
897 'Innodb_data_reads' => __('The total number of data reads.'),
898 'Innodb_data_writes' => __('The total number of data writes.'),
899 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
900 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
901 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
902 '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.'),
903 'Innodb_log_write_requests' => __('The number of log write requests.'),
904 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
905 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
906 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
907 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
908 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
909 'Innodb_pages_created' => __('The number of pages created.'),
910 '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.'),
911 'Innodb_pages_read' => __('The number of pages read.'),
912 'Innodb_pages_written' => __('The number of pages written.'),
913 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
914 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
915 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
916 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
917 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
918 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
919 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
920 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
921 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
922 '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.'),
923 '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.'),
924 '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.'),
925 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
926 '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.'),
927 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
928 'Key_writes' => __('The number of physical writes of a key block to disk.'),
929 '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.'),
930 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
931 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
932 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
933 'Open_files' => __('The number of files that are open.'),
934 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
935 'Open_tables' => __('The number of tables that are open.'),
936 '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.'),
937 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
938 'Qcache_hits' => __('The number of cache hits.'),
939 'Qcache_inserts' => __('The number of queries added to the cache.'),
940 '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.'),
941 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
942 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
943 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
944 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
945 '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.'),
946 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
947 '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.)'),
948 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
949 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
950 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
951 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
952 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
953 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
954 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
955 '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.'),
956 'Sort_range' => __('The number of sorts that were done with ranges.'),
957 'Sort_rows' => __('The number of sorted rows.'),
958 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
959 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
960 '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.'),
961 '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.'),
962 'Threads_connected' => __('The number of currently open connections.'),
963 '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.)'),
964 'Threads_running' => __('The number of threads that are not sleeping.')
968 * define some alerts
970 // name => max value before alert
971 $alerts = array(
972 // lower is better
973 // variable => max value
974 'Aborted_clients' => 0,
975 'Aborted_connects' => 0,
977 'Binlog_cache_disk_use' => 0,
979 'Created_tmp_disk_tables' => 0,
981 'Handler_read_rnd' => 0,
982 'Handler_read_rnd_next' => 0,
984 'Innodb_buffer_pool_pages_dirty' => 0,
985 'Innodb_buffer_pool_reads' => 0,
986 'Innodb_buffer_pool_wait_free' => 0,
987 'Innodb_log_waits' => 0,
988 'Innodb_row_lock_time_avg' => 10, // ms
989 'Innodb_row_lock_time_max' => 50, // ms
990 'Innodb_row_lock_waits' => 0,
992 'Slow_queries' => 0,
993 'Delayed_errors' => 0,
994 'Select_full_join' => 0,
995 'Select_range_check' => 0,
996 'Sort_merge_passes' => 0,
997 'Opened_tables' => 0,
998 'Table_locks_waited' => 0,
999 'Qcache_lowmem_prunes' => 0,
1001 'Qcache_free_blocks' => $server_status['Qcache_total_blocks'] / 5,
1002 'Slow_launch_threads' => 0,
1004 // depends on Key_read_requests
1005 // normaly lower then 1:0.01
1006 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
1007 // depends on Key_write_requests
1008 // normaly nearly 1:1
1009 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
1011 'Key_buffer_fraction' => 0.5,
1013 // alert if more than 95% of thread cache is in use
1014 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
1016 // higher is better
1017 // variable => min value
1018 //'Handler read key' => '> ',
1022 <table class="data sortable" id="serverstatusvariables">
1023 <col class="namecol" />
1024 <col class="valuecol" />
1025 <col class="descrcol" />
1026 <thead>
1027 <tr>
1028 <th><?php echo __('Variable'); ?></th>
1029 <th><?php echo __('Value'); ?></th>
1030 <th><?php echo __('Description'); ?></th>
1031 </tr>
1032 </thead>
1033 <tbody>
1034 <?php
1036 $odd_row = false;
1037 foreach ($server_status as $name => $value) {
1038 $odd_row = !$odd_row;
1040 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_'.$allocationMap[$name]:''; ?>">
1041 <th class="name"><?php echo htmlspecialchars($name) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1042 </th>
1043 <td class="value"><?php
1044 if (isset($alerts[$name])) {
1045 if ($value > $alerts[$name]) {
1046 echo '<span class="attention">';
1047 } else {
1048 echo '<span class="allfine">';
1051 if ('%' === substr($name, -1, 1)) {
1052 echo PMA_formatNumber($value, 0, 2) . ' %';
1053 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1054 echo PMA_formatNumber($value, 3, 1);
1055 } elseif (is_numeric($value) && $value == (int) $value) {
1056 echo PMA_formatNumber($value, 3, 0);
1057 } elseif (is_numeric($value)) {
1058 echo PMA_formatNumber($value, 3, 1);
1059 } else {
1060 echo htmlspecialchars($value);
1062 if (isset($alerts[$name])) {
1063 echo '</span>';
1065 ?></td>
1066 <td class="descr">
1067 <?php
1068 if (isset($strShowStatus[$name ])) {
1069 echo $strShowStatus[$name];
1072 if (isset($links[$name])) {
1073 foreach ($links[$name] as $link_name => $link_url) {
1074 if ('doc' == $link_name) {
1075 echo PMA_showMySQLDocu($link_url, $link_url);
1076 } else {
1077 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1078 "\n";
1081 unset($link_url, $link_name);
1084 </td>
1085 </tr>
1086 <?php
1089 </tbody>
1090 </table>
1091 <?php
1095 * cleanup of some deprecated values
1097 function cleanDeprecated(&$server_status) {
1098 $deprecated = array(
1099 'Com_prepare_sql' => 'Com_stmt_prepare',
1100 'Com_execute_sql' => 'Com_stmt_execute',
1101 'Com_dealloc_sql' => 'Com_stmt_close',
1104 foreach ($deprecated as $old => $new) {
1105 if (isset($server_status[$old])
1106 && isset($server_status[$new])) {
1107 unset($server_status[$old]);
1113 * Sends the footer
1115 require './libraries/footer.inc.php';