Translation update done using Pootle.
[phpmyadmin-themes.git] / server_status.php
blobec6083a1941d0a5c4d27356ee2f7a994dea9d8df
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 'Handler_' => 'handler',
210 'Qcache_' => 'qcache',
211 'Threads_' => 'threads',
212 'Slow_launch_threads' => 'threads',
214 'Binlog_cache_' => 'binlog_cache',
215 'Created_tmp_' => 'created_tmp',
216 'Key_' => 'key',
218 'Delayed_' => 'delayed',
219 'Not_flushed_delayed_rows' => 'delayed',
221 'Flush_commands' => 'query',
222 'Last_query_cost' => 'query',
223 'Slow_queries' => 'query',
225 'Select_' => 'select',
226 'Sort_' => 'sort',
228 'Open_tables' => 'table',
229 'Opened_tables' => 'table',
230 'Table_locks_' => 'table',
232 'Rpl_status' => 'repl',
233 'Slave_' => 'repl',
235 'Tc_' => 'tc',
237 'Ssl_' => 'ssl',
240 $sections = array(
241 // section => section name (description)
242 'com' => array('title' => ''),
243 'query' => array('title' => $strSQLQuery),
244 'innodb' => array('title' => 'InnoDB'),
245 'ndb' => array('title' => 'NDB'),
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),
258 'ssl' => array('title' => 'SSL'),
262 * define some needfull links/commands
264 // variable or section name => (name => url)
265 $links = array();
267 $links['table'][$strFlushTables]
268 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
269 $links['table'][$strShowOpenTables]
270 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
271 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
273 if ($server_master_status) {
274 $links['repl'][$strShowSlaveHosts]
275 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
276 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
277 $links['repl'][$strShowMasterStatus] = '#replication_master';
279 if ($server_slave_status) {
280 $links['repl'][$strShowSlaveStatus] = '#replication_slave';
283 $links['repl']['doc'] = 'replication';
285 $links['qcache'][$strFlushQueryCache]
286 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
287 PMA_generate_common_url();
288 $links['qcache']['doc'] = 'query_cache';
290 $links['threads'][$strMySQLShowProcess]
291 = 'server_processlist.php?' . PMA_generate_common_url();
292 $links['threads']['doc'] = 'mysql_threads';
294 $links['key']['doc'] = 'myisam_key_cache';
296 $links['binlog_cache']['doc'] = 'binary_log';
298 $links['Slow_queries']['doc'] = 'slow_query_log';
300 $links['innodb'][$strServerTabVariables]
301 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
302 $links['innodb'][$strInnodbStat]
303 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
304 PMA_generate_common_url();
305 $links['innodb']['doc'] = 'innodb';
308 // sort status vars into arrays
309 foreach ($server_status as $name => $value) {
310 if (isset($allocations[$name])) {
311 $sections[$allocations[$name]]['vars'][$name] = $value;
312 unset($server_status[$name]);
313 } else {
314 foreach ($allocations as $filter => $section) {
315 if (preg_match('/^' . $filter . '/', $name)
316 && isset($server_status[$name])) {
317 unset($server_status[$name]);
318 $sections[$section]['vars'][$name] = $value;
323 unset($name, $value, $filter, $section, $allocations);
325 // rest
326 $sections['all']['vars'] =& $server_status;
328 $hour_factor = 3600 / $server_status['Uptime'];
331 * start output
334 <div id="statuslinks">
335 <a href="<?php echo
336 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
337 ><?php echo $strRefresh; ?></a>
338 <a href="<?php echo
339 $PMA_PHP_SELF . '?flush=STATUS&amp;' . PMA_generate_common_url(); ?>"
340 ><?php echo $strShowStatusReset; ?></a>
341 <?php echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?>
342 </div>
345 <?php
346 echo sprintf($strServerStatusUptime,
347 PMA_timespanFormat($server_status['Uptime']),
348 PMA_localisedDate($start_time)) . "\n";
350 </p>
352 <?php
353 if ($server_master_status || $server_slave_status)
355 $replicationOut = "";
356 foreach ($replication_types as $type)
358 if (${"server_{$type}_status"})
360 if ($replicationOut != "")
361 $replicationOut .= $strAndSmall . ' ';
362 $replicationOut .= '<b>' . $type . '</b> ';
365 echo sprintf('<p>' . $strReplicationStatusInfo . '</p>', $replicationOut);
369 <div id="sectionlinks">
370 <?php
371 foreach ($sections as $section_name => $section) {
372 if (! empty($section['vars']) && ! empty($section['title'])) {
373 echo '<a href="' . $PMA_PHP_SELF . '?' .
374 PMA_generate_common_url() . '#' . $section_name . '">' .
375 $section['title'] . '</a>' . "\n";
379 </div>
381 <h3><?php echo $strServerTrafficNotes; ?></h3>
383 <table id="serverstatustraffic" class="data">
384 <thead>
385 <tr>
386 <th colspan="2"><?php echo $strTraffic . '&nbsp;' . PMA_showHint($strStatisticsOverrun); ?></th>
387 <th>&oslash; <?php echo $strPerHour; ?></th>
388 </tr>
389 </thead>
390 <tbody>
391 <tr class="odd">
392 <th class="name"><?php echo $strReceived; ?></th>
393 <td class="value"><?php echo
394 implode(' ',
395 PMA_formatByteDown($server_status['Bytes_received'], 2, 1)); ?></td>
396 <td class="value"><?php echo
397 implode(' ',
398 PMA_formatByteDown(
399 $server_status['Bytes_received'] * $hour_factor, 2, 1)); ?></td>
400 </tr>
401 <tr class="even">
402 <th class="name"><?php echo $strSent; ?></th>
403 <td class="value"><?php echo
404 implode(' ',
405 PMA_formatByteDown($server_status['Bytes_sent'], 2, 1)); ?></td>
406 <td class="value"><?php echo
407 implode(' ',
408 PMA_formatByteDown(
409 $server_status['Bytes_sent'] * $hour_factor, 2, 1)); ?></td>
410 </tr>
411 <tr class="odd">
412 <th class="name"><?php echo $strTotalUC; ?></th>
413 <td class="value"><?php echo
414 implode(' ',
415 PMA_formatByteDown(
416 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 2, 1)
417 ); ?></td>
418 <td class="value"><?php echo
419 implode(' ',
420 PMA_formatByteDown(
421 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
422 * $hour_factor, 2, 1)
423 ); ?></td>
424 </tr>
425 </tbody>
426 </table>
428 <table id="serverstatusconnections" class="data">
429 <thead>
430 <tr>
431 <th colspan="2"><?php echo $strConnections; ?></th>
432 <th>&oslash; <?php echo $strPerHour; ?></th>
433 <th>%</th>
434 </tr>
435 </thead>
436 <tbody>
437 <tr class="odd">
438 <th class="name"><?php echo $strMaxConnects; ?></th>
439 <td class="value"><?php echo
440 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
441 <td class="value">--- </td>
442 <td class="value">--- </td>
443 </tr>
444 <tr class="even">
445 <th class="name"><?php echo $strFailedAttempts; ?></th>
446 <td class="value"><?php echo
447 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?></td>
448 <td class="value"><?php echo
449 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
450 4, 2); ?></td>
451 <td class="value"><?php echo
452 $server_status['Connections'] > 0
453 ? PMA_formatNumber(
454 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
455 0, 2) . '%'
456 : '--- '; ?></td>
457 </tr>
458 <tr class="odd">
459 <th class="name"><?php echo $strAbortedClients; ?></th>
460 <td class="value"><?php echo
461 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?></td>
462 <td class="value"><?php echo
463 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
464 4, 2); ?></td>
465 <td class="value"><?php echo
466 $server_status['Connections'] > 0
467 ? PMA_formatNumber(
468 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
469 0, 2) . '%'
470 : '--- '; ?></td>
471 </tr>
472 <tr class="even">
473 <th class="name"><?php echo $strTotalUC; ?></th>
474 <td class="value"><?php echo
475 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
476 <td class="value"><?php echo
477 PMA_formatNumber($server_status['Connections'] * $hour_factor,
478 4, 2); ?></td>
479 <td class="value"><?php echo
480 PMA_formatNumber(100, 0, 2); ?>%</td>
481 </tr>
482 </tbody>
483 </table>
485 <hr class="clearfloat" />
487 <h3><?php echo
488 sprintf($strQueryStatistics,
489 PMA_formatNumber($server_status['Questions'], 0)); ?></h3>
491 <table id="serverstatusqueriessummary" class="data">
492 <thead>
493 <tr>
494 <th><?php echo $strTotalUC; ?></th>
495 <th>&oslash; <?php echo $strPerHour; ?></th>
496 <th>&oslash; <?php echo $strPerMinute; ?></th>
497 <th>&oslash; <?php echo $strPerSecond; ?></th>
498 </tr>
499 </thead>
500 <tbody>
501 <tr class="odd">
502 <td class="value"><?php echo
503 PMA_formatNumber($server_status['Questions'], 4, 0); ?></td>
504 <td class="value"><?php echo
505 PMA_formatNumber($server_status['Questions'] * $hour_factor,
506 3, 2); ?></td>
507 <td class="value"><?php echo
508 PMA_formatNumber(
509 $server_status['Questions'] * 60 / $server_status['Uptime'],
510 3, 2); ?></td>
511 <td class="value"><?php echo
512 PMA_formatNumber(
513 $server_status['Questions'] / $server_status['Uptime'],
514 3, 2); ?></td>
515 </tr>
516 </tbody>
517 </table>
519 <div id="serverstatusqueriesdetails">
520 <?php
522 $used_queries = $sections['com']['vars'];
523 // reverse sort by value to show most used statements first
524 arsort($used_queries);
525 // remove all zero values from the end
526 while (end($used_queries) == 0) {
527 array_pop($used_queries);
530 // number of tables to split values into
531 $tables = 3;
532 $max_rows_per_table = (int) ceil(count($used_queries) / $tables);
533 $current_table = 0;
534 $odd_row = true;
535 $count_displayed_rows = 0;
536 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
538 foreach ($used_queries as $name => $value) {
539 $current_table++;
540 if ($count_displayed_rows === 0 || $count_displayed_rows === $max_rows_per_table) {
541 $odd_row = true;
542 if ($count_displayed_rows === $max_rows_per_table) {
543 echo ' </tbody>' . "\n";
544 echo ' </table>' . "\n";
545 $count_displayed_rows = 0;
548 <table id="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
549 <col class="namecol" />
550 <col class="valuecol" span="3" />
551 <thead>
552 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
553 <th>&oslash; <?php echo $strPerHour; ?></th>
554 <th>%</th>
555 </tr>
556 </thead>
557 <tbody>
558 <?php
559 } else {
560 $odd_row = !$odd_row;
562 $count_displayed_rows++;
564 // For the percentage column, use Questions - Connections, because
565 // the number of connections is not an item of the Query types
566 // but is included in Questions. Then the total of the percentages is 100.
567 $name = str_replace('Com_', '', $name);
568 $name = str_replace('_', ' ', $name);
570 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
571 <th class="name"><?php echo htmlspecialchars($name); ?></th>
572 <td class="value"><?php echo PMA_formatNumber($value, 4, 0); ?></td>
573 <td class="value"><?php echo
574 PMA_formatNumber($value * $hour_factor, 3, 3); ?></td>
575 <td class="value"><?php echo
576 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
577 </tr>
578 <?php
581 </tbody>
582 </table>
583 </div>
585 <div id="serverstatussection">
586 <?php
587 //Unset used variables
588 unset(
589 $tables, $max_rows_per_table, $current_table, $count_displayed_rows, $perc_factor,
590 $hour_factor, $sections['com'],
591 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
592 $server_status['Max_used_connections'], $server_status['Bytes_received'],
593 $server_status['Bytes_sent'], $server_status['Connections'],
594 $server_status['Questions'], $server_status['Uptime'],
595 $used_queries
598 foreach ($sections as $section_name => $section) {
599 if (! empty($section['vars'])) {
601 <table class="data" id="serverstatussection<?php echo $section_name; ?>">
602 <caption class="tblHeaders">
603 <a class="top"
604 href="<?php echo $PMA_PHP_SELF . '?' .
605 PMA_generate_common_url() . '#serverstatus'; ?>"
606 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
607 <?php echo
608 ($GLOBALS['cfg']['MainPageIconic']
609 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
610 's_asc.png" width="11" height="9" align="middle" alt="" />'
611 : ''); ?>
612 </a>
613 <?php
614 if (! empty($section['title'])) {
615 echo $section['title'];
618 </caption>
619 <col class="namecol" />
620 <col class="valuecol" />
621 <col class="descrcol" />
622 <thead>
623 <tr>
624 <th><?php echo $strVar; ?></th>
625 <th><?php echo $strValue; ?></th>
626 <th><?php echo $strDescription; ?></th>
627 </tr>
628 </thead>
629 <?php
630 if (! empty($links[$section_name])) {
632 <tfoot>
633 <tr class="tblFooters">
634 <th colspan="3" class="tblFooters">
635 <?php
636 foreach ($links[$section_name] as $link_name => $link_url) {
637 if ('doc' == $link_name) {
638 echo PMA_showMySQLDocu($link_url, $link_url);
639 } else {
640 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
643 unset($link_url, $link_name);
645 </th>
646 </tr>
647 </tfoot>
648 <?php
651 <tbody>
652 <?php
653 $odd_row = false;
654 foreach ($section['vars'] as $name => $value) {
655 $odd_row = !$odd_row;
657 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
658 <th class="name"><?php echo htmlspecialchars($name); ?></th>
659 <td class="value"><?php
660 if (isset($alerts[$name])) {
661 if ($value > $alerts[$name]) {
662 echo '<span class="attention">';
663 } else {
664 echo '<span class="allfine">';
667 if ('%' === substr($name, -1, 1)) {
668 echo PMA_formatNumber($value, 0, 2) . ' %';
669 } elseif (is_numeric($value) && $value == (int) $value) {
670 echo PMA_formatNumber($value, 3, 1);
671 } elseif (is_numeric($value)) {
672 echo PMA_formatNumber($value, 3, 1);
673 } else {
674 echo htmlspecialchars($value);
676 if (isset($alerts[$name])) {
677 echo '</span>';
679 ?></td>
680 <td class="descr">
681 <?php
682 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
683 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
686 if (isset($links[$name])) {
687 foreach ($links[$name] as $link_name => $link_url) {
688 if ('doc' == $link_name) {
689 echo PMA_showMySQLDocu($link_url, $link_url);
690 } else {
691 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
692 "\n";
695 unset($link_url, $link_name);
698 </td>
699 </tr>
700 <?php
702 unset($name, $value);
704 </tbody>
705 </table>
706 <?php
709 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
711 </div>
712 <?php
713 /* if the server works as master or slave in replication process, display useful information */
714 if ($server_master_status || $server_slave_status)
717 <hr class="clearfloat" />
719 <h3><a name="replication"></a><?php echo $strReplicationStatus; ?></h3>
720 <?php
722 foreach ($replication_types as $type)
724 if (${"server_{$type}_status"}) {
725 PMA_replication_print_status_table($type);
728 unset($types);
732 </div>
734 <?php
736 * Sends the footer
738 require_once './libraries/footer.inc.php';