Merge remote branch 'origin/master'
[phpmyadmin/bananer.git] / server_status.php
bloba6d63bd8e0fa6f0dc9dac31dc3ec65cf03594856
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 * @version $Id$
8 * @package phpMyAdmin
9 */
11 /**
12 * no need for variables importing
13 * @ignore
15 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
16 define('PMA_NO_VARIABLES_IMPORT', true);
18 require_once './libraries/common.inc.php';
20 /**
21 * Does the common work
23 require './libraries/server_common.inc.php';
26 /**
27 * Displays the links
29 require './libraries/server_links.inc.php';
31 /**
32 * Replication library
34 require './libraries/replication.inc.php';
35 require_once './libraries/replication_gui.lib.php';
37 /**
38 * Displays the sub-page heading
40 echo '<div id="serverstatus">' . "\n";
41 echo '<h2>' . "\n"
42 . ($GLOBALS['cfg']['MainPageIconic']
43 ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
44 's_status.png" width="16" height="16" alt="" />'
45 : '')
46 . $strServerStatus . "\n"
47 . '</h2>' . "\n";
50 /**
51 * flush status variables if requested
53 if (isset($_REQUEST['flush'])) {
54 $_flush_commands = array(
55 'STATUS',
56 'TABLES',
57 'QUERY CACHE',
60 if (in_array($_REQUEST['flush'], $_flush_commands)) {
61 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
63 unset($_flush_commands);
67 /**
68 * get status from server
70 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
72 /**
73 * for some calculations we require also some server settings
75 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
77 /**
78 * starttime calculation
80 $start_time = PMA_DBI_fetch_value(
81 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
84 /**
85 * cleanup some deprecated values
87 $deprecated = array(
88 'Com_prepare_sql' => 'Com_stmt_prepare',
89 'Com_execute_sql' => 'Com_stmt_execute',
90 'Com_dealloc_sql' => 'Com_stmt_close',
93 foreach ($deprecated as $old => $new) {
94 if (isset($server_status[$old])
95 && isset($server_status[$new])) {
96 unset($server_status[$old]);
99 unset($deprecated);
103 * calculate some values
105 // Key_buffer_fraction
106 if (isset($server_status['Key_blocks_unused'])
107 && isset($server_variables['key_cache_block_size'])
108 && isset($server_variables['key_buffer_size'])) {
109 $server_status['Key_buffer_fraction_%'] =
111 - $server_status['Key_blocks_unused']
112 * $server_variables['key_cache_block_size']
113 / $server_variables['key_buffer_size']
114 * 100;
115 } elseif (
116 isset($server_status['Key_blocks_used'])
117 && isset($server_variables['key_buffer_size'])) {
118 $server_status['Key_buffer_fraction_%'] =
119 $server_status['Key_blocks_used']
120 * 1024
121 / $server_variables['key_buffer_size'];
124 // Ratio for key read/write
125 if (isset($server_status['Key_writes'])
126 && isset($server_status['Key_write_requests'])
127 && $server_status['Key_write_requests'] > 0)
128 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
130 if (isset($server_status['Key_reads'])
131 && isset($server_status['Key_read_requests'])
132 && $server_status['Key_read_requests'] > 0)
133 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
135 // Threads_cache_hitrate
136 if (isset($server_status['Threads_created'])
137 && isset($server_status['Connections'])
138 && $server_status['Connections'] > 0) {
139 $server_status['Threads_cache_hitrate_%'] =
141 - $server_status['Threads_created']
142 / $server_status['Connections']
143 * 100;
146 // Format Uptime_since_flush_status : show as days, hours, minutes, seconds
147 if (isset($server_status['Uptime_since_flush_status'])) {
148 $server_status['Uptime_since_flush_status'] = PMA_timespanFormat($server_status['Uptime_since_flush_status']);
152 * define some alerts
154 // name => max value before alert
155 $alerts = array(
156 // lower is better
157 // variable => max value
158 'Aborted_clients' => 0,
159 'Aborted_connects' => 0,
161 'Binlog_cache_disk_use' => 0,
163 'Created_tmp_disk_tables' => 0,
165 'Handler_read_rnd' => 0,
166 'Handler_read_rnd_next' => 0,
168 'Innodb_buffer_pool_pages_dirty' => 0,
169 'Innodb_buffer_pool_reads' => 0,
170 'Innodb_buffer_pool_wait_free' => 0,
171 'Innodb_log_waits' => 0,
172 'Innodb_row_lock_time_avg' => 10, // ms
173 'Innodb_row_lock_time_max' => 50, // ms
174 'Innodb_row_lock_waits' => 0,
176 'Slow_queries' => 0,
177 'Delayed_errors' => 0,
178 'Select_full_join' => 0,
179 'Select_range_check' => 0,
180 'Sort_merge_passes' => 0,
181 'Opened_tables' => 0,
182 'Table_locks_waited' => 0,
183 'Qcache_lowmem_prunes' => 0,
184 'Slow_launch_threads' => 0,
186 // depends on Key_read_requests
187 // normaly lower then 1:0.01
188 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
189 // depends on Key_write_requests
190 // normaly nearly 1:1
191 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
193 'Key_buffer_fraction' => 0.5,
195 // alert if more than 95% of thread cache is in use
196 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
198 // higher is better
199 // variable => min value
200 //'Handler read key' => '> ',
205 * split variables in sections
207 $allocations = array(
208 // variable name => section
210 'Com_' => 'com',
211 'Innodb_' => 'innodb',
212 'Ndb_' => 'ndb',
213 'Handler_' => 'handler',
214 'Qcache_' => 'qcache',
215 'Threads_' => 'threads',
216 'Slow_launch_threads' => 'threads',
218 'Binlog_cache_' => 'binlog_cache',
219 'Created_tmp_' => 'created_tmp',
220 'Key_' => 'key',
222 'Delayed_' => 'delayed',
223 'Not_flushed_delayed_rows' => 'delayed',
225 'Flush_commands' => 'query',
226 'Last_query_cost' => 'query',
227 'Slow_queries' => 'query',
229 'Select_' => 'select',
230 'Sort_' => 'sort',
232 'Open_tables' => 'table',
233 'Opened_tables' => 'table',
234 'Table_locks_' => 'table',
236 'Rpl_status' => 'repl',
237 'Slave_' => 'repl',
239 'Tc_' => 'tc',
241 'Ssl_' => 'ssl',
244 $sections = array(
245 // section => section name (description)
246 'com' => array('title' => ''),
247 'query' => array('title' => $strSQLQuery),
248 'innodb' => array('title' => 'InnoDB'),
249 'ndb' => array('title' => 'NDB'),
250 'handler' => array('title' => $strHandler),
251 'qcache' => array('title' => $strQueryCache),
252 'threads' => array('title' => $strThreads),
253 'binlog_cache' => array('title' => $strBinaryLog),
254 'created_tmp' => array('title' => $strTempData),
255 'delayed' => array('title' => $strServerStatusDelayedInserts),
256 'key' => array('title' => $strKeyCache),
257 'select' => array('title' => $strJoins),
258 'repl' => array('title' => $strReplication),
259 'sort' => array('title' => $strSorting),
260 'table' => array('title' => $strNumTables),
261 'tc' => array('title' => $strTransactionCoordinator),
262 'ssl' => array('title' => 'SSL'),
266 * define some needfull links/commands
268 // variable or section name => (name => url)
269 $links = array();
271 $links['table'][$strFlushTables]
272 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
273 $links['table'][$strShowOpenTables]
274 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
275 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
277 if ($server_master_status) {
278 $links['repl'][$strShowSlaveHosts]
279 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
280 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
281 $links['repl'][$strShowMasterStatus] = '#replication_master';
283 if ($server_slave_status) {
284 $links['repl'][$strShowSlaveStatus] = '#replication_slave';
287 $links['repl']['doc'] = 'replication';
289 $links['qcache'][$strFlushQueryCache]
290 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
291 PMA_generate_common_url();
292 $links['qcache']['doc'] = 'query_cache';
294 $links['threads'][$strMySQLShowProcess]
295 = 'server_processlist.php?' . PMA_generate_common_url();
296 $links['threads']['doc'] = 'mysql_threads';
298 $links['key']['doc'] = 'myisam_key_cache';
300 $links['binlog_cache']['doc'] = 'binary_log';
302 $links['Slow_queries']['doc'] = 'slow_query_log';
304 $links['innodb'][$strServerTabVariables]
305 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
306 $links['innodb'][$strInnodbStat]
307 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
308 PMA_generate_common_url();
309 $links['innodb']['doc'] = 'innodb';
312 // sort status vars into arrays
313 foreach ($server_status as $name => $value) {
314 if (isset($allocations[$name])) {
315 $sections[$allocations[$name]]['vars'][$name] = $value;
316 unset($server_status[$name]);
317 } else {
318 foreach ($allocations as $filter => $section) {
319 if (preg_match('/^' . $filter . '/', $name)
320 && isset($server_status[$name])) {
321 unset($server_status[$name]);
322 $sections[$section]['vars'][$name] = $value;
327 unset($name, $value, $filter, $section, $allocations);
329 // rest
330 $sections['all']['vars'] =& $server_status;
332 $hour_factor = 3600 / $server_status['Uptime'];
335 * start output
338 <div id="statuslinks">
339 <a href="<?php echo
340 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
341 ><?php echo $strRefresh; ?></a>
342 <a href="<?php echo
343 $PMA_PHP_SELF . '?flush=STATUS&amp;' . PMA_generate_common_url(); ?>"
344 ><?php echo $strShowStatusReset; ?></a>
345 <?php echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?>
346 </div>
349 <?php
350 echo sprintf($strServerStatusUptime,
351 PMA_timespanFormat($server_status['Uptime']),
352 PMA_localisedDate($start_time)) . "\n";
354 </p>
356 <?php
357 if ($server_master_status || $server_slave_status)
359 $replicationOut = "";
360 foreach ($replication_types as $type)
362 if (${"server_{$type}_status"})
364 if ($replicationOut != "")
365 $replicationOut .= $strAndSmall . ' ';
366 $replicationOut .= '<b>' . $type . '</b> ';
369 echo sprintf('<p>' . $strReplicationStatusInfo . '</p>', $replicationOut);
373 <div id="sectionlinks">
374 <?php
375 foreach ($sections as $section_name => $section) {
376 if (! empty($section['vars']) && ! empty($section['title'])) {
377 echo '<a href="' . $PMA_PHP_SELF . '?' .
378 PMA_generate_common_url() . '#' . $section_name . '">' .
379 $section['title'] . '</a>' . "\n";
383 </div>
385 <h3><?php echo $strServerTrafficNotes; ?></h3>
387 <table id="serverstatustraffic" class="data">
388 <thead>
389 <tr>
390 <th colspan="2"><?php echo $strTraffic . '&nbsp;' . PMA_showHint($strStatisticsOverrun); ?></th>
391 <th>&oslash; <?php echo $strPerHour; ?></th>
392 </tr>
393 </thead>
394 <tbody>
395 <tr class="odd">
396 <th class="name"><?php echo $strReceived; ?></th>
397 <td class="value"><?php echo
398 implode(' ',
399 PMA_formatByteDown($server_status['Bytes_received'], 2, 1)); ?></td>
400 <td class="value"><?php echo
401 implode(' ',
402 PMA_formatByteDown(
403 $server_status['Bytes_received'] * $hour_factor, 2, 1)); ?></td>
404 </tr>
405 <tr class="even">
406 <th class="name"><?php echo $strSent; ?></th>
407 <td class="value"><?php echo
408 implode(' ',
409 PMA_formatByteDown($server_status['Bytes_sent'], 2, 1)); ?></td>
410 <td class="value"><?php echo
411 implode(' ',
412 PMA_formatByteDown(
413 $server_status['Bytes_sent'] * $hour_factor, 2, 1)); ?></td>
414 </tr>
415 <tr class="odd">
416 <th class="name"><?php echo $strTotalUC; ?></th>
417 <td class="value"><?php echo
418 implode(' ',
419 PMA_formatByteDown(
420 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 2, 1)
421 ); ?></td>
422 <td class="value"><?php echo
423 implode(' ',
424 PMA_formatByteDown(
425 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
426 * $hour_factor, 2, 1)
427 ); ?></td>
428 </tr>
429 </tbody>
430 </table>
432 <table id="serverstatusconnections" class="data">
433 <thead>
434 <tr>
435 <th colspan="2"><?php echo $strConnections; ?></th>
436 <th>&oslash; <?php echo $strPerHour; ?></th>
437 <th>%</th>
438 </tr>
439 </thead>
440 <tbody>
441 <tr class="odd">
442 <th class="name"><?php echo $strMaxConnects; ?></th>
443 <td class="value"><?php echo
444 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
445 <td class="value">--- </td>
446 <td class="value">--- </td>
447 </tr>
448 <tr class="even">
449 <th class="name"><?php echo $strFailedAttempts; ?></th>
450 <td class="value"><?php echo
451 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?></td>
452 <td class="value"><?php echo
453 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
454 4, 2); ?></td>
455 <td class="value"><?php echo
456 $server_status['Connections'] > 0
457 ? PMA_formatNumber(
458 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
459 0, 2) . '%'
460 : '--- '; ?></td>
461 </tr>
462 <tr class="odd">
463 <th class="name"><?php echo $strAbortedClients; ?></th>
464 <td class="value"><?php echo
465 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?></td>
466 <td class="value"><?php echo
467 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
468 4, 2); ?></td>
469 <td class="value"><?php echo
470 $server_status['Connections'] > 0
471 ? PMA_formatNumber(
472 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
473 0, 2) . '%'
474 : '--- '; ?></td>
475 </tr>
476 <tr class="even">
477 <th class="name"><?php echo $strTotalUC; ?></th>
478 <td class="value"><?php echo
479 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
480 <td class="value"><?php echo
481 PMA_formatNumber($server_status['Connections'] * $hour_factor,
482 4, 2); ?></td>
483 <td class="value"><?php echo
484 PMA_formatNumber(100, 0, 2); ?>%</td>
485 </tr>
486 </tbody>
487 </table>
489 <hr class="clearfloat" />
491 <h3><?php echo
492 sprintf($strQueryStatistics,
493 PMA_formatNumber($server_status['Questions'], 0)); ?></h3>
495 <table id="serverstatusqueriessummary" class="data">
496 <thead>
497 <tr>
498 <th><?php echo $strTotalUC; ?></th>
499 <th>&oslash; <?php echo $strPerHour; ?></th>
500 <th>&oslash; <?php echo $strPerMinute; ?></th>
501 <th>&oslash; <?php echo $strPerSecond; ?></th>
502 </tr>
503 </thead>
504 <tbody>
505 <tr class="odd">
506 <td class="value"><?php echo
507 PMA_formatNumber($server_status['Questions'], 4, 0); ?></td>
508 <td class="value"><?php echo
509 PMA_formatNumber($server_status['Questions'] * $hour_factor,
510 3, 2); ?></td>
511 <td class="value"><?php echo
512 PMA_formatNumber(
513 $server_status['Questions'] * 60 / $server_status['Uptime'],
514 3, 2); ?></td>
515 <td class="value"><?php echo
516 PMA_formatNumber(
517 $server_status['Questions'] / $server_status['Uptime'],
518 3, 2); ?></td>
519 </tr>
520 </tbody>
521 </table>
523 <div id="serverstatusqueriesdetails">
524 <?php
526 $used_queries = $sections['com']['vars'];
527 // reverse sort by value to show most used statements first
528 arsort($used_queries);
529 // remove all zero values from the end
530 while (end($used_queries) == 0) {
531 array_pop($used_queries);
534 // number of tables to split values into
535 $tables = 3;
536 $max_rows_per_table = (int) ceil(count($used_queries) / $tables);
537 $current_table = 0;
538 $odd_row = true;
539 $count_displayed_rows = 0;
540 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
542 foreach ($used_queries as $name => $value) {
543 $current_table++;
544 if ($count_displayed_rows === 0 || $count_displayed_rows === $max_rows_per_table) {
545 $odd_row = true;
546 if ($count_displayed_rows === $max_rows_per_table) {
547 echo ' </tbody>' . "\n";
548 echo ' </table>' . "\n";
549 $count_displayed_rows = 0;
552 <table id="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
553 <col class="namecol" />
554 <col class="valuecol" span="3" />
555 <thead>
556 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
557 <th>&oslash; <?php echo $strPerHour; ?></th>
558 <th>%</th>
559 </tr>
560 </thead>
561 <tbody>
562 <?php
563 } else {
564 $odd_row = !$odd_row;
566 $count_displayed_rows++;
568 // For the percentage column, use Questions - Connections, because
569 // the number of connections is not an item of the Query types
570 // but is included in Questions. Then the total of the percentages is 100.
571 $name = str_replace('Com_', '', $name);
572 $name = str_replace('_', ' ', $name);
574 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
575 <th class="name"><?php echo htmlspecialchars($name); ?></th>
576 <td class="value"><?php echo PMA_formatNumber($value, 4, 0); ?></td>
577 <td class="value"><?php echo
578 PMA_formatNumber($value * $hour_factor, 3, 3); ?></td>
579 <td class="value"><?php echo
580 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
581 </tr>
582 <?php
585 </tbody>
586 </table>
587 </div>
589 <div id="serverstatussection">
590 <?php
591 //Unset used variables
592 unset(
593 $tables, $max_rows_per_table, $current_table, $count_displayed_rows, $perc_factor,
594 $hour_factor, $sections['com'],
595 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
596 $server_status['Max_used_connections'], $server_status['Bytes_received'],
597 $server_status['Bytes_sent'], $server_status['Connections'],
598 $server_status['Questions'], $server_status['Uptime'],
599 $used_queries
602 foreach ($sections as $section_name => $section) {
603 if (! empty($section['vars'])) {
605 <table class="data" id="serverstatussection<?php echo $section_name; ?>">
606 <caption class="tblHeaders">
607 <a class="top"
608 href="<?php echo $PMA_PHP_SELF . '?' .
609 PMA_generate_common_url() . '#serverstatus'; ?>"
610 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
611 <?php echo
612 ($GLOBALS['cfg']['MainPageIconic']
613 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
614 's_asc.png" width="11" height="9" align="middle" alt="" />'
615 : ''); ?>
616 </a>
617 <?php
618 if (! empty($section['title'])) {
619 echo $section['title'];
622 </caption>
623 <col class="namecol" />
624 <col class="valuecol" />
625 <col class="descrcol" />
626 <thead>
627 <tr>
628 <th><?php echo $strVar; ?></th>
629 <th><?php echo $strValue; ?></th>
630 <th><?php echo $strDescription; ?></th>
631 </tr>
632 </thead>
633 <?php
634 if (! empty($links[$section_name])) {
636 <tfoot>
637 <tr class="tblFooters">
638 <th colspan="3" class="tblFooters">
639 <?php
640 foreach ($links[$section_name] as $link_name => $link_url) {
641 if ('doc' == $link_name) {
642 echo PMA_showMySQLDocu($link_url, $link_url);
643 } else {
644 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
647 unset($link_url, $link_name);
649 </th>
650 </tr>
651 </tfoot>
652 <?php
655 <tbody>
656 <?php
657 $odd_row = false;
658 foreach ($section['vars'] as $name => $value) {
659 $odd_row = !$odd_row;
661 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
662 <th class="name"><?php echo htmlspecialchars($name); ?></th>
663 <td class="value"><?php
664 if (isset($alerts[$name])) {
665 if ($value > $alerts[$name]) {
666 echo '<span class="attention">';
667 } else {
668 echo '<span class="allfine">';
671 if ('%' === substr($name, -1, 1)) {
672 echo PMA_formatNumber($value, 0, 2) . ' %';
673 } elseif (is_numeric($value) && $value == (int) $value) {
674 echo PMA_formatNumber($value, 3, 1);
675 } elseif (is_numeric($value)) {
676 echo PMA_formatNumber($value, 3, 1);
677 } else {
678 echo htmlspecialchars($value);
680 if (isset($alerts[$name])) {
681 echo '</span>';
683 ?></td>
684 <td class="descr">
685 <?php
686 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
687 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
690 if (isset($links[$name])) {
691 foreach ($links[$name] as $link_name => $link_url) {
692 if ('doc' == $link_name) {
693 echo PMA_showMySQLDocu($link_url, $link_url);
694 } else {
695 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
696 "\n";
699 unset($link_url, $link_name);
702 </td>
703 </tr>
704 <?php
706 unset($name, $value);
708 </tbody>
709 </table>
710 <?php
713 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
715 </div>
716 <?php
717 /* if the server works as master or slave in replication process, display useful information */
718 if ($server_master_status || $server_slave_status)
721 <hr class="clearfloat" />
723 <h3><a name="replication"></a><?php echo $strReplicationStatus; ?></h3>
724 <?php
726 foreach ($replication_types as $type)
728 if (${"server_{$type}_status"}) {
729 PMA_replication_print_status_table($type);
732 unset($types);
736 </div>
738 <?php
740 * Sends the footer
742 require_once './libraries/footer.inc.php';