Better plugin list
[phpmyadmin.git] / server_status.php
blobf740e9112e384eb701c4d177efbb6455f6ec3f3a
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 if (PMA_DRIZZLE) {
63 $sql = "SELECT concat('Com_', variable_name), variable_value
64 FROM data_dictionary.GLOBAL_STATEMENTS
65 WHERE variable_value > 0";
66 $queries = PMA_DBI_fetch_result($sql, 0, 1);
67 } else {
68 $queries = PMA_DBI_fetch_result('SHOW GLOBAL STATUS WHERE Variable_name LIKE "Com_%" AND Value>0', 0, 1);
70 cleanDeprecated($queries);
71 // admin commands are not queries
72 unset($queries['Com_admin_commands']);
74 $sum = array_sum($queries);
75 $ret = array(
76 'x' => microtime(true)*1000,
77 'y' => $sum,
78 'pointInfo' => $queries
81 exit(json_encode($ret));
82 case 'traffic':
83 $traffic = PMA_DBI_fetch_result('SHOW GLOBAL STATUS WHERE Variable_name="Bytes_received" OR Variable_name="Bytes_sent"', 0, 1);
85 $ret = array(
86 'x' => microtime(true)*1000,
87 'y_sent' => $traffic['Bytes_sent'],
88 'y_received' => $traffic['Bytes_received']
91 exit(json_encode($ret));
98 /**
99 * Replication library
101 if (PMA_DRIZZLE) {
102 $server_master_status = false;
103 $server_slave_status = false;
104 } else {
105 require './libraries/replication.inc.php';
106 require_once './libraries/replication_gui.lib.php';
110 * JS Includes
113 $GLOBALS['js_include'][] = 'server_status.js';
114 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
115 $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
116 $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
117 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
118 /* Files required for chart exporting */
119 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
120 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
121 $GLOBALS['js_include'][] = 'canvg/canvg.js';
122 $GLOBALS['js_include'][] = 'canvg/rgbcolor.js';
126 * flush status variables if requested
128 if (isset($_REQUEST['flush'])) {
129 $_flush_commands = array(
130 'STATUS',
131 'TABLES',
132 'QUERY CACHE',
135 if (in_array($_REQUEST['flush'], $_flush_commands)) {
136 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
138 unset($_flush_commands);
142 * Kills a selected process
144 if (!empty($_REQUEST['kill'])) {
145 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
146 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
147 } else {
148 $message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
150 $message->addParam($_REQUEST['kill']);
151 //$message->display();
157 * get status from server
159 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
160 if (PMA_DRIZZLE) {
161 // Drizzle doesn't put query statistics into variables, add it
162 $sql = "SELECT concat('Com_', variable_name), variable_value
163 FROM data_dictionary.GLOBAL_STATEMENTS";
164 $statements = PMA_DBI_fetch_result($sql, 0, 1);
165 $server_status = array_merge($server_status, $statements);
169 * for some calculations we require also some server settings
171 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
174 * cleanup of some deprecated values
176 cleanDeprecated($server_status);
179 * calculate some values
181 // Key_buffer_fraction
182 if (isset($server_status['Key_blocks_unused'])
183 && isset($server_variables['key_cache_block_size'])
184 && isset($server_variables['key_buffer_size'])) {
185 $server_status['Key_buffer_fraction_%'] =
187 - $server_status['Key_blocks_unused']
188 * $server_variables['key_cache_block_size']
189 / $server_variables['key_buffer_size']
190 * 100;
191 } elseif (
192 isset($server_status['Key_blocks_used'])
193 && isset($server_variables['key_buffer_size'])) {
194 $server_status['Key_buffer_fraction_%'] =
195 $server_status['Key_blocks_used']
196 * 1024
197 / $server_variables['key_buffer_size'];
200 // Ratio for key read/write
201 if (isset($server_status['Key_writes'])
202 && isset($server_status['Key_write_requests'])
203 && $server_status['Key_write_requests'] > 0)
204 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
206 if (isset($server_status['Key_reads'])
207 && isset($server_status['Key_read_requests'])
208 && $server_status['Key_read_requests'] > 0)
209 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
211 // Threads_cache_hitrate
212 if (isset($server_status['Threads_created'])
213 && isset($server_status['Connections'])
214 && $server_status['Connections'] > 0) {
215 $server_status['Threads_cache_hitrate_%'] =
217 - $server_status['Threads_created']
218 / $server_status['Connections']
219 * 100;
222 // Format Uptime_since_flush_status : show as days, hours, minutes, seconds
223 if (isset($server_status['Uptime_since_flush_status'])) {
224 $server_status['Uptime_since_flush_status'] = PMA_timespanFormat($server_status['Uptime_since_flush_status']);
228 * split variables in sections
230 $allocations = array(
231 // variable name => section
232 // variable names match when they begin with the given string
234 'Com_' => 'com',
235 'Innodb_' => 'innodb',
236 'Ndb_' => 'ndb',
237 'Handler_' => 'handler',
238 'Qcache_' => 'qcache',
239 'Threads_' => 'threads',
240 'Slow_launch_threads' => 'threads',
242 'Binlog_cache_' => 'binlog_cache',
243 'Created_tmp_' => 'created_tmp',
244 'Key_' => 'key',
246 'Delayed_' => 'delayed',
247 'Not_flushed_delayed_rows' => 'delayed',
249 'Flush_commands' => 'query',
250 'Last_query_cost' => 'query',
251 'Slow_queries' => 'query',
252 'Queries' => 'query',
253 'Prepared_stmt_count' => 'query',
255 'Select_' => 'select',
256 'Sort_' => 'sort',
258 'Open_tables' => 'table',
259 'Opened_tables' => 'table',
260 'Open_table_definitions' => 'table',
261 'Opened_table_definitions' => 'table',
262 'Table_locks_' => 'table',
264 'Rpl_status' => 'repl',
265 'Slave_' => 'repl',
267 'Tc_' => 'tc',
269 'Ssl_' => 'ssl',
271 'Open_files' => 'files',
272 'Open_streams' => 'files',
273 'Opened_files' => 'files',
276 $sections = array(
277 // section => section name (description)
278 'com' => 'Com',
279 'query' => __('SQL query'),
280 'innodb' => 'InnoDB',
281 'ndb' => 'NDB',
282 'handler' => __('Handler'),
283 'qcache' => __('Query cache'),
284 'threads' => __('Threads'),
285 'binlog_cache' => __('Binary log'),
286 'created_tmp' => __('Temporary data'),
287 'delayed' => __('Delayed inserts'),
288 'key' => __('Key cache'),
289 'select' => __('Joins'),
290 'repl' => __('Replication'),
291 'sort' => __('Sorting'),
292 'table' => __('Tables'),
293 'tc' => __('Transaction coordinator'),
294 'files' => __('Files'),
295 'ssl' => 'SSL',
296 'other' => __('Other')
300 * define some needfull links/commands
302 // variable or section name => (name => url)
303 $links = array();
305 $links['table'][__('Flush (close) all tables')]
306 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
307 $links['table'][__('Show open tables')]
308 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
309 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
311 if ($server_master_status) {
312 $links['repl'][__('Show slave hosts')]
313 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
314 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
315 $links['repl'][__('Show master status')] = '#replication_master';
317 if ($server_slave_status) {
318 $links['repl'][__('Show slave status')] = '#replication_slave';
321 $links['repl']['doc'] = 'replication';
323 $links['qcache'][__('Flush query cache')]
324 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
325 PMA_generate_common_url();
326 $links['qcache']['doc'] = 'query_cache';
328 //$links['threads'][__('Show processes')]
329 // = 'server_processlist.php?' . PMA_generate_common_url();
330 $links['threads']['doc'] = 'mysql_threads';
332 $links['key']['doc'] = 'myisam_key_cache';
334 $links['binlog_cache']['doc'] = 'binary_log';
336 $links['Slow_queries']['doc'] = 'slow_query_log';
338 $links['innodb'][__('Variables')]
339 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
340 $links['innodb'][__('InnoDB Status')]
341 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
342 PMA_generate_common_url();
343 $links['innodb']['doc'] = 'innodb';
346 // Variable to contain all com_ variables (query statistics)
347 $used_queries = array();
349 // Variable to map variable names to their respective section name (used for js category filtering)
350 $allocationMap = array();
352 // Variable to mark used sections
353 $categoryUsed = array();
355 // sort vars into arrays
356 foreach ($server_status as $name => $value) {
357 $section_found = false;
358 foreach ($allocations as $filter => $section) {
359 if (strpos($name, $filter) !== false) {
360 $allocationMap[$name] = $section;
361 $categoryUsed[$section] = true;
362 $section_found = true;
363 if ($section == 'com' && $value > 0) $used_queries[$name] = $value;
364 break; // Only exits inner loop
367 if (!$section_found) {
368 $allocationMap[$name] = 'other';
369 $categoryUsed['other'] = true;
373 // admin commands are not queries (e.g. they include COM_PING, which is excluded from $server_status['Questions'])
374 unset($used_queries['Com_admin_commands']);
376 /* Ajax request refresh */
377 if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
378 switch($_REQUEST['show']) {
379 case 'query_statistics':
380 printQueryStatistics();
381 exit();
382 case 'server_traffic':
383 printServerTraffic();
384 exit();
385 case 'variables_table':
386 // Prints the variables table
387 printVariablesTable();
388 exit();
390 default:
391 break;
396 * start output
400 * Does the common work
402 require './libraries/server_common.inc.php';
406 * Displays the links
408 require './libraries/server_links.inc.php';
411 <script type="text/javascript">
412 pma_token = '<?php echo $_SESSION[' PMA_token ']; ?>';
413 url_query = '<?php echo str_replace('&amp;','&',$url_query);?>';
414 pma_theme_image = '<?php echo $GLOBALS['pmaThemeImage']; ?>';
415 </script>
416 <div id="serverstatus">
417 <h2><?php
420 * Displays the sub-page heading
422 if ($GLOBALS['cfg']['MainPageIconic']) {
423 echo '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_status.png" width="16" height="16" alt="" />';
426 echo __('Runtime Information');
428 ?></h2>
429 <div id="serverStatusTabs">
430 <ul>
431 <li><a href="#statustabs_traffic"><?php echo __('Server traffic'); ?></a></li>
432 <li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
433 <li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
434 </ul>
436 <div id="statustabs_traffic">
437 <div class="statuslinks">
438 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&amp;' . PMA_generate_common_url(); ?>" >
439 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
440 <?php echo __('Refresh'); ?>
441 </a>
442 <span class="refreshList" style="display:none;">
443 <label for="trafficChartRefresh"><?php echo __('Refresh rate:'); ?></label>
444 <select name="trafficChartRefresh" style="display:none;">
445 <?php PMA_choose_refresh_rate(); ?>
446 </select>
447 </span>
449 <a class="tabChart livetrafficLink" href="#">
450 <?php echo __('Live traffic chart'); ?>
451 </a>
452 <a class="tabChart liveconnectionsLink" href="#">
453 <?php echo __('Live conn./process chart'); ?>
456 </a>
457 </div>
458 <div class="tabInnerContent">
459 <?php printServerTraffic(); ?>
460 </div>
461 </div>
462 <div id="statustabs_queries">
463 <div class="statuslinks">
464 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
465 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
466 <?php echo __('Refresh'); ?>
467 </a>
468 <span class="refreshList" style="display:none;">
469 <label for="queryChartRefresh"><?php echo __('Refresh rate:'); ?></label>
470 <select name="queryChartRefresh" style="display:none;">
471 <?php PMA_choose_refresh_rate(); ?>
472 </select>
473 </span>
474 <a class="tabChart livequeriesLink" href="#">
475 <?php echo __('Live query chart'); ?>
476 </a>
477 </div>
478 <div class="tabInnerContent">
479 <?php printQueryStatistics(); ?>
480 </div>
481 </div>
482 <div id="statustabs_allvars">
483 <fieldset id="tableFilter">
484 <div class="statuslinks">
485 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
486 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
487 <?php echo __('Refresh'); ?>
488 </a>
489 </div>
490 <legend>Filters</legend>
491 <div class="formelement">
492 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
493 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
494 </div>
495 <div class="formelement">
496 <input type="checkbox" name="filterAlert" id="filterAlert">
497 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
498 </div>
499 <div class="formelement">
500 <select id="filterCategory" name="filterCategory">
501 <option value=''><?php echo __('Filter by category...'); ?></option>
502 <?php
503 foreach($sections as $section_id => $section_name) {
504 if (isset($categoryUsed[$section_id])) {
506 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
507 <?php
511 </select>
512 </div>
513 </fieldset>
514 <div id="linkSuggestions" class="defaultLinks" style="display:none">
515 <p><?php echo __('Related links:'); ?>
516 <?php
517 foreach ($links as $section_name => $section_links) {
518 echo '<span class="status_'.$section_name.'"> ';
519 $i=0;
520 foreach ($section_links as $link_name => $link_url) {
521 if ($i > 0) echo ', ';
522 if ('doc' == $link_name) {
523 echo PMA_showMySQLDocu($link_url, $link_url);
524 } else {
525 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
527 $i++;
529 echo '</span>';
531 unset($link_url, $link_name, $i);
533 </p>
534 </div>
535 <div class="tabInnerContent">
536 <?php printVariablesTable(); ?>
537 </div>
538 </div>
539 </div>
540 </div>
542 <?php
544 function printQueryStatistics() {
545 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
547 $hour_factor = 3600 / $server_status['Uptime'];
549 $total_queries = array_sum($used_queries);
552 <h3 id="serverstatusqueries">
553 <?php
554 echo sprintf('Queries since startup: %s',PMA_formatNumber($total_queries, 0));
556 <br>
557 <span>
558 <?php
559 echo '&oslash;'.__('per hour').':';
560 echo PMA_formatNumber($total_queries * $hour_factor, 0);
561 echo '<br>';
563 echo '&oslash;'.__('per minute').':';
564 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
565 echo '<br>';
567 if ($total_queries / $server_status['Uptime'] >= 1) {
568 echo '&oslash;'.__('per second').':';
569 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
571 </span><br>
572 </h3>
573 <?php
576 // reverse sort by value to show most used statements first
577 arsort($used_queries);
579 $odd_row = true;
580 $count_displayed_rows = 0;
581 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
585 <table id="serverstatusqueriesdetails" class="data sortable">
586 <col class="namecol" />
587 <col class="valuecol" span="3" />
588 <thead>
589 <tr><th><?php echo __('Query type'); ?></th>
590 <th><?php
591 /* l10n: # = Amount of queries */
592 echo __('#');
594 <th>&oslash; <?php echo __('per hour'); ?></th>
595 <th>%</th>
596 </tr>
597 </thead>
598 <tbody>
600 <?php
601 $chart_json = array();
602 $query_sum = array_sum($used_queries);
603 $other_sum = 0;
604 foreach ($used_queries as $name => $value) {
605 $odd_row = !$odd_row;
607 // For the percentage column, use Questions - Connections, because
608 // the number of connections is not an item of the Query types
609 // but is included in Questions. Then the total of the percentages is 100.
610 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
612 if ($value < $query_sum * 0.02)
613 $other_sum += $value;
614 else $chart_json[$name] = $value;
616 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
617 <th class="name"><?php echo htmlspecialchars($name); ?></th>
618 <td class="value"><?php echo PMA_formatNumber($value, 5, 0, true); ?></td>
619 <td class="value"><?php echo
620 PMA_formatNumber($value * $hour_factor, 4, 1, true); ?></td>
621 <td class="value"><?php echo
622 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
623 </tr>
624 <?php
627 </tbody>
628 </table>
630 <div id="serverstatusquerieschart">
631 <?php
632 if ($other_sum > 0)
633 $chart_json[__('Other')] = $other_sum;
635 echo json_encode($chart_json);
637 </div>
638 <?php
641 function printServerTraffic() {
642 global $server_status,$PMA_PHP_SELF;
643 global $server_master_status, $server_slave_status, $replication_types;
645 $hour_factor = 3600 / $server_status['Uptime'];
648 * starttime calculation
650 $start_time = PMA_DBI_fetch_value(
651 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
654 <h3><?php
655 echo sprintf(
656 __('Network traffic since startup: %s'),
657 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
660 </h3>
663 <?php
664 echo sprintf(__('This MySQL server has been running for %s. It started up on %s.'),
665 PMA_timespanFormat($server_status['Uptime']),
666 PMA_localisedDate($start_time)) . "\n";
668 </p>
670 <?php
671 if ($server_master_status || $server_slave_status) {
672 echo '<p>';
673 if ($server_master_status && $server_slave_status) {
674 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
675 } elseif ($server_master_status) {
676 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
677 } elseif ($server_slave_status) {
678 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
680 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
681 echo '</p>';
684 /* if the server works as master or slave in replication process, display useful information */
685 if ($server_master_status || $server_slave_status)
688 <hr class="clearfloat" />
690 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
691 <?php
693 foreach ($replication_types as $type)
695 if (${"server_{$type}_status"}) {
696 PMA_replication_print_status_table($type);
699 unset($types);
703 <table id="serverstatustraffic" class="data">
704 <thead>
705 <tr>
706 <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>
707 <th>&oslash; <?php echo __('per hour'); ?></th>
708 </tr>
709 </thead>
710 <tbody>
711 <tr class="noclick odd">
712 <th class="name"><?php echo __('Received'); ?></th>
713 <td class="value"><?php echo
714 implode(' ',
715 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
716 <td class="value"><?php echo
717 implode(' ',
718 PMA_formatByteDown(
719 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
720 </tr>
721 <tr class="noclick even">
722 <th class="name"><?php echo __('Sent'); ?></th>
723 <td class="value"><?php echo
724 implode(' ',
725 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
726 <td class="value"><?php echo
727 implode(' ',
728 PMA_formatByteDown(
729 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
730 </tr>
731 <tr class="noclick odd">
732 <th class="name"><?php echo __('Total'); ?></th>
733 <td class="value"><?php echo
734 implode(' ',
735 PMA_formatByteDown(
736 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
737 ); ?></td>
738 <td class="value"><?php echo
739 implode(' ',
740 PMA_formatByteDown(
741 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
742 * $hour_factor, 3, 1)
743 ); ?></td>
744 </tr>
745 </tbody>
746 </table>
748 <table id="serverstatusconnections" class="data">
749 <thead>
750 <tr>
751 <th colspan="2"><?php echo __('Connections'); ?></th>
752 <th>&oslash; <?php echo __('per hour'); ?></th>
753 <th>%</th>
754 </tr>
755 </thead>
756 <tbody>
757 <tr class="noclick odd">
758 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
759 <td class="value"><?php echo
760 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
761 <td class="value">--- </td>
762 <td class="value">--- </td>
763 </tr>
764 <tr class="noclick even">
765 <th class="name"><?php echo __('Failed attempts'); ?></th>
766 <td class="value"><?php echo
767 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
768 <td class="value"><?php echo
769 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
770 4, 2, true); ?></td>
771 <td class="value"><?php echo
772 $server_status['Connections'] > 0
773 ? PMA_formatNumber(
774 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
775 0, 2, true) . '%'
776 : '--- '; ?></td>
777 </tr>
778 <tr class="noclick odd">
779 <th class="name"><?php echo __('Aborted'); ?></th>
780 <td class="value"><?php echo
781 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
782 <td class="value"><?php echo
783 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
784 4, 2, true); ?></td>
785 <td class="value"><?php echo
786 $server_status['Connections'] > 0
787 ? PMA_formatNumber(
788 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
789 0, 2, true) . '%'
790 : '--- '; ?></td>
791 </tr>
792 <tr class="noclick even">
793 <th class="name"><?php echo __('Total'); ?></th>
794 <td class="value"><?php echo
795 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
796 <td class="value"><?php echo
797 PMA_formatNumber($server_status['Connections'] * $hour_factor,
798 4, 2); ?></td>
799 <td class="value"><?php echo
800 PMA_formatNumber(100, 0, 2); ?>%</td>
801 </tr>
802 </tbody>
803 </table>
804 <?php
806 $url_params = array();
808 $show_full_sql = !empty($_REQUEST['full']);
809 if ($show_full_sql) {
810 $url_params['full'] = 1;
811 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
812 } else {
813 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
815 if (PMA_DRIZZLE) {
816 $sql_query = "SELECT
817 p.id AS Id,
818 p.username AS User,
819 p.host AS Host,
820 p.db AS db,
821 p.command AS Command,
822 p.time AS Time,
823 p.state AS State,
824 " . ($show_full_sql ? 's.query' : 'p.info') . " AS Info
825 FROM data_dictionary.PROCESSLIST p
826 " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
827 } else {
828 $sql_query = $show_full_sql
829 ? 'SHOW FULL PROCESSLIST'
830 : 'SHOW PROCESSLIST';
832 $result = PMA_DBI_query($sql_query);
835 * Displays the page
838 <table id="tableprocesslist" class="data clearfloat">
839 <thead>
840 <tr>
841 <th><?php echo __('Processes'); ?></th>
842 <th><?php echo __('ID'); ?></th>
843 <th><?php echo __('User'); ?></th>
844 <th><?php echo __('Host'); ?></th>
845 <th><?php echo __('Database'); ?></th>
846 <th><?php echo __('Command'); ?></th>
847 <th><?php echo __('Time'); ?></th>
848 <th><?php echo __('Status'); ?></th>
849 <th><?php echo __('SQL query'); ?>
850 <a href="<?php echo $full_text_link; ?>"
851 title="<?php echo empty($full) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>">
852 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (empty($_REQUEST['full']) ? 'full' : 'partial'); ?>text.png"
853 alt="<?php echo empty($_REQUEST['full']) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>" />
854 </a>
855 </th>
856 </tr>
857 </thead>
858 <tbody>
859 <?php
860 $odd_row = true;
861 while ($process = PMA_DBI_fetch_assoc($result)) {
862 $url_params['kill'] = $process['Id'];
863 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
865 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
866 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
867 <td class="value"><?php echo $process['Id']; ?></td>
868 <td><?php echo $process['User']; ?></td>
869 <td><?php echo $process['Host']; ?></td>
870 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
871 <td><?php echo $process['Command']; ?></td>
872 <td class="value"><?php echo $process['Time']; ?></td>
873 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
874 <td><?php echo (empty($process['Info']) ? '---' : PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']))); ?></td>
875 </tr>
876 <?php
877 $odd_row = ! $odd_row;
880 </tbody>
881 </table>
882 <?php
885 function printVariablesTable() {
886 global $server_status, $server_variables, $allocationMap, $links;
888 * Messages are built using the message name
890 $strShowStatus = array(
891 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
892 '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.'),
893 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
894 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
895 '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.'),
896 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
897 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
898 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
899 '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.'),
900 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
901 'Flush_commands' => __('The number of executed FLUSH statements.'),
902 'Handler_commit' => __('The number of internal COMMIT statements.'),
903 'Handler_delete' => __('The number of times a row was deleted from a table.'),
904 '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.'),
905 '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.'),
906 '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.'),
907 '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.'),
908 '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.'),
909 '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.'),
910 '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.'),
911 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
912 'Handler_update' => __('The number of requests to update a row in a table.'),
913 'Handler_write' => __('The number of requests to insert a row in a table.'),
914 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
915 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
916 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
917 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
918 '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.'),
919 '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.'),
920 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
921 '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.'),
922 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
923 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
924 '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.'),
925 '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.'),
926 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
927 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
928 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
929 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
930 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
931 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
932 'Innodb_data_reads' => __('The total number of data reads.'),
933 'Innodb_data_writes' => __('The total number of data writes.'),
934 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
935 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
936 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
937 '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.'),
938 'Innodb_log_write_requests' => __('The number of log write requests.'),
939 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
940 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
941 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
942 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
943 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
944 'Innodb_pages_created' => __('The number of pages created.'),
945 '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.'),
946 'Innodb_pages_read' => __('The number of pages read.'),
947 'Innodb_pages_written' => __('The number of pages written.'),
948 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
949 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
950 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
951 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
952 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
953 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
954 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
955 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
956 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
957 '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.'),
958 '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.'),
959 '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.'),
960 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
961 '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.'),
962 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
963 'Key_writes' => __('The number of physical writes of a key block to disk.'),
964 '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.'),
965 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
966 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
967 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
968 'Open_files' => __('The number of files that are open.'),
969 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
970 'Open_tables' => __('The number of tables that are open.'),
971 '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.'),
972 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
973 'Qcache_hits' => __('The number of cache hits.'),
974 'Qcache_inserts' => __('The number of queries added to the cache.'),
975 '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.'),
976 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
977 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
978 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
979 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
980 '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.'),
981 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
982 '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.)'),
983 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
984 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
985 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
986 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
987 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
988 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
989 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
990 '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.'),
991 'Sort_range' => __('The number of sorts that were done with ranges.'),
992 'Sort_rows' => __('The number of sorted rows.'),
993 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
994 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
995 '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.'),
996 '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.'),
997 'Threads_connected' => __('The number of currently open connections.'),
998 '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.)'),
999 'Threads_running' => __('The number of threads that are not sleeping.')
1003 * define some alerts
1005 // name => max value before alert
1006 $alerts = array(
1007 // lower is better
1008 // variable => max value
1009 'Aborted_clients' => 0,
1010 'Aborted_connects' => 0,
1012 'Binlog_cache_disk_use' => 0,
1014 'Created_tmp_disk_tables' => 0,
1016 'Handler_read_rnd' => 0,
1017 'Handler_read_rnd_next' => 0,
1019 'Innodb_buffer_pool_pages_dirty' => 0,
1020 'Innodb_buffer_pool_reads' => 0,
1021 'Innodb_buffer_pool_wait_free' => 0,
1022 'Innodb_log_waits' => 0,
1023 'Innodb_row_lock_time_avg' => 10, // ms
1024 'Innodb_row_lock_time_max' => 50, // ms
1025 'Innodb_row_lock_waits' => 0,
1027 'Slow_queries' => 0,
1028 'Delayed_errors' => 0,
1029 'Select_full_join' => 0,
1030 'Select_range_check' => 0,
1031 'Sort_merge_passes' => 0,
1032 'Opened_tables' => 0,
1033 'Table_locks_waited' => 0,
1034 'Qcache_lowmem_prunes' => 0,
1036 'Qcache_free_blocks' => isset($server_status['Qcache_total_blocks']) ? $server_status['Qcache_total_blocks'] / 5 : 0,
1037 'Slow_launch_threads' => 0,
1039 // depends on Key_read_requests
1040 // normaly lower then 1:0.01
1041 'Key_reads' => isset($server_status['Key_read_requests']) ? (0.01 * $server_status['Key_read_requests']) : 0,
1042 // depends on Key_write_requests
1043 // normaly nearly 1:1
1044 'Key_writes' => isset($server_status['Key_write_requests']) ? (0.9 * $server_status['Key_write_requests']) : 0,
1046 'Key_buffer_fraction' => 0.5,
1048 // alert if more than 95% of thread cache is in use
1049 'Threads_cached' => isset($server_variables['thread_cache_size']) ? 0.95 * $server_variables['thread_cache_size'] : 0
1051 // higher is better
1052 // variable => min value
1053 //'Handler read key' => '> ',
1057 <table class="data sortable" id="serverstatusvariables">
1058 <col class="namecol" />
1059 <col class="valuecol" />
1060 <col class="descrcol" />
1061 <thead>
1062 <tr>
1063 <th><?php echo __('Variable'); ?></th>
1064 <th><?php echo __('Value'); ?></th>
1065 <th><?php echo __('Description'); ?></th>
1066 </tr>
1067 </thead>
1068 <tbody>
1069 <?php
1071 $odd_row = false;
1072 foreach ($server_status as $name => $value) {
1073 $odd_row = !$odd_row;
1075 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_'.$allocationMap[$name]:''; ?>">
1076 <th class="name"><?php echo htmlspecialchars($name) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1077 </th>
1078 <td class="value"><?php
1079 if (isset($alerts[$name])) {
1080 if ($value > $alerts[$name]) {
1081 echo '<span class="attention">';
1082 } else {
1083 echo '<span class="allfine">';
1086 if ('%' === substr($name, -1, 1)) {
1087 echo PMA_formatNumber($value, 0, 2) . ' %';
1088 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1089 echo PMA_formatNumber($value, 3, 1);
1090 } elseif (is_numeric($value) && $value == (int) $value) {
1091 echo PMA_formatNumber($value, 3, 0);
1092 } elseif (is_numeric($value)) {
1093 echo PMA_formatNumber($value, 3, 1);
1094 } else {
1095 echo htmlspecialchars($value);
1097 if (isset($alerts[$name])) {
1098 echo '</span>';
1100 ?></td>
1101 <td class="descr">
1102 <?php
1103 if (isset($strShowStatus[$name ])) {
1104 echo $strShowStatus[$name];
1107 if (isset($links[$name])) {
1108 foreach ($links[$name] as $link_name => $link_url) {
1109 if ('doc' == $link_name) {
1110 echo PMA_showMySQLDocu($link_url, $link_url);
1111 } else {
1112 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1113 "\n";
1116 unset($link_url, $link_name);
1119 </td>
1120 </tr>
1121 <?php
1124 </tbody>
1125 </table>
1126 <?php
1130 * cleanup of some deprecated values
1132 function cleanDeprecated(&$server_status) {
1133 $deprecated = array(
1134 'Com_prepare_sql' => 'Com_stmt_prepare',
1135 'Com_execute_sql' => 'Com_stmt_execute',
1136 'Com_dealloc_sql' => 'Com_stmt_close',
1139 foreach ($deprecated as $old => $new) {
1140 if (isset($server_status[$old])
1141 && isset($server_status[$new])) {
1142 unset($server_status[$old]);
1148 * Sends the footer
1150 require './libraries/footer.inc.php';