Don't show 0 if index cardinality is unknown
[phpmyadmin.git] / server_status.php
blobfd3eb08d0f4e46a6245198a4ceef3eeee79ea6ee
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 $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 <select name="trafficChartRefresh" style="display:none;">
413 <?php PMA_choose_refresh_rate(); ?>
414 </select>
416 <a class="tabChart livetrafficLink" href="#">
417 <?php echo __('Live traffic chart'); ?>
418 </a>
419 <a class="tabChart liveconnectionsLink" href="#">
420 <?php echo __('Live conn./process chart'); ?>
423 </a>
424 </div>
425 <div class="tabInnerContent">
426 <?php printServerTraffic(); ?>
427 </div>
428 </div>
429 <div id="statustabs_queries">
430 <div class="statuslinks">
431 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
432 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
433 <?php echo __('Refresh'); ?>
434 </a>
435 <select name="queryChartRefresh" style="display:none;">
436 <?php PMA_choose_refresh_rate(); ?>
437 </select>
438 <a class="tabChart livequeriesLink" href="#">
439 <?php echo __('Live query chart'); ?>
440 </a>
441 </div>
442 <div class="tabInnerContent">
443 <?php printQueryStatistics(); ?>
444 </div>
445 </div>
446 <div id="statustabs_allvars">
447 <fieldset id="tableFilter">
448 <div class="statuslinks">
449 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
450 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
451 <?php echo __('Refresh'); ?>
452 </a>
453 </div>
454 <legend>Filters</legend>
455 <div class="formelement">
456 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
457 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
458 </div>
459 <div class="formelement">
460 <input type="checkbox" name="filterAlert" id="filterAlert">
461 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
462 </div>
463 <div class="formelement">
464 <select id="filterCategory" name="filterCategory">
465 <option value=''><?php echo __('Filter by category...'); ?></option>
466 <?php
467 foreach($sections as $section_id => $section_name) {
469 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
470 <?php
474 </select>
475 </div>
476 </fieldset>
477 <div id="linkSuggestions" class="defaultLinks" style="display:none">
478 <p><?php echo __('Related links:'); ?>
479 <?php
480 foreach ($links as $section_name => $section_links) {
481 echo '<span class="status_'.$section_name.'"> ';
482 $i=0;
483 foreach ($section_links as $link_name => $link_url) {
484 if ($i > 0) echo ', ';
485 if ('doc' == $link_name) {
486 echo PMA_showMySQLDocu($link_url, $link_url);
487 } else {
488 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
490 $i++;
492 echo '</span>';
494 unset($link_url, $link_name, $i);
496 </p>
497 </div>
498 <div class="tabInnerContent">
499 <?php printVariablesTable(); ?>
500 </div>
501 </div>
502 </div>
503 </div>
505 <?php
507 function printQueryStatistics() {
508 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
510 $hour_factor = 3600 / $server_status['Uptime'];
512 $total_queries = array_sum($used_queries);
515 <h3 id="serverstatusqueries">
516 <?php
517 echo sprintf('Queries since startup: %s',PMA_formatNumber($total_queries, 0));
519 <br>
520 <span>
521 <?php
522 echo '&oslash;'.__('per hour').':';
523 echo PMA_formatNumber($total_queries * $hour_factor, 0);
524 echo '<br>';
526 echo '&oslash;'.__('per minute').':';
527 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
528 echo '<br>';
530 if ($total_queries / $server_status['Uptime'] >= 1) {
531 echo '&oslash;'.__('per second').':';
532 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
534 </span><br>
535 </h3>
536 <?php
539 // reverse sort by value to show most used statements first
540 arsort($used_queries);
542 $odd_row = true;
543 $count_displayed_rows = 0;
544 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
548 <table id="serverstatusqueriesdetails" class="data sortable">
549 <col class="namecol" />
550 <col class="valuecol" span="3" />
551 <thead>
552 <tr><th><?php echo __('Query type'); ?></th>
553 <th><?php
554 /* l10n: # = Amount of queries */
555 echo __('#');
557 <th>&oslash; <?php echo __('per hour'); ?></th>
558 <th>%</th>
559 </tr>
560 </thead>
561 <tbody>
563 <?php
564 $chart_json = array();
565 $query_sum = array_sum($used_queries);
566 $other_sum = 0;
567 foreach ($used_queries as $name => $value) {
568 $odd_row = !$odd_row;
570 // For the percentage column, use Questions - Connections, because
571 // the number of connections is not an item of the Query types
572 // but is included in Questions. Then the total of the percentages is 100.
573 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
575 if ($value < $query_sum * 0.02)
576 $other_sum += $value;
577 else $chart_json[$name] = $value;
579 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
580 <th class="name"><?php echo htmlspecialchars($name); ?></th>
581 <td class="value"><?php echo PMA_formatNumber($value, 5, 0, true); ?></td>
582 <td class="value"><?php echo
583 PMA_formatNumber($value * $hour_factor, 4, 1, true); ?></td>
584 <td class="value"><?php echo
585 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
586 </tr>
587 <?php
590 </tbody>
591 </table>
593 <div id="serverstatusquerieschart">
594 <?php
595 if ($other_sum > 0)
596 $chart_json[__('Other')] = $other_sum;
598 echo json_encode($chart_json);
600 </div>
601 <?php
604 function printServerTraffic() {
605 global $server_status,$PMA_PHP_SELF;
606 global $server_master_status, $server_slave_status;
608 $hour_factor = 3600 / $server_status['Uptime'];
611 * starttime calculation
613 $start_time = PMA_DBI_fetch_value(
614 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
617 <h3><?php
618 echo sprintf(
619 __('Network traffic since startup: %s'),
620 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
623 </h3>
626 <?php
627 echo sprintf(__('This MySQL server has been running for %s. It started up on %s.'),
628 PMA_timespanFormat($server_status['Uptime']),
629 PMA_localisedDate($start_time)) . "\n";
631 </p>
633 <?php
634 if ($server_master_status || $server_slave_status) {
635 echo '<p>';
636 if ($server_master_status && $server_slave_status) {
637 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
638 } elseif ($server_master_status) {
639 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
640 } elseif ($server_slave_status) {
641 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
643 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
644 echo '</p>';
647 /* if the server works as master or slave in replication process, display useful information */
648 if ($server_master_status || $server_slave_status)
651 <hr class="clearfloat" />
653 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
654 <?php
656 foreach ($replication_types as $type)
658 if (${"server_{$type}_status"}) {
659 PMA_replication_print_status_table($type);
662 unset($types);
666 <table id="serverstatustraffic" class="data">
667 <thead>
668 <tr>
669 <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>
670 <th>&oslash; <?php echo __('per hour'); ?></th>
671 </tr>
672 </thead>
673 <tbody>
674 <tr class="noclick odd">
675 <th class="name"><?php echo __('Received'); ?></th>
676 <td class="value"><?php echo
677 implode(' ',
678 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
679 <td class="value"><?php echo
680 implode(' ',
681 PMA_formatByteDown(
682 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
683 </tr>
684 <tr class="noclick even">
685 <th class="name"><?php echo __('Sent'); ?></th>
686 <td class="value"><?php echo
687 implode(' ',
688 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
689 <td class="value"><?php echo
690 implode(' ',
691 PMA_formatByteDown(
692 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
693 </tr>
694 <tr class="noclick odd">
695 <th class="name"><?php echo __('Total'); ?></th>
696 <td class="value"><?php echo
697 implode(' ',
698 PMA_formatByteDown(
699 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
700 ); ?></td>
701 <td class="value"><?php echo
702 implode(' ',
703 PMA_formatByteDown(
704 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
705 * $hour_factor, 3, 1)
706 ); ?></td>
707 </tr>
708 </tbody>
709 </table>
711 <table id="serverstatusconnections" class="data">
712 <thead>
713 <tr>
714 <th colspan="2"><?php echo __('Connections'); ?></th>
715 <th>&oslash; <?php echo __('per hour'); ?></th>
716 <th>%</th>
717 </tr>
718 </thead>
719 <tbody>
720 <tr class="noclick odd">
721 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
722 <td class="value"><?php echo
723 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
724 <td class="value">--- </td>
725 <td class="value">--- </td>
726 </tr>
727 <tr class="noclick even">
728 <th class="name"><?php echo __('Failed attempts'); ?></th>
729 <td class="value"><?php echo
730 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
731 <td class="value"><?php echo
732 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
733 4, 2, true); ?></td>
734 <td class="value"><?php echo
735 $server_status['Connections'] > 0
736 ? PMA_formatNumber(
737 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
738 0, 2, true) . '%'
739 : '--- '; ?></td>
740 </tr>
741 <tr class="noclick odd">
742 <th class="name"><?php echo __('Aborted'); ?></th>
743 <td class="value"><?php echo
744 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
745 <td class="value"><?php echo
746 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
747 4, 2, true); ?></td>
748 <td class="value"><?php echo
749 $server_status['Connections'] > 0
750 ? PMA_formatNumber(
751 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
752 0, 2, true) . '%'
753 : '--- '; ?></td>
754 </tr>
755 <tr class="noclick even">
756 <th class="name"><?php echo __('Total'); ?></th>
757 <td class="value"><?php echo
758 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
759 <td class="value"><?php echo
760 PMA_formatNumber($server_status['Connections'] * $hour_factor,
761 4, 2); ?></td>
762 <td class="value"><?php echo
763 PMA_formatNumber(100, 0, 2); ?>%</td>
764 </tr>
765 </tbody>
766 </table>
767 <?php
769 $url_params = array();
771 if (! empty($_REQUEST['full'])) {
772 $sql_query = 'SHOW FULL PROCESSLIST';
773 $url_params['full'] = 1;
774 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
775 } else {
776 $sql_query = 'SHOW PROCESSLIST';
777 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
779 $result = PMA_DBI_query($sql_query);
782 * Displays the page
785 <table id="tableprocesslist" class="data clearfloat">
786 <thead>
787 <tr>
788 <th><?php echo __('Processes'); ?></th>
789 <th><?php echo __('ID'); ?></th>
790 <th><?php echo __('User'); ?></th>
791 <th><?php echo __('Host'); ?></th>
792 <th><?php echo __('Database'); ?></th>
793 <th><?php echo __('Command'); ?></th>
794 <th><?php echo __('Time'); ?></th>
795 <th><?php echo __('Status'); ?></th>
796 <th><?php
797 echo __('SQL query');
798 if (! PMA_DRIZZLE) { ?>
799 <a href="<?php echo $full_text_link; ?>"
800 title="<?php echo empty($full) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>">
801 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (empty($_REQUEST['full']) ? 'full' : 'partial'); ?>text.png"
802 alt="<?php echo empty($_REQUEST['full']) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>" />
803 </a>
804 <?php } ?>
805 </th>
806 </tr>
807 </thead>
808 <tbody>
809 <?php
810 $odd_row = true;
811 while ($process = PMA_DBI_fetch_assoc($result)) {
812 if (PMA_DRIZZLE) {
813 // Drizzle uses uppercase keys
814 foreach ($process as $k => $v) {
815 $k = $k !== 'DB'
816 ? ucfirst(strtolower($k))
817 : 'db';
818 $process[$k] = $v;
821 $url_params['kill'] = $process['Id'];
822 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
824 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
825 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
826 <td class="value"><?php echo $process['Id']; ?></td>
827 <td><?php echo $process['User']; ?></td>
828 <td><?php echo $process['Host']; ?></td>
829 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
830 <td><?php echo $process['Command']; ?></td>
831 <td class="value"><?php echo $process['Time']; ?></td>
832 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
833 <td><?php echo (empty($process['Info']) ? '---' : PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']))); ?></td>
834 </tr>
835 <?php
836 $odd_row = ! $odd_row;
839 </tbody>
840 </table>
841 <?php
844 function printVariablesTable() {
845 global $server_status, $server_variables, $allocationMap, $links;
847 * Messages are built using the message name
849 $strShowStatus = array(
850 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
851 '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.'),
852 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
853 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
854 '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.'),
855 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
856 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
857 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
858 '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.'),
859 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
860 'Flush_commands' => __('The number of executed FLUSH statements.'),
861 'Handler_commit' => __('The number of internal COMMIT statements.'),
862 'Handler_delete' => __('The number of times a row was deleted from a table.'),
863 '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.'),
864 '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.'),
865 '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.'),
866 '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.'),
867 '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.'),
868 '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.'),
869 '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.'),
870 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
871 'Handler_update' => __('The number of requests to update a row in a table.'),
872 'Handler_write' => __('The number of requests to insert a row in a table.'),
873 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
874 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
875 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
876 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
877 '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.'),
878 '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.'),
879 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
880 '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.'),
881 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
882 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
883 '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.'),
884 '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.'),
885 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
886 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
887 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
888 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
889 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
890 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
891 'Innodb_data_reads' => __('The total number of data reads.'),
892 'Innodb_data_writes' => __('The total number of data writes.'),
893 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
894 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
895 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
896 '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.'),
897 'Innodb_log_write_requests' => __('The number of log write requests.'),
898 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
899 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
900 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
901 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
902 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
903 'Innodb_pages_created' => __('The number of pages created.'),
904 '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.'),
905 'Innodb_pages_read' => __('The number of pages read.'),
906 'Innodb_pages_written' => __('The number of pages written.'),
907 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
908 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
909 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
910 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
911 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
912 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
913 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
914 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
915 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
916 '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.'),
917 '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.'),
918 '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.'),
919 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
920 '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.'),
921 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
922 'Key_writes' => __('The number of physical writes of a key block to disk.'),
923 '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.'),
924 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
925 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
926 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
927 'Open_files' => __('The number of files that are open.'),
928 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
929 'Open_tables' => __('The number of tables that are open.'),
930 '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.'),
931 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
932 'Qcache_hits' => __('The number of cache hits.'),
933 'Qcache_inserts' => __('The number of queries added to the cache.'),
934 '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.'),
935 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
936 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
937 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
938 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
939 '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.'),
940 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
941 '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.)'),
942 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
943 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
944 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
945 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
946 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
947 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
948 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
949 '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.'),
950 'Sort_range' => __('The number of sorts that were done with ranges.'),
951 'Sort_rows' => __('The number of sorted rows.'),
952 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
953 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
954 '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.'),
955 '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.'),
956 'Threads_connected' => __('The number of currently open connections.'),
957 '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.)'),
958 'Threads_running' => __('The number of threads that are not sleeping.')
962 * define some alerts
964 // name => max value before alert
965 $alerts = array(
966 // lower is better
967 // variable => max value
968 'Aborted_clients' => 0,
969 'Aborted_connects' => 0,
971 'Binlog_cache_disk_use' => 0,
973 'Created_tmp_disk_tables' => 0,
975 'Handler_read_rnd' => 0,
976 'Handler_read_rnd_next' => 0,
978 'Innodb_buffer_pool_pages_dirty' => 0,
979 'Innodb_buffer_pool_reads' => 0,
980 'Innodb_buffer_pool_wait_free' => 0,
981 'Innodb_log_waits' => 0,
982 'Innodb_row_lock_time_avg' => 10, // ms
983 'Innodb_row_lock_time_max' => 50, // ms
984 'Innodb_row_lock_waits' => 0,
986 'Slow_queries' => 0,
987 'Delayed_errors' => 0,
988 'Select_full_join' => 0,
989 'Select_range_check' => 0,
990 'Sort_merge_passes' => 0,
991 'Opened_tables' => 0,
992 'Table_locks_waited' => 0,
993 'Qcache_lowmem_prunes' => 0,
995 'Qcache_free_blocks' => $server_status['Qcache_total_blocks'] / 5,
996 'Slow_launch_threads' => 0,
998 // depends on Key_read_requests
999 // normaly lower then 1:0.01
1000 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
1001 // depends on Key_write_requests
1002 // normaly nearly 1:1
1003 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
1005 'Key_buffer_fraction' => 0.5,
1007 // alert if more than 95% of thread cache is in use
1008 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
1010 // higher is better
1011 // variable => min value
1012 //'Handler read key' => '> ',
1016 <table class="data sortable" id="serverstatusvariables">
1017 <col class="namecol" />
1018 <col class="valuecol" />
1019 <col class="descrcol" />
1020 <thead>
1021 <tr>
1022 <th><?php echo __('Variable'); ?></th>
1023 <th><?php echo __('Value'); ?></th>
1024 <th><?php echo __('Description'); ?></th>
1025 </tr>
1026 </thead>
1027 <tbody>
1028 <?php
1030 $odd_row = false;
1031 foreach ($server_status as $name => $value) {
1032 $odd_row = !$odd_row;
1034 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_'.$allocationMap[$name]:''; ?>">
1035 <th class="name"><?php echo htmlspecialchars($name) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1036 </th>
1037 <td class="value"><?php
1038 if (isset($alerts[$name])) {
1039 if ($value > $alerts[$name]) {
1040 echo '<span class="attention">';
1041 } else {
1042 echo '<span class="allfine">';
1045 if ('%' === substr($name, -1, 1)) {
1046 echo PMA_formatNumber($value, 0, 2) . ' %';
1047 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1048 echo PMA_formatNumber($value, 3, 1);
1049 } elseif (is_numeric($value) && $value == (int) $value) {
1050 echo PMA_formatNumber($value, 3, 0);
1051 } elseif (is_numeric($value)) {
1052 echo PMA_formatNumber($value, 3, 1);
1053 } else {
1054 echo htmlspecialchars($value);
1056 if (isset($alerts[$name])) {
1057 echo '</span>';
1059 ?></td>
1060 <td class="descr">
1061 <?php
1062 if (isset($strShowStatus[$name ])) {
1063 echo $strShowStatus[$name];
1066 if (isset($links[$name])) {
1067 foreach ($links[$name] as $link_name => $link_url) {
1068 if ('doc' == $link_name) {
1069 echo PMA_showMySQLDocu($link_url, $link_url);
1070 } else {
1071 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1072 "\n";
1075 unset($link_url, $link_name);
1078 </td>
1079 </tr>
1080 <?php
1083 </tbody>
1084 </table>
1085 <?php
1089 * cleanup of some deprecated values
1091 function cleanDeprecated(&$server_status) {
1092 $deprecated = array(
1093 'Com_prepare_sql' => 'Com_stmt_prepare',
1094 'Com_execute_sql' => 'Com_stmt_execute',
1095 'Com_dealloc_sql' => 'Com_stmt_close',
1098 foreach ($deprecated as $old => $new) {
1099 if (isset($server_status[$old])
1100 && isset($server_status[$new])) {
1101 unset($server_status[$old]);
1107 * Sends the footer
1109 require './libraries/footer.inc.php';