remove the border removal for the Filter field; todo: improve the X reset appearance
[phpmyadmin/dkf.git] / server_status.php
blob64048b311f9cfa46941d1fea249266384bc9ce37
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;
148 * define some alerts
150 // name => max value before alert
151 $alerts = array(
152 // lower is better
153 // variable => max value
154 'Aborted_clients' => 0,
155 'Aborted_connects' => 0,
157 'Binlog_cache_disk_use' => 0,
159 'Created_tmp_disk_tables' => 0,
161 'Handler_read_rnd' => 0,
162 'Handler_read_rnd_next' => 0,
164 'Innodb_buffer_pool_pages_dirty' => 0,
165 'Innodb_buffer_pool_reads' => 0,
166 'Innodb_buffer_pool_wait_free' => 0,
167 'Innodb_log_waits' => 0,
168 'Innodb_row_lock_time_avg' => 10, // ms
169 'Innodb_row_lock_time_max' => 50, // ms
170 'Innodb_row_lock_waits' => 0,
172 'Slow_queries' => 0,
173 'Delayed_errors' => 0,
174 'Select_full_join' => 0,
175 'Select_range_check' => 0,
176 'Sort_merge_passes' => 0,
177 'Opened_tables' => 0,
178 'Table_locks_waited' => 0,
179 'Qcache_lowmem_prunes' => 0,
180 'Slow_launch_threads' => 0,
182 // depends on Key_read_requests
183 // normaly lower then 1:0.01
184 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
185 // depends on Key_write_requests
186 // normaly nearly 1:1
187 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
189 'Key_buffer_fraction' => 0.5,
191 // alert if more than 95% of thread cache is in use
192 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
194 // higher is better
195 // variable => min value
196 //'Handler read key' => '> ',
201 * split variables in sections
203 $allocations = array(
204 // variable name => section
206 'Com_' => 'com',
207 'Innodb_' => 'innodb',
208 'Ndb_' => 'ndb',
209 'Ssl_' => 'ssl',
210 'Handler_' => 'handler',
211 'Qcache_' => 'qcache',
212 'Threads_' => 'threads',
213 'Slow_launch_threads' => 'threads',
215 'Binlog_cache_' => 'binlog_cache',
216 'Created_tmp_' => 'created_tmp',
217 'Key_' => 'key',
219 'Delayed_' => 'delayed',
220 'Not_flushed_delayed_rows' => 'delayed',
222 'Flush_commands' => 'query',
223 'Last_query_cost' => 'query',
224 'Slow_queries' => 'query',
226 'Select_' => 'select',
227 'Sort_' => 'sort',
229 'Open_tables' => 'table',
230 'Opened_tables' => 'table',
231 'Table_locks_' => 'table',
233 'Rpl_status' => 'repl',
234 'Slave_' => 'repl',
236 'Tc_' => 'tc',
239 $sections = array(
240 // section => section name (description)
241 'com' => array('title' => ''),
242 'query' => array('title' => $strSQLQuery),
243 'innodb' => array('title' => 'InnoDB'),
244 'ndb' => array('title' => 'NDB'),
245 'ssl' => array('title' => 'SSL'),
246 'handler' => array('title' => $strHandler),
247 'qcache' => array('title' => $strQueryCache),
248 'threads' => array('title' => $strThreads),
249 'binlog_cache' => array('title' => $strBinaryLog),
250 'created_tmp' => array('title' => $strTempData),
251 'delayed' => array('title' => $strServerStatusDelayedInserts),
252 'key' => array('title' => $strKeyCache),
253 'select' => array('title' => $strJoins),
254 'repl' => array('title' => $strReplication),
255 'sort' => array('title' => $strSorting),
256 'table' => array('title' => $strNumTables),
257 'tc' => array('title' => $strTransactionCoordinator),
261 * define some needfull links/commands
263 // variable or section name => (name => url)
264 $links = array();
266 $links['table'][$strFlushTables]
267 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
268 $links['table'][$strShowOpenTables]
269 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
270 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
272 if ($server_master_status) {
273 $links['repl'][$strShowSlaveHosts]
274 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
275 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
276 $links['repl'][$strShowMasterStatus] = '#replication_master';
278 if ($server_slave_status) {
279 $links['repl'][$strShowSlaveStatus] = '#replication_slave';
282 $links['repl']['doc'] = 'replication';
284 $links['qcache'][$strFlushQueryCache]
285 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
286 PMA_generate_common_url();
287 $links['qcache']['doc'] = 'query_cache';
289 $links['threads'][$strMySQLShowProcess]
290 = 'server_processlist.php?' . PMA_generate_common_url();
291 $links['threads']['doc'] = 'mysql_threads';
293 $links['key']['doc'] = 'myisam_key_cache';
295 $links['binlog_cache']['doc'] = 'binary_log';
297 $links['Slow_queries']['doc'] = 'slow_query_log';
299 $links['innodb'][$strServerTabVariables]
300 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
301 $links['innodb'][$strInnodbStat]
302 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
303 PMA_generate_common_url();
304 $links['innodb']['doc'] = 'innodb';
307 // sort status vars into arrays
308 foreach ($server_status as $name => $value) {
309 if (isset($allocations[$name])) {
310 $sections[$allocations[$name]]['vars'][$name] = $value;
311 unset($server_status[$name]);
312 } else {
313 foreach ($allocations as $filter => $section) {
314 if (preg_match('/^' . $filter . '/', $name)
315 && isset($server_status[$name])) {
316 unset($server_status[$name]);
317 $sections[$section]['vars'][$name] = $value;
322 unset($name, $value, $filter, $section, $allocations);
324 // rest
325 $sections['all']['vars'] =& $server_status;
327 $hour_factor = 3600 / $server_status['Uptime'];
330 * start output
333 <div id="statuslinks">
334 <a href="<?php echo
335 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
336 ><?php echo $strRefresh; ?></a>
337 <a href="<?php echo
338 $PMA_PHP_SELF . '?flush=STATUS&amp;' . PMA_generate_common_url(); ?>"
339 ><?php echo $strShowStatusReset; ?></a>
340 <?php echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?>
341 </div>
344 <?php
345 echo sprintf($strServerStatusUptime,
346 PMA_timespanFormat($server_status['Uptime']),
347 PMA_localisedDate($start_time)) . "\n";
349 </p>
351 <?php
352 if ($server_master_status || $server_slave_status)
354 $replicationOut = "";
355 foreach ($replication_types as $type)
357 if (${"server_{$type}_status"})
359 if ($replicationOut != "")
360 $replicationOut .= $strAndSmall . ' ';
361 $replicationOut .= '<b>' . $type . '</b> ';
364 echo sprintf('<p>' . $strReplicationStatusInfo . '</p>', $replicationOut);
368 <div id="sectionlinks">
369 <?php
370 foreach ($sections as $section_name => $section) {
371 if (! empty($section['vars']) && ! empty($section['title'])) {
372 echo '<a href="' . $PMA_PHP_SELF . '?' .
373 PMA_generate_common_url() . '#' . $section_name . '">' .
374 $section['title'] . '</a>' . "\n";
378 </div>
380 <h3><?php echo $strServerTrafficNotes; ?></h3>
382 <table id="serverstatustraffic" class="data">
383 <thead>
384 <tr>
385 <th colspan="2"><?php echo $strTraffic . '&nbsp;' . PMA_showHint($strStatisticsOverrun); ?></th>
386 <th>&oslash; <?php echo $strPerHour; ?></th>
387 </tr>
388 </thead>
389 <tbody>
390 <tr class="odd">
391 <th class="name"><?php echo $strReceived; ?></th>
392 <td class="value"><?php echo
393 implode(' ',
394 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?></td>
395 <td class="value"><?php echo
396 implode(' ',
397 PMA_formatByteDown(
398 $server_status['Bytes_received'] * $hour_factor, 4)); ?></td>
399 </tr>
400 <tr class="even">
401 <th class="name"><?php echo $strSent; ?></th>
402 <td class="value"><?php echo
403 implode(' ',
404 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?></td>
405 <td class="value"><?php echo
406 implode(' ',
407 PMA_formatByteDown(
408 $server_status['Bytes_sent'] * $hour_factor, 4)); ?></td>
409 </tr>
410 <tr class="odd">
411 <th class="name"><?php echo $strTotalUC; ?></th>
412 <td class="value"><?php echo
413 implode(' ',
414 PMA_formatByteDown(
415 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 4)
416 ); ?></td>
417 <td class="value"><?php echo
418 implode(' ',
419 PMA_formatByteDown(
420 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
421 * $hour_factor, 4)
422 ); ?></td>
423 </tr>
424 </tbody>
425 </table>
427 <table id="serverstatusconnections" class="data">
428 <thead>
429 <tr>
430 <th colspan="2"><?php echo $strConnections; ?></th>
431 <th>&oslash; <?php echo $strPerHour; ?></th>
432 <th>%</th>
433 </tr>
434 </thead>
435 <tbody>
436 <tr class="odd">
437 <th class="name"><?php echo $strMaxConnects; ?></th>
438 <td class="value"><?php echo
439 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
440 <td class="value">--- </td>
441 <td class="value">--- </td>
442 </tr>
443 <tr class="even">
444 <th class="name"><?php echo $strFailedAttempts; ?></th>
445 <td class="value"><?php echo
446 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?></td>
447 <td class="value"><?php echo
448 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
449 4, 2); ?></td>
450 <td class="value"><?php echo
451 $server_status['Connections'] > 0
452 ? PMA_formatNumber(
453 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
454 0, 2) . '%'
455 : '--- '; ?></td>
456 </tr>
457 <tr class="odd">
458 <th class="name"><?php echo $strAbortedClients; ?></th>
459 <td class="value"><?php echo
460 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?></td>
461 <td class="value"><?php echo
462 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
463 4, 2); ?></td>
464 <td class="value"><?php echo
465 $server_status['Connections'] > 0
466 ? PMA_formatNumber(
467 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
468 0, 2) . '%'
469 : '--- '; ?></td>
470 </tr>
471 <tr class="even">
472 <th class="name"><?php echo $strTotalUC; ?></th>
473 <td class="value"><?php echo
474 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
475 <td class="value"><?php echo
476 PMA_formatNumber($server_status['Connections'] * $hour_factor,
477 4, 2); ?></td>
478 <td class="value"><?php echo
479 PMA_formatNumber(100, 0, 2); ?>%</td>
480 </tr>
481 </tbody>
482 </table>
484 <hr class="clearfloat" />
486 <h3><?php echo
487 sprintf($strQueryStatistics,
488 PMA_formatNumber($server_status['Questions'], 0)); ?></h3>
490 <table id="serverstatusqueriessummary" class="data">
491 <thead>
492 <tr>
493 <th><?php echo $strTotalUC; ?></th>
494 <th>&oslash; <?php echo $strPerHour; ?></th>
495 <th>&oslash; <?php echo $strPerMinute; ?></th>
496 <th>&oslash; <?php echo $strPerSecond; ?></th>
497 </tr>
498 </thead>
499 <tbody>
500 <tr class="odd">
501 <td class="value"><?php echo
502 PMA_formatNumber($server_status['Questions'], 4, 0); ?></td>
503 <td class="value"><?php echo
504 PMA_formatNumber($server_status['Questions'] * $hour_factor,
505 3, 2); ?></td>
506 <td class="value"><?php echo
507 PMA_formatNumber(
508 $server_status['Questions'] * 60 / $server_status['Uptime'],
509 3, 2); ?></td>
510 <td class="value"><?php echo
511 PMA_formatNumber(
512 $server_status['Questions'] / $server_status['Uptime'],
513 3, 2); ?></td>
514 </tr>
515 </tbody>
516 </table>
518 <div id="serverstatusqueriesdetails">
519 <?php
521 $used_queries = $sections['com']['vars'];
522 // reverse sort by value to show most used statements first
523 arsort($used_queries);
524 // remove all zero values from the end
525 while (end($used_queries) == 0) {
526 array_pop($used_queries);
529 // number of tables to split values into
530 $tables = 3;
531 $max_rows_per_table = (int) ceil(count($used_queries) / $tables);
532 $current_table = 0;
533 $odd_row = true;
534 $count_displayed_rows = 0;
535 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
537 foreach ($used_queries as $name => $value) {
538 $current_table++;
539 if ($count_displayed_rows === 0 || $count_displayed_rows === $max_rows_per_table) {
540 $odd_row = true;
541 if ($count_displayed_rows === $max_rows_per_table) {
542 echo ' </tbody>' . "\n";
543 echo ' </table>' . "\n";
544 $count_displayed_rows = 0;
547 <table id="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
548 <col class="namecol" />
549 <col class="valuecol" span="3" />
550 <thead>
551 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
552 <th>&oslash; <?php echo $strPerHour; ?></th>
553 <th>%</th>
554 </tr>
555 </thead>
556 <tbody>
557 <?php
558 } else {
559 $odd_row = !$odd_row;
561 $count_displayed_rows++;
563 // For the percentage column, use Questions - Connections, because
564 // the number of connections is not an item of the Query types
565 // but is included in Questions. Then the total of the percentages is 100.
566 $name = str_replace('Com_', '', $name);
567 $name = str_replace('_', ' ', $name);
569 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
570 <th class="name"><?php echo htmlspecialchars($name); ?></th>
571 <td class="value"><?php echo PMA_formatNumber($value, 4, 0); ?></td>
572 <td class="value"><?php echo
573 PMA_formatNumber($value * $hour_factor, 3, 3); ?></td>
574 <td class="value"><?php echo
575 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
576 </tr>
577 <?php
580 </tbody>
581 </table>
582 </div>
584 <div id="serverstatussection">
585 <?php
586 //Unset used variables
587 unset(
588 $tables, $max_rows_per_table, $current_table, $count_displayed_rows, $perc_factor,
589 $hour_factor, $sections['com'],
590 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
591 $server_status['Max_used_connections'], $server_status['Bytes_received'],
592 $server_status['Bytes_sent'], $server_status['Connections'],
593 $server_status['Questions'], $server_status['Uptime'],
594 $used_queries
597 foreach ($sections as $section_name => $section) {
598 if (! empty($section['vars'])) {
600 <table class="data" id="serverstatussection<?php echo $section_name; ?>">
601 <caption class="tblHeaders">
602 <a class="top"
603 href="<?php echo $PMA_PHP_SELF . '?' .
604 PMA_generate_common_url() . '#serverstatus'; ?>"
605 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
606 <?php echo
607 ($GLOBALS['cfg']['MainPageIconic']
608 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
609 's_asc.png" width="11" height="9" align="middle" alt="" />'
610 : ''); ?>
611 </a>
612 <?php
613 if (! empty($section['title'])) {
614 echo $section['title'];
617 </caption>
618 <col class="namecol" />
619 <col class="valuecol" />
620 <col class="descrcol" />
621 <thead>
622 <tr>
623 <th><?php echo $strVar; ?></th>
624 <th><?php echo $strValue; ?></th>
625 <th><?php echo $strDescription; ?></th>
626 </tr>
627 </thead>
628 <?php
629 if (! empty($links[$section_name])) {
631 <tfoot>
632 <tr class="tblFooters">
633 <th colspan="3" class="tblFooters">
634 <?php
635 foreach ($links[$section_name] as $link_name => $link_url) {
636 if ('doc' == $link_name) {
637 echo PMA_showMySQLDocu($link_url, $link_url);
638 } else {
639 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
642 unset($link_url, $link_name);
644 </th>
645 </tr>
646 </tfoot>
647 <?php
650 <tbody>
651 <?php
652 $odd_row = false;
653 foreach ($section['vars'] as $name => $value) {
654 $odd_row = !$odd_row;
656 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
657 <th class="name"><?php echo htmlspecialchars($name); ?></th>
658 <td class="value"><?php
659 if (isset($alerts[$name])) {
660 if ($value > $alerts[$name]) {
661 echo '<span class="attention">';
662 } else {
663 echo '<span class="allfine">';
666 if ('%' === substr($name, -1, 1)) {
667 echo PMA_formatNumber($value, 0, 2) . ' %';
668 } elseif (is_numeric($value) && $value == (int) $value) {
669 echo PMA_formatNumber($value, 4, 0);
670 } elseif (is_numeric($value)) {
671 echo PMA_formatNumber($value, 4, 2);
672 } else {
673 echo htmlspecialchars($value);
675 if (isset($alerts[$name])) {
676 echo '</span>';
678 ?></td>
679 <td class="descr">
680 <?php
681 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
682 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
685 if (isset($links[$name])) {
686 foreach ($links[$name] as $link_name => $link_url) {
687 if ('doc' == $link_name) {
688 echo PMA_showMySQLDocu($link_url, $link_url);
689 } else {
690 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
691 "\n";
694 unset($link_url, $link_name);
697 </td>
698 </tr>
699 <?php
701 unset($name, $value);
703 </tbody>
704 </table>
705 <?php
708 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
710 </div>
711 <?php
712 /* if the server works as master or slave in replication process, display useful information */
713 if ($server_master_status || $server_slave_status)
716 <hr class="clearfloat" />
718 <h3><a name="replication"></a><?php echo $strReplicationStatus; ?></h3>
719 <?php
721 foreach ($replication_types as $type)
723 if (${"server_{$type}_status"}) {
724 PMA_replication_print_status_table($type);
727 unset($types);
731 </div>
733 <?php
735 * Sends the footer
737 require_once './libraries/footer.inc.php';