should not use mysql_connect() directly
[phpmyadmin/crack.git] / server_status.php
blob46858621acf571e566ff03ddfd80239eac2375b2
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
520 // number of tables to split values into
521 $tables = 2;
522 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
523 $current_table = 0;
524 $odd_row = true;
525 $countRows = 0;
526 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
527 foreach ($sections['com']['vars'] as $name => $value) {
528 $current_table++;
529 if ($countRows === 0 || $countRows === $rows_per_table) {
530 $odd_row = true;
531 if ($countRows === $rows_per_table) {
532 echo ' </tbody>' . "\n";
533 echo ' </table>' . "\n";
536 <table id="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
537 <col class="namecol" />
538 <col class="valuecol" span="3" />
539 <thead>
540 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
541 <th>&oslash; <?php echo $strPerHour; ?></th>
542 <th>%</th>
543 </tr>
544 </thead>
545 <tbody>
546 <?php
547 } else {
548 $odd_row = !$odd_row;
550 $countRows++;
552 // For the percentage column, use Questions - Connections, because
553 // the number of connections is not an item of the Query types
554 // but is included in Questions. Then the total of the percentages is 100.
555 $name = str_replace('Com_', '', $name);
556 $name = str_replace('_', ' ', $name);
558 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
559 <th class="name"><?php echo htmlspecialchars($name); ?></th>
560 <td class="value"><?php echo PMA_formatNumber($value, 4, 0); ?></td>
561 <td class="value"><?php echo
562 PMA_formatNumber($value * $hour_factor, 4, 2); ?></td>
563 <td class="value"><?php echo
564 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
565 </tr>
566 <?php
569 </tbody>
570 </table>
571 </div>
573 <div id="serverstatussection">
574 <?php
575 //Unset used variables
576 unset(
577 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
578 $hour_factor, $sections['com'],
579 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
580 $server_status['Max_used_connections'], $server_status['Bytes_received'],
581 $server_status['Bytes_sent'], $server_status['Connections'],
582 $server_status['Questions'], $server_status['Uptime']
585 foreach ($sections as $section_name => $section) {
586 if (! empty($section['vars'])) {
588 <table class="data" id="serverstatussection<?php echo $section_name; ?>">
589 <caption class="tblHeaders">
590 <a class="top"
591 href="<?php echo $PMA_PHP_SELF . '?' .
592 PMA_generate_common_url() . '#serverstatus'; ?>"
593 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
594 <?php echo
595 ($GLOBALS['cfg']['MainPageIconic']
596 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
597 's_asc.png" width="11" height="9" align="middle" alt="" />'
598 : ''); ?>
599 </a>
600 <?php
601 if (! empty($section['title'])) {
602 echo $section['title'];
605 </caption>
606 <col class="namecol" />
607 <col class="valuecol" />
608 <col class="descrcol" />
609 <thead>
610 <tr>
611 <th><?php echo $strVar; ?></th>
612 <th><?php echo $strValue; ?></th>
613 <th><?php echo $strDescription; ?></th>
614 </tr>
615 </thead>
616 <?php
617 if (! empty($links[$section_name])) {
619 <tfoot>
620 <tr class="tblFooters">
621 <th colspan="3" class="tblFooters">
622 <?php
623 foreach ($links[$section_name] as $link_name => $link_url) {
624 if ('doc' == $link_name) {
625 echo PMA_showMySQLDocu($link_url, $link_url);
626 } else {
627 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
630 unset($link_url, $link_name);
632 </th>
633 </tr>
634 </tfoot>
635 <?php
638 <tbody>
639 <?php
640 $odd_row = false;
641 foreach ($section['vars'] as $name => $value) {
642 $odd_row = !$odd_row;
644 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
645 <th class="name"><?php echo htmlspecialchars($name); ?></th>
646 <td class="value"><?php
647 if (isset($alerts[$name])) {
648 if ($value > $alerts[$name]) {
649 echo '<span class="attention">';
650 } else {
651 echo '<span class="allfine">';
654 if ('%' === substr($name, -1, 1)) {
655 echo PMA_formatNumber($value, 0, 2) . ' %';
656 } elseif (is_numeric($value) && $value == (int) $value) {
657 echo PMA_formatNumber($value, 4, 0);
658 } elseif (is_numeric($value)) {
659 echo PMA_formatNumber($value, 4, 2);
660 } else {
661 echo htmlspecialchars($value);
663 if (isset($alerts[$name])) {
664 echo '</span>';
666 ?></td>
667 <td class="descr">
668 <?php
669 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
670 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
673 if (isset($links[$name])) {
674 foreach ($links[$name] as $link_name => $link_url) {
675 if ('doc' == $link_name) {
676 echo PMA_showMySQLDocu($link_url, $link_url);
677 } else {
678 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
679 "\n";
682 unset($link_url, $link_name);
685 </td>
686 </tr>
687 <?php
689 unset($name, $value);
691 </tbody>
692 </table>
693 <?php
696 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
698 </div>
699 <?php
700 /* if the server works as master or slave in replication process, display useful information */
701 if ($server_master_status || $server_slave_status)
704 <hr class="clearfloat" />
706 <h3><a name="replication"></a><?php echo $strReplicationStatus; ?></h3>
707 <?php
709 foreach ($replication_types as $type)
711 if (${"server_{$type}_status"}) {
712 PMA_replication_print_status_table($type);
715 unset($types);
719 </div>
721 <?php
723 * Sends the footer
725 require_once './libraries/footer.inc.php';