bug #1798646 [display] Character + in query wrongly interpreted
[phpmyadmin/crack.git] / server_status.php
blob75d9137f30334d6d77c54dbd3e2cee420b2a37db
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 */
10 /**
13 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
14 define('PMA_NO_VARIABLES_IMPORT', true);
16 require_once './libraries/common.inc.php';
18 /**
19 * Does the common work
21 require './libraries/server_common.inc.php';
24 /**
25 * Displays the links
27 require './libraries/server_links.inc.php';
30 /**
31 * Displays the sub-page heading
33 echo '<div id="serverstatus">' . "\n";
34 echo '<h2>' . "\n"
35 . ($GLOBALS['cfg']['MainPageIconic']
36 ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
37 's_status.png" width="16" height="16" alt="" />'
38 : '')
39 . $strServerStatus . "\n"
40 . '</h2>' . "\n";
43 /**
44 * flush status variables if requested
46 if (isset($_REQUEST['flush'])) {
47 $_flush_commands = array(
48 'STATUS',
49 'TABLES',
50 'QUERY CACHE',
53 if (in_array($_REQUEST['flush'], $_flush_commands)) {
54 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
56 unset($_flush_commands);
60 /**
61 * get status from server
63 if (PMA_MYSQL_INT_VERSION >= 50002) {
64 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
65 } else {
66 $server_status = PMA_DBI_fetch_result('SHOW STATUS', 0, 1);
70 /**
71 * for some calculations we require also some server settings
73 if (PMA_MYSQL_INT_VERSION >= 40003) {
74 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
75 } else {
76 $server_variables = PMA_DBI_fetch_result('SHOW VARIABLES', 0, 1);
80 /**
81 * starttime calculation
83 $start_time = PMA_DBI_fetch_value(
84 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
87 /**
88 * cleanup some deprecated values
90 $deprecated = array(
91 'Com_prepare_sql' => 'Com_stmt_prepare',
92 'Com_execute_sql' => 'Com_stmt_execute',
93 'Com_dealloc_sql' => 'Com_stmt_close',
96 foreach ($deprecated as $old => $new) {
97 if (isset($server_status[$old])
98 && isset($server_status[$new])) {
99 unset($server_status[$old]);
102 unset($deprecated);
106 * calculate some values
108 // Key_buffer_fraction
109 if (isset($server_status['Key_blocks_unused'])
110 && isset($server_variables['key_cache_block_size'])
111 && isset($server_variables['key_buffer_size'])) {
112 $server_status['Key_buffer_fraction_%'] =
114 - $server_status['Key_blocks_unused']
115 * $server_variables['key_cache_block_size']
116 / $server_variables['key_buffer_size']
117 * 100;
118 } elseif (
119 isset($server_status['Key_blocks_used'])
120 && isset($server_variables['key_buffer_size'])) {
121 $server_status['Key_buffer_fraction_%'] =
122 $server_status['Key_blocks_used']
123 * 1024
124 / $server_variables['key_buffer_size'];
127 // Ratio for key read/write
128 if (isset($server_status['Key_writes'])
129 && isset($server_status['Key_write_requests'])
130 && $server_status['Key_write_requests'] > 0)
131 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
133 if (isset($server_status['Key_reads'])
134 && isset($server_status['Key_read_requests'])
135 && $server_status['Key_read_requests'] > 0)
136 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
138 // Threads_cache_hitrate
139 if (isset($server_status['Threads_created'])
140 && isset($server_status['Connections'])
141 && $server_status['Connections'] > 0) {
142 $server_status['Threads_cache_hitrate_%'] =
144 - $server_status['Threads_created']
145 / $server_status['Connections']
146 * 100;
151 * define some alerts
153 // name => max value before alert
154 $alerts = array(
155 // lower is better
156 // variable => max value
157 'Aborted_clients' => 0,
158 'Aborted_connects' => 0,
160 'Binlog_cache_disk_use' => 0,
162 'Created_tmp_disk_tables' => 0,
164 'Handler_read_rnd' => 0,
165 'Handler_read_rnd_next' => 0,
167 'Innodb_buffer_pool_pages_dirty' => 0,
168 'Innodb_buffer_pool_reads' => 0,
169 'Innodb_buffer_pool_wait_free' => 0,
170 'Innodb_log_waits' => 0,
171 'Innodb_row_lock_time_avg' => 10, // ms
172 'Innodb_row_lock_time_max' => 50, // ms
173 'Innodb_row_lock_waits' => 0,
175 'Slow_queries' => 0,
176 'Delayed_errors' => 0,
177 'Select_full_join' => 0,
178 'Select_range_check' => 0,
179 'Sort_merge_passes' => 0,
180 'Opened_tables' => 0,
181 'Table_locks_waited' => 0,
182 'Qcache_lowmem_prunes' => 0,
183 'Slow_launch_threads' => 0,
185 // depends on Key_read_requests
186 // normaly lower then 1:0.01
187 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
188 // depends on Key_write_requests
189 // normaly nearly 1:1
190 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
192 'Key_buffer_fraction' => 0.5,
194 // alert if more than 95% of thread cache is in use
195 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
197 // higher is better
198 // variable => min value
199 //'Handler read key' => '> ',
204 * split variables in sections
206 $allocations = array(
207 // variable name => section
209 'Com_' => 'com',
210 'Innodb_' => 'innodb',
211 'Ndb_' => 'ndb',
212 'Ssl_' => 'ssl',
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',
242 $sections = array(
243 // section => section name (description)
244 'com' => array('title' => ''),
245 'query' => array('title' => ''),
246 'innodb' => array('title' => 'InnoDB'),
247 'ndb' => array('title' => 'NDB'),
248 'ssl' => array('title' => 'SSL'),
249 'handler' => array('title' => $strHandler),
250 'qcache' => array('title' => $strQueryCache),
251 'threads' => array('title' => $strThreads),
252 'binlog_cache' => array('title' => $strBinaryLog),
253 'created_tmp' => array('title' => $strTempData),
254 'delayed' => array('title' => $strServerStatusDelayedInserts),
255 'key' => array('title' => $strKeyCache),
256 'select' => array('title' => $strJoins),
257 'repl' => array('title' => $strReplication),
258 'sort' => array('title' => $strSorting),
259 'table' => array('title' => $strNumTables),
260 'tc' => array('title' => $strTransactionCoordinator),
265 * define some needfull links/commands
267 // variable or section name => (name => url)
268 $links = array();
270 // because of PMA_NO_VARIABLES_IMPORT, the $PHP_SELF globalized by
271 // grab_globals is not available here when register_globals = Off
272 // and in some situations, $_SERVER['PHP_SELF'] is not defined
273 $links['table'][$strFlushTables]
274 = PMA_getenv('PHP_SELF') . '?flush=TABLES&amp;' . PMA_generate_common_url();
275 $links['table'][$strShowOpenTables]
276 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
277 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
279 $links['repl'][$strShowSlaveHosts]
280 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
281 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
282 $links['repl'][$strShowSlaveStatus]
283 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
284 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
285 $links['repl']['MySQL - ' . $strDocu]
286 = $cfg['MySQLManualBase'] . '/replication.html';
288 $links['qcache'][$strFlushQueryCache]
289 = PMA_getenv('PHP_SELF') . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
290 PMA_generate_common_url();
291 $links['qcache']['MySQL - ' . $strDocu]
292 = $cfg['MySQLManualBase'] . '/query-cache.html';
294 $links['threads'][$strMySQLShowProcess]
295 = 'server_processlist.php?' . PMA_generate_common_url();
296 $links['threads']['MySQL - ' . $strDocu]
297 = $cfg['MySQLManualBase'] . '/mysql-threads.html';
299 $links['key']['MySQL - ' . $strDocu]
300 = $cfg['MySQLManualBase'] . '/myisam-key-cache.html';
302 $links['slow_queries']['MySQL - ' . $strDocu]
303 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
305 $links['binlog_cache']['MySQL - ' . $strDocu]
306 = $cfg['MySQLManualBase'] . '/binary-log.html';
308 $links['Slow_queries']['MySQL - ' . $strDocu]
309 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
311 $links['innodb'][$strServerTabVariables]
312 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
313 $links['innodb'][$strInnodbStat]
314 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
315 PMA_generate_common_url();
316 $links['innodb']['MySQL - ' . $strDocu]
317 = $cfg['MySQLManualBase'] . '/innodb.html';
320 // sort status vars into arrays
321 foreach ($server_status as $name => $value) {
322 if (isset($allocations[$name])) {
323 $sections[$allocations[$name]]['vars'][$name] = $value;
324 unset($server_status[$name]);
325 } else {
326 foreach ($allocations as $filter => $section) {
327 if (preg_match('/^' . $filter . '/', $name)
328 && isset($server_status[$name])) {
329 unset($server_status[$name]);
330 $sections[$section]['vars'][$name] = $value;
335 unset($name, $value, $filter, $section, $allocations);
337 // rest
338 $sections['all']['vars'] =& $server_status;
340 $hour_factor = 3600 / $server_status['Uptime'];
343 * start output
346 <div id="statuslinks">
347 <a href="<?php echo
348 PMA_getenv('PHP_SELF') . '?' . PMA_generate_common_url(); ?>"
349 ><?php echo $strRefresh; ?></a>
350 <a href="<?php echo
351 PMA_getenv('PHP_SELF') . '?flush=STATUS&amp;' . PMA_generate_common_url(); ?>"
352 ><?php echo $strShowStatusReset; ?></a>
353 <a href="<?php echo
354 $cfg['MySQLManualBase']; ?>/server-status-variables.html"
355 target="documentation">MySQL - <?php echo $strDocu; ?></a>
356 </div>
359 <?php
360 echo sprintf($strServerStatusUptime,
361 PMA_timespanFormat($server_status['Uptime']),
362 PMA_localisedDate($start_time)) . "\n";
364 </p>
366 <div id="sectionlinks">
367 <?php
368 foreach ($sections as $section_name => $section) {
369 if (! empty($section['vars']) && ! empty($section['title'])) {
370 echo '<a href="' . PMA_getenv('PHP_SELF') . '?' .
371 PMA_generate_common_url() . '#' . $section_name . '">' .
372 $section['title'] . '</a>' . "\n";
376 </div>
378 <h3><?php echo $strServerTrafficNotes; ?></h3>
380 <table id="serverstatustraffic" class="data">
381 <thead>
382 <tr>
383 <th colspan="2"><?php echo $strTraffic . '&nbsp;' . PMA_showHint($strStatisticsOverrun); ?></th>
384 <th>&oslash; <?php echo $strPerHour; ?></th>
385 </tr>
386 </thead>
387 <tbody>
388 <tr class="odd">
389 <th class="name"><?php echo $strReceived; ?></th>
390 <td class="value"><?php echo
391 implode(' ',
392 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?></td>
393 <td class="value"><?php echo
394 implode(' ',
395 PMA_formatByteDown(
396 $server_status['Bytes_received'] * $hour_factor, 4)); ?></td>
397 </tr>
398 <tr class="even">
399 <th class="name"><?php echo $strSent; ?></th>
400 <td class="value"><?php echo
401 implode(' ',
402 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?></td>
403 <td class="value"><?php echo
404 implode(' ',
405 PMA_formatByteDown(
406 $server_status['Bytes_sent'] * $hour_factor, 4)); ?></td>
407 </tr>
408 <tr class="odd">
409 <th class="name"><?php echo $strTotalUC; ?></th>
410 <td class="value"><?php echo
411 implode(' ',
412 PMA_formatByteDown(
413 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 4)
414 ); ?></td>
415 <td class="value"><?php echo
416 implode(' ',
417 PMA_formatByteDown(
418 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
419 * $hour_factor, 4)
420 ); ?></td>
421 </tr>
422 </tbody>
423 </table>
425 <table id="serverstatusconnections" class="data">
426 <thead>
427 <tr>
428 <th colspan="2"><?php echo $strConnections; ?></th>
429 <th>&oslash; <?php echo $strPerHour; ?></th>
430 <th>%</th>
431 </tr>
432 </thead>
433 <tbody>
434 <tr class="odd">
435 <th class="name"><?php echo $strMaxConnects; ?></th>
436 <td class="value"><?php echo
437 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
438 <td class="value">--- </td>
439 <td class="value">--- </td>
440 </tr>
441 <tr class="even">
442 <th class="name"><?php echo $strFailedAttempts; ?></th>
443 <td class="value"><?php echo
444 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?></td>
445 <td class="value"><?php echo
446 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
447 4, 2); ?></td>
448 <td class="value"><?php echo
449 $server_status['Connections'] > 0
450 ? PMA_formatNumber(
451 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
452 0, 2) . '%'
453 : '--- '; ?></td>
454 </tr>
455 <tr class="odd">
456 <th class="name"><?php echo $strAbortedClients; ?></th>
457 <td class="value"><?php echo
458 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?></td>
459 <td class="value"><?php echo
460 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
461 4, 2); ?></td>
462 <td class="value"><?php echo
463 $server_status['Connections'] > 0
464 ? PMA_formatNumber(
465 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
466 0, 2) . '%'
467 : '--- '; ?></td>
468 </tr>
469 <tr class="even">
470 <th class="name"><?php echo $strTotalUC; ?></th>
471 <td class="value"><?php echo
472 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
473 <td class="value"><?php echo
474 PMA_formatNumber($server_status['Connections'] * $hour_factor,
475 4, 2); ?></td>
476 <td class="value"><?php echo
477 PMA_formatNumber(100, 0, 2); ?>%</td>
478 </tr>
479 </tbody>
480 </table>
482 <hr class="clearfloat" />
484 <h3><?php echo
485 sprintf($strQueryStatistics,
486 PMA_formatNumber($server_status['Questions'], 0)); ?></h3>
488 <table id="serverstatusqueriessummary" class="data">
489 <thead>
490 <tr>
491 <th><?php echo $strTotalUC; ?></th>
492 <th>&oslash; <?php echo $strPerHour; ?></th>
493 <th>&oslash; <?php echo $strPerMinute; ?></th>
494 <th>&oslash; <?php echo $strPerSecond; ?></th>
495 </tr>
496 </thead>
497 <tbody>
498 <tr class="odd">
499 <td class="value"><?php echo
500 PMA_formatNumber($server_status['Questions'], 4, 0); ?></td>
501 <td class="value"><?php echo
502 PMA_formatNumber($server_status['Questions'] * $hour_factor,
503 3, 2); ?></td>
504 <td class="value"><?php echo
505 PMA_formatNumber(
506 $server_status['Questions'] * 60 / $server_status['Uptime'],
507 3, 2); ?></td>
508 <td class="value"><?php echo
509 PMA_formatNumber(
510 $server_status['Questions'] / $server_status['Uptime'],
511 3, 2); ?></td>
512 </tr>
513 </tbody>
514 </table>
516 <div id="serverstatusqueriesdetails">
517 <?php
518 // number of tables to split values into
519 $tables = 2;
520 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
521 $current_table = 0;
522 $odd_row = true;
523 $countRows = 0;
524 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
525 foreach ($sections['com']['vars'] as $name => $value) {
526 $current_table++;
527 if ($countRows === 0 || $countRows === $rows_per_table) {
528 $odd_row = true;
529 if ($countRows === $rows_per_table) {
530 echo ' </tbody>' . "\n";
531 echo ' </table>' . "\n";
534 <table id="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
535 <col class="namecol" />
536 <col class="valuecol" span="3" />
537 <thead>
538 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
539 <th>&oslash; <?php echo $strPerHour; ?></th>
540 <th>%</th>
541 </tr>
542 </thead>
543 <tbody>
544 <?php
545 } else {
546 $odd_row = !$odd_row;
548 $countRows++;
550 // For the percentage column, use Questions - Connections, because
551 // the number of connections is not an item of the Query types
552 // but is included in Questions. Then the total of the percentages is 100.
553 $name = str_replace('Com_', '', $name);
554 $name = str_replace('_', ' ', $name);
556 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
557 <th class="name"><?php echo htmlspecialchars($name); ?></th>
558 <td class="value"><?php echo PMA_formatNumber($value, 4, 0); ?></td>
559 <td class="value"><?php echo
560 PMA_formatNumber($value * $hour_factor, 4, 2); ?></td>
561 <td class="value"><?php echo
562 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
563 </tr>
564 <?php
567 </tbody>
568 </table>
569 </div>
571 <div id="serverstatussection">
572 <?php
573 //Unset used variables
574 unset(
575 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
576 $hour_factor, $sections['com'],
577 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
578 $server_status['Max_used_connections'], $server_status['Bytes_received'],
579 $server_status['Bytes_sent'], $server_status['Connections'],
580 $server_status['Questions'], $server_status['Uptime']
583 foreach ($sections as $section_name => $section) {
584 if (! empty($section['vars'])) {
586 <table class="data" id="serverstatussection<?php echo $section_name; ?>">
587 <caption class="tblHeaders">
588 <a class="top"
589 href="<?php echo PMA_getenv('PHP_SELF') . '?' .
590 PMA_generate_common_url() . '#serverstatus'; ?>"
591 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
592 <?php echo
593 ($GLOBALS['cfg']['MainPageIconic']
594 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
595 's_asc.png" width="11" height="9" align="middle" alt="" />'
596 : ''); ?>
597 </a>
598 <?php
599 if (! empty($section['title'])) {
600 echo $section['title'];
603 </caption>
604 <col class="namecol" />
605 <col class="valuecol" />
606 <col class="descrcol" />
607 <thead>
608 <tr>
609 <th><?php echo $strVar; ?></th>
610 <th><?php echo $strValue; ?></th>
611 <th><?php echo $strDescription; ?></th>
612 </tr>
613 </thead>
614 <?php
615 if (! empty($links[$section_name])) {
617 <tfoot>
618 <tr class="tblFooters">
619 <th colspan="3" class="tblFooters">
620 <?php
621 foreach ($links[$section_name] as $link_name => $link_url) {
622 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
624 unset($link_url, $link_name);
626 </th>
627 </tr>
628 </tfoot>
629 <?php
632 <tbody>
633 <?php
634 $odd_row = false;
635 foreach ($section['vars'] as $name => $value) {
636 $odd_row = !$odd_row;
638 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
639 <th class="name"><?php echo htmlspecialchars($name); ?></th>
640 <td class="value"><?php
641 if (isset($alerts[$name])) {
642 if ($value > $alerts[$name]) {
643 echo '<span class="attention">';
644 } else {
645 echo '<span class="allfine">';
648 if ('%' === substr($name, -1, 1)) {
649 echo PMA_formatNumber($value, 0, 2) . ' %';
650 } elseif (is_numeric($value) && $value == (int) $value) {
651 echo PMA_formatNumber($value, 4, 0);
652 } elseif (is_numeric($value)) {
653 echo PMA_formatNumber($value, 4, 2);
654 } else {
655 echo htmlspecialchars($value);
657 if (isset($alerts[$name])) {
658 echo '</span>';
660 ?></td>
661 <td class="descr">
662 <?php
663 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
664 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
667 if (isset($links[$name])) {
668 foreach ($links[$name] as $link_name => $link_url) {
669 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
670 "\n";
672 unset($link_url, $link_name);
675 </td>
676 </tr>
677 <?php
679 unset($name, $value);
681 </tbody>
682 </table>
683 <?php
686 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
688 </div>
689 </div>
690 <?php
694 * Sends the footer
696 require_once './libraries/footer.inc.php';