Add IF NOT EXISTS to CREATE DATABASE query (RFE #1608372), reload navigation after...
[phpmyadmin/crack.git] / server_status.php
blob5dffe0dce492a9a40e918907c875f318ce5417fd
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4 /**
5 * displays status variables with descriptions and some hints an optmizing
6 * + reset status variables
7 */
8 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
9 define('PMA_NO_VARIABLES_IMPORT', true);
11 require_once './libraries/common.lib.php';
13 /**
14 * Does the common work
16 require './libraries/server_common.inc.php';
19 /**
20 * Displays the links
22 require './libraries/server_links.inc.php';
25 /**
26 * Displays the sub-page heading
28 echo '<div id="serverstatus">' . "\n";
29 echo '<h2>' . "\n"
30 . ($GLOBALS['cfg']['MainPageIconic']
31 ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
32 's_status.png" width="16" height="16" alt="" />'
33 : '')
34 . $strServerStatus . "\n"
35 . '</h2>' . "\n";
38 /**
39 * flush status variables if requested
41 if (isset($_REQUEST['flush'])) {
42 $_flush_commands = array(
43 'STATUS',
44 'TABLES',
45 'QUERY CACHE',
48 if (in_array($_REQUEST['flush'], $_flush_commands)) {
49 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
51 unset($_flush_commands);
55 /**
56 * get status from server
58 if (PMA_MYSQL_INT_VERSION >= 50002) {
59 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
60 } else {
61 $server_status = PMA_DBI_fetch_result('SHOW STATUS', 0, 1);
65 /**
66 * for some calculations we require also some server settings
68 if (PMA_MYSQL_INT_VERSION >= 40003) {
69 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
70 } else {
71 $server_variables = PMA_DBI_fetch_result('SHOW VARIABLES', 0, 1);
75 /**
76 * starttime calculation
78 $start_time = PMA_DBI_fetch_value(
79 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
82 /**
83 * cleanup some deprecated values
85 $deprecated = array(
86 'Com_prepare_sql' => 'Com_stmt_prepare',
87 'Com_execute_sql' => 'Com_stmt_execute',
88 'Com_dealloc_sql' => 'Com_stmt_close',
91 foreach ($deprecated as $old => $new) {
92 if (isset($server_status[$old])
93 && isset($server_status[$new])) {
94 unset($server_status[$old]);
97 unset($deprecated);
101 * calculate some values
103 // Key_buffer_fraction
104 if (isset($server_status['Key_blocks_unused'])
105 && isset($server_variables['key_cache_block_size'])
106 && isset($server_variables['key_buffer_size'])) {
107 $server_status['Key_buffer_fraction_%'] =
109 - $server_status['Key_blocks_unused']
110 * $server_variables['key_cache_block_size']
111 / $server_variables['key_buffer_size']
112 * 100;
113 } elseif (
114 isset($server_status['Key_blocks_used'])
115 && isset($server_variables['key_buffer_size'])) {
116 $server_status['Key_buffer_fraction_%'] =
117 $server_status['Key_blocks_used']
118 * 1024
119 / $server_variables['key_buffer_size'];
122 // Ratio for key read/write
123 if (isset($server_status['Key_writes'])
124 && isset($server_status['Key_write_requests'])
125 && $server_status['Key_write_requests'] > 0)
126 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
128 if (isset($server_status['Key_reads'])
129 && isset($server_status['Key_read_requests'])
130 && $server_status['Key_read_requests'] > 0)
131 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
133 // Threads_cache_hitrate
134 if (isset($server_status['Threads_created'])
135 && isset($server_status['Connections'])
136 && $server_status['Connections'] > 0) {
137 $server_status['Threads_cache_hitrate_%'] =
139 - $server_status['Threads_created']
140 / $server_status['Connections']
141 * 100;
146 * define some alerts
148 // name => max value before alert
149 $alerts = array(
150 // lower is better
151 // variable => max value
152 'Aborted_clients' => 0,
153 'Aborted_connects' => 0,
155 'Binlog_cache_disk_use' => 0,
157 'Created_tmp_disk_tables' => 0,
159 'Handler_read_rnd' => 0,
160 'Handler_read_rnd_next' => 0,
162 'Innodb_buffer_pool_pages_dirty' => 0,
163 'Innodb_buffer_pool_reads' => 0,
164 'Innodb_buffer_pool_wait_free' => 0,
165 'Innodb_log_waits' => 0,
166 'Innodb_row_lock_time_avg' => 10, // ms
167 'Innodb_row_lock_time_max' => 50, // ms
168 'Innodb_row_lock_waits' => 0,
170 'Slow_queries' => 0,
171 'Delayed_errors' => 0,
172 'Select_full_join' => 0,
173 'Select_range_check' => 0,
174 'Sort_merge_passes' => 0,
175 'Opened_tables' => 0,
176 'Table_locks_waited' => 0,
177 'Qcache_lowmem_prunes' => 0,
178 'Slow_launch_threads' => 0,
180 // depends on Key_read_requests
181 // normaly lower then 1:0.01
182 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
183 // depends on Key_write_requests
184 // normaly nearly 1:1
185 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
187 'Key_buffer_fraction' => 0.5,
189 // alert if more than 95% of thread cache is in use
190 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
192 // higher is better
193 // variable => min value
194 //'Handler read key' => '> ',
199 * split variables in sections
201 $allocations = array(
202 // variable name => section
204 'Com_' => 'com',
205 'Innodb_' => 'innodb',
206 'Ndb_' => 'ndb',
207 'Ssl_' => 'ssl',
208 'Handler_' => 'handler',
209 'Qcache_' => 'qcache',
210 'Threads_' => 'threads',
211 'Slow_launch_threads' => 'threads',
213 'Binlog_cache_' => 'binlog_cache',
214 'Created_tmp_' => 'created_tmp',
215 'Key_' => 'key',
217 'Delayed_' => 'delayed',
218 'Not_flushed_delayed_rows' => 'delayed',
220 'Flush_commands' => 'query',
221 'Last_query_cost' => 'query',
222 'Slow_queries' => 'query',
224 'Select_' => 'select',
225 'Sort_' => 'sort',
227 'Open_tables' => 'table',
228 'Opened_tables' => 'table',
229 'Table_locks_' => 'table',
231 'Rpl_status' => 'repl',
232 'Slave_' => 'repl',
234 'Tc_' => 'tc',
237 $sections = array(
238 // section => section name (description)
239 'com' => array('title' => ''),
240 'query' => array('title' => ''),
241 'innodb' => array('title' => 'InnoDB'),
242 'ndb' => array('title' => 'NDB'),
243 'ssl' => array('title' => 'SSL'),
244 'handler' => array('title' => $strHandler),
245 'qcache' => array('title' => $strQueryCache),
246 'threads' => array('title' => $strThreads),
247 'binlog_cache' => array('title' => $strBinaryLog),
248 'created_tmp' => array('title' => $strTempData),
249 'delayed' => array('title' => $strServerStatusDelayedInserts),
250 'key' => array('title' => $strKeyCache),
251 'select' => array('title' => $strJoins),
252 'repl' => array('title' => $strReplication),
253 'sort' => array('title' => $strSorting),
254 'table' => array('title' => $strNumTables),
255 'tc' => array('title' => $strTransactionCoordinator),
260 * define some needfull links/commands
262 // variable or section name => (name => url)
263 $links = array();
265 $links['table'][$strFlushTables]
266 = $PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
267 $links['table'][$strShowOpenTables]
268 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
269 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
271 $links['repl'][$strShowSlaveHosts]
272 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
273 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
274 $links['repl'][$strShowSlaveStatus]
275 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
276 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
277 $links['repl']['MySQL - ' . $strDocu]
278 = $cfg['MySQLManualBase'] . '/replication.html';
280 $links['qcache'][$strFlushQueryCache]
281 = $PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
282 PMA_generate_common_url();
283 $links['qcache']['MySQL - ' . $strDocu]
284 = $cfg['MySQLManualBase'] . '/query-cache.html';
286 $links['threads'][$strMySQLShowProcess]
287 = 'server_processlist.php?' . PMA_generate_common_url();
288 $links['threads']['MySQL - ' . $strDocu]
289 = $cfg['MySQLManualBase'] . '/mysql-threads.html';
291 $links['key']['MySQL - ' . $strDocu]
292 = $cfg['MySQLManualBase'] . '/myisam-key-cache.html';
294 $links['slow_queries']['MySQL - ' . $strDocu]
295 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
297 $links['binlog_cache']['MySQL - ' . $strDocu]
298 = $cfg['MySQLManualBase'] . '/binary-log.html';
300 $links['Slow_queries']['MySQL - ' . $strDocu]
301 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
303 $links['innodb'][$strServerTabVariables]
304 = 'server_engines.php?engine=innodb&amp;' . PMA_generate_common_url();
305 $links['innodb'][$strInnodbStat]
306 = 'server_engines.php?engine=innodb&amp;page=status&amp;' .
307 PMA_generate_common_url();
308 $links['innodb']['MySQL - ' . $strDocu]
309 = $cfg['MySQLManualBase'] . '/innodb.html';
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 $PHP_SELF . '?' . PMA_generate_common_url(); ?>"
341 ><?php echo $strRefresh; ?></a>
342 <a href="<?php echo
343 $PHP_SELF . '?flush=STATUS&amp;' . PMA_generate_common_url(); ?>"
344 ><?php echo $strShowStatusReset; ?></a>
345 <a href="<?php echo
346 $cfg['MySQLManualBase']; ?>/server-status-variables.html"
347 target="documentation">MySQL - <?php echo $strDocu; ?></a>
348 </div>
351 <?php
352 echo sprintf($strServerStatusUptime,
353 PMA_timespanFormat($server_status['Uptime']),
354 PMA_localisedDate($start_time)) . "\n";
356 </p>
358 <div id="sectionlinks">
359 <?php
360 foreach ($sections as $section_name => $section) {
361 if (! empty($section['vars']) && ! empty($section['title'])) {
362 echo '<a href="' . $PHP_SELF . '?' .
363 PMA_generate_common_url() . '#' . $section_name . '">' .
364 $section['title'] . '</a>' . "\n";
368 </div>
370 <h3><?php echo $strServerTrafficNotes; ?></h3>
372 <table id="serverstatustraffic" class="data">
373 <thead>
374 <tr>
375 <th colspan="2"><?php echo $strTraffic . '&nbsp;' . PMA_showHint($strStatisticsOverrun); ?></th>
376 <th>&oslash; <?php echo $strPerHour; ?></th>
377 </tr>
378 </thead>
379 <tbody>
380 <tr class="odd">
381 <th class="name"><?php echo $strReceived; ?></th>
382 <td class="value"><?php echo
383 implode(' ',
384 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?></td>
385 <td class="value"><?php echo
386 implode(' ',
387 PMA_formatByteDown(
388 $server_status['Bytes_received'] * $hour_factor, 4)); ?></td>
389 </tr>
390 <tr class="even">
391 <th class="name"><?php echo $strSent; ?></th>
392 <td class="value"><?php echo
393 implode(' ',
394 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?></td>
395 <td class="value"><?php echo
396 implode(' ',
397 PMA_formatByteDown(
398 $server_status['Bytes_sent'] * $hour_factor, 4)); ?></td>
399 </tr>
400 <tr class="odd">
401 <th class="name"><?php echo $strTotalUC; ?></th>
402 <td class="value"><?php echo
403 implode(' ',
404 PMA_formatByteDown(
405 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 4)
406 ); ?></td>
407 <td class="value"><?php echo
408 implode(' ',
409 PMA_formatByteDown(
410 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
411 * $hour_factor, 4)
412 ); ?></td>
413 </tr>
414 </tbody>
415 </table>
417 <table id="serverstatusconnections" class="data">
418 <thead>
419 <tr>
420 <th colspan="2"><?php echo $strConnections; ?></th>
421 <th>&oslash; <?php echo $strPerHour; ?></th>
422 <th>%</th>
423 </tr>
424 </thead>
425 <tbody>
426 <tr class="odd">
427 <th class="name"><?php echo $strMaxConnects; ?></th>
428 <td class="value"><?php echo
429 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
430 <td class="value">--- </td>
431 <td class="value">--- </td>
432 </tr>
433 <tr class="even">
434 <th class="name"><?php echo $strFailedAttempts; ?></th>
435 <td class="value"><?php echo
436 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?></td>
437 <td class="value"><?php echo
438 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
439 4, 2); ?></td>
440 <td class="value"><?php echo
441 $server_status['Connections'] > 0
442 ? PMA_formatNumber(
443 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
444 0, 2) . '%'
445 : '--- '; ?></td>
446 </tr>
447 <tr class="odd">
448 <th class="name"><?php echo $strAbortedClients; ?></th>
449 <td class="value"><?php echo
450 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?></td>
451 <td class="value"><?php echo
452 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
453 4, 2); ?></td>
454 <td class="value"><?php echo
455 $server_status['Connections'] > 0
456 ? PMA_formatNumber(
457 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
458 0, 2) . '%'
459 : '--- '; ?></td>
460 </tr>
461 <tr class="even">
462 <th class="name"><?php echo $strTotalUC; ?></th>
463 <td class="value"><?php echo
464 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
465 <td class="value"><?php echo
466 PMA_formatNumber($server_status['Connections'] * $hour_factor,
467 4, 2); ?></td>
468 <td class="value"><?php echo
469 PMA_formatNumber(100, 0, 2); ?>%</td>
470 </tr>
471 </tbody>
472 </table>
474 <hr class="clearfloat" />
476 <h3><?php echo
477 sprintf($strQueryStatistics,
478 PMA_formatNumber($server_status['Questions'], 0)); ?></h3>
480 <table id="serverstatusqueriessummary" class="data">
481 <thead>
482 <tr>
483 <th><?php echo $strTotalUC; ?></th>
484 <th>&oslash; <?php echo $strPerHour; ?></th>
485 <th>&oslash; <?php echo $strPerMinute; ?></th>
486 <th>&oslash; <?php echo $strPerSecond; ?></th>
487 </tr>
488 </thead>
489 <tbody>
490 <tr class="odd">
491 <td class="value"><?php echo
492 PMA_formatNumber($server_status['Questions'], 4, 0); ?></td>
493 <td class="value"><?php echo
494 PMA_formatNumber($server_status['Questions'] * $hour_factor,
495 3, 2); ?></td>
496 <td class="value"><?php echo
497 PMA_formatNumber(
498 $server_status['Questions'] * 60 / $server_status['Uptime'],
499 3, 2); ?></td>
500 <td class="value"><?php echo
501 PMA_formatNumber(
502 $server_status['Questions'] / $server_status['Uptime'],
503 3, 2); ?></td>
504 </tr>
505 </tbody>
506 </table>
508 <div id="serverstatusqueriesdetails">
509 <?php
510 // number of tables to split values into
511 $tables = 2;
512 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
513 $current_table = 0;
514 $odd_row = true;
515 $countRows = 0;
516 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
517 foreach ($sections['com']['vars'] as $name => $value) {
518 $current_table++;
519 if ($countRows === 0 || $countRows === $rows_per_table) {
520 $odd_row = true;
521 if ($countRows === $rows_per_table) {
522 echo ' </tbody>' . "\n";
523 echo ' </table>' . "\n";
526 <table id="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
527 <col class="namecol" />
528 <col class="valuecol" span="3" />
529 <thead>
530 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
531 <th>&oslash; <?php echo $strPerHour; ?></th>
532 <th>%</th>
533 </tr>
534 </thead>
535 <tbody>
536 <?php
537 } else {
538 $odd_row = !$odd_row;
540 $countRows++;
542 // For the percentage column, use Questions - Connections, because
543 // the number of connections is not an item of the Query types
544 // but is included in Questions. Then the total of the percentages is 100.
545 $name = str_replace('Com_', '', $name);
546 $name = str_replace('_', ' ', $name);
548 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
549 <th class="name"><?php echo htmlspecialchars($name); ?></th>
550 <td class="value"><?php echo PMA_formatNumber($value, 4, 0); ?></td>
551 <td class="value"><?php echo
552 PMA_formatNumber($value * $hour_factor, 4, 2); ?></td>
553 <td class="value"><?php echo
554 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
555 </tr>
556 <?php
559 </tbody>
560 </table>
561 </div>
563 <div id="serverstatussection">
564 <?php
565 //Unset used variables
566 unset(
567 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
568 $hour_factor, $sections['com'],
569 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
570 $server_status['Max_used_connections'], $server_status['Bytes_received'],
571 $server_status['Bytes_sent'], $server_status['Connections'],
572 $server_status['Questions'], $server_status['Uptime']
575 foreach ($sections as $section_name => $section) {
576 if (! empty($section['vars'])) {
578 <table class="data" id="serverstatussection<?php echo $section_name; ?>">
579 <caption class="tblHeaders">
580 <a class="top"
581 href="<?php echo $PHP_SELF . '?' .
582 PMA_generate_common_url() . '#serverstatus'; ?>"
583 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
584 <?php echo
585 ($GLOBALS['cfg']['MainPageIconic']
586 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
587 's_asc.png" width="11" height="9" align="middle" alt="" />'
588 : ''); ?>
589 </a>
590 <?php
591 if (! empty($section['title'])) {
592 echo $section['title'];
595 </caption>
596 <col class="namecol" />
597 <col class="valuecol" />
598 <col class="descrcol" />
599 <thead>
600 <tr>
601 <th><?php echo $strVar; ?></th>
602 <th><?php echo $strValue; ?></th>
603 <th><?php echo $strDescription; ?></th>
604 </tr>
605 </thead>
606 <?php
607 if (! empty($links[$section_name])) {
609 <tfoot>
610 <tr class="tblFooters">
611 <th colspan="3" class="tblFooters">
612 <?php
613 foreach ($links[$section_name] as $link_name => $link_url) {
614 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
616 unset($link_url, $link_name);
618 </th>
619 </tr>
620 </tfoot>
621 <?php
624 <tbody>
625 <?php
626 $odd_row = false;
627 foreach ($section['vars'] as $name => $value) {
628 $odd_row = !$odd_row;
630 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
631 <th class="name"><?php echo htmlspecialchars($name); ?></th>
632 <td class="value"><?php
633 if (isset($alerts[$name])) {
634 if ($value > $alerts[$name]) {
635 echo '<span class="attention">';
636 } else {
637 echo '<span class="allfine">';
640 if ('%' === substr($name, -1, 1)) {
641 echo PMA_formatNumber($value, 0, 2) . ' %';
642 } elseif (is_numeric($value) && $value == (int) $value) {
643 echo PMA_formatNumber($value, 4, 0);
644 } elseif (is_numeric($value)) {
645 echo PMA_formatNumber($value, 4, 2);
646 } else {
647 echo htmlspecialchars($value);
649 if (isset($alerts[$name])) {
650 echo '</span>';
652 ?></td>
653 <td class="descr">
654 <?php
655 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
656 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
659 if (isset($links[$name])) {
660 foreach ($links[$name] as $link_name => $link_url) {
661 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
662 "\n";
664 unset($link_url, $link_name);
667 </td>
668 </tr>
669 <?php
671 unset($name, $value);
673 </tbody>
674 </table>
675 <?php
678 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
680 </div>
681 </div>
682 <?php
686 * Sends the footer
688 require_once './libraries/footer.inc.php';