2.11.1.2 release
[phpmyadmin/arisferyanto.git] / server_status.php
blobb5de5cdf189982b85484758750f74106240acd8c
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 $links['table'][$strFlushTables]
271 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
272 $links['table'][$strShowOpenTables]
273 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
274 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
276 $links['repl'][$strShowSlaveHosts]
277 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
278 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
279 $links['repl'][$strShowSlaveStatus]
280 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
281 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
282 $links['repl']['MySQL - ' . $strDocu]
283 = $cfg['MySQLManualBase'] . '/replication.html';
285 $links['qcache'][$strFlushQueryCache]
286 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
287 PMA_generate_common_url();
288 $links['qcache']['MySQL - ' . $strDocu]
289 = $cfg['MySQLManualBase'] . '/query-cache.html';
291 $links['threads'][$strMySQLShowProcess]
292 = 'server_processlist.php?' . PMA_generate_common_url();
293 $links['threads']['MySQL - ' . $strDocu]
294 = $cfg['MySQLManualBase'] . '/mysql-threads.html';
296 $links['key']['MySQL - ' . $strDocu]
297 = $cfg['MySQLManualBase'] . '/myisam-key-cache.html';
299 $links['slow_queries']['MySQL - ' . $strDocu]
300 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
302 $links['binlog_cache']['MySQL - ' . $strDocu]
303 = $cfg['MySQLManualBase'] . '/binary-log.html';
305 $links['Slow_queries']['MySQL - ' . $strDocu]
306 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
308 $links['innodb'][$strServerTabVariables]
309 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
310 $links['innodb'][$strInnodbStat]
311 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
312 PMA_generate_common_url();
313 $links['innodb']['MySQL - ' . $strDocu]
314 = $cfg['MySQLManualBase'] . '/innodb.html';
317 // sort status vars into arrays
318 foreach ($server_status as $name => $value) {
319 if (isset($allocations[$name])) {
320 $sections[$allocations[$name]]['vars'][$name] = $value;
321 unset($server_status[$name]);
322 } else {
323 foreach ($allocations as $filter => $section) {
324 if (preg_match('/^' . $filter . '/', $name)
325 && isset($server_status[$name])) {
326 unset($server_status[$name]);
327 $sections[$section]['vars'][$name] = $value;
332 unset($name, $value, $filter, $section, $allocations);
334 // rest
335 $sections['all']['vars'] =& $server_status;
337 $hour_factor = 3600 / $server_status['Uptime'];
340 * start output
343 <div id="statuslinks">
344 <a href="<?php echo
345 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
346 ><?php echo $strRefresh; ?></a>
347 <a href="<?php echo
348 $PMA_PHP_SELF . '?flush=STATUS&amp;' . PMA_generate_common_url(); ?>"
349 ><?php echo $strShowStatusReset; ?></a>
350 <a href="<?php echo
351 $cfg['MySQLManualBase']; ?>/server-status-variables.html"
352 target="documentation">MySQL - <?php echo $strDocu; ?></a>
353 </div>
356 <?php
357 echo sprintf($strServerStatusUptime,
358 PMA_timespanFormat($server_status['Uptime']),
359 PMA_localisedDate($start_time)) . "\n";
361 </p>
363 <div id="sectionlinks">
364 <?php
365 foreach ($sections as $section_name => $section) {
366 if (! empty($section['vars']) && ! empty($section['title'])) {
367 echo '<a href="' . $PMA_PHP_SELF . '?' .
368 PMA_generate_common_url() . '#' . $section_name . '">' .
369 $section['title'] . '</a>' . "\n";
373 </div>
375 <h3><?php echo $strServerTrafficNotes; ?></h3>
377 <table id="serverstatustraffic" class="data">
378 <thead>
379 <tr>
380 <th colspan="2"><?php echo $strTraffic . '&nbsp;' . PMA_showHint($strStatisticsOverrun); ?></th>
381 <th>&oslash; <?php echo $strPerHour; ?></th>
382 </tr>
383 </thead>
384 <tbody>
385 <tr class="odd">
386 <th class="name"><?php echo $strReceived; ?></th>
387 <td class="value"><?php echo
388 implode(' ',
389 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?></td>
390 <td class="value"><?php echo
391 implode(' ',
392 PMA_formatByteDown(
393 $server_status['Bytes_received'] * $hour_factor, 4)); ?></td>
394 </tr>
395 <tr class="even">
396 <th class="name"><?php echo $strSent; ?></th>
397 <td class="value"><?php echo
398 implode(' ',
399 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?></td>
400 <td class="value"><?php echo
401 implode(' ',
402 PMA_formatByteDown(
403 $server_status['Bytes_sent'] * $hour_factor, 4)); ?></td>
404 </tr>
405 <tr class="odd">
406 <th class="name"><?php echo $strTotalUC; ?></th>
407 <td class="value"><?php echo
408 implode(' ',
409 PMA_formatByteDown(
410 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 4)
411 ); ?></td>
412 <td class="value"><?php echo
413 implode(' ',
414 PMA_formatByteDown(
415 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
416 * $hour_factor, 4)
417 ); ?></td>
418 </tr>
419 </tbody>
420 </table>
422 <table id="serverstatusconnections" class="data">
423 <thead>
424 <tr>
425 <th colspan="2"><?php echo $strConnections; ?></th>
426 <th>&oslash; <?php echo $strPerHour; ?></th>
427 <th>%</th>
428 </tr>
429 </thead>
430 <tbody>
431 <tr class="odd">
432 <th class="name"><?php echo $strMaxConnects; ?></th>
433 <td class="value"><?php echo
434 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
435 <td class="value">--- </td>
436 <td class="value">--- </td>
437 </tr>
438 <tr class="even">
439 <th class="name"><?php echo $strFailedAttempts; ?></th>
440 <td class="value"><?php echo
441 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?></td>
442 <td class="value"><?php echo
443 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
444 4, 2); ?></td>
445 <td class="value"><?php echo
446 $server_status['Connections'] > 0
447 ? PMA_formatNumber(
448 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
449 0, 2) . '%'
450 : '--- '; ?></td>
451 </tr>
452 <tr class="odd">
453 <th class="name"><?php echo $strAbortedClients; ?></th>
454 <td class="value"><?php echo
455 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?></td>
456 <td class="value"><?php echo
457 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
458 4, 2); ?></td>
459 <td class="value"><?php echo
460 $server_status['Connections'] > 0
461 ? PMA_formatNumber(
462 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
463 0, 2) . '%'
464 : '--- '; ?></td>
465 </tr>
466 <tr class="even">
467 <th class="name"><?php echo $strTotalUC; ?></th>
468 <td class="value"><?php echo
469 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
470 <td class="value"><?php echo
471 PMA_formatNumber($server_status['Connections'] * $hour_factor,
472 4, 2); ?></td>
473 <td class="value"><?php echo
474 PMA_formatNumber(100, 0, 2); ?>%</td>
475 </tr>
476 </tbody>
477 </table>
479 <hr class="clearfloat" />
481 <h3><?php echo
482 sprintf($strQueryStatistics,
483 PMA_formatNumber($server_status['Questions'], 0)); ?></h3>
485 <table id="serverstatusqueriessummary" class="data">
486 <thead>
487 <tr>
488 <th><?php echo $strTotalUC; ?></th>
489 <th>&oslash; <?php echo $strPerHour; ?></th>
490 <th>&oslash; <?php echo $strPerMinute; ?></th>
491 <th>&oslash; <?php echo $strPerSecond; ?></th>
492 </tr>
493 </thead>
494 <tbody>
495 <tr class="odd">
496 <td class="value"><?php echo
497 PMA_formatNumber($server_status['Questions'], 4, 0); ?></td>
498 <td class="value"><?php echo
499 PMA_formatNumber($server_status['Questions'] * $hour_factor,
500 3, 2); ?></td>
501 <td class="value"><?php echo
502 PMA_formatNumber(
503 $server_status['Questions'] * 60 / $server_status['Uptime'],
504 3, 2); ?></td>
505 <td class="value"><?php echo
506 PMA_formatNumber(
507 $server_status['Questions'] / $server_status['Uptime'],
508 3, 2); ?></td>
509 </tr>
510 </tbody>
511 </table>
513 <div id="serverstatusqueriesdetails">
514 <?php
515 // number of tables to split values into
516 $tables = 2;
517 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
518 $current_table = 0;
519 $odd_row = true;
520 $countRows = 0;
521 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
522 foreach ($sections['com']['vars'] as $name => $value) {
523 $current_table++;
524 if ($countRows === 0 || $countRows === $rows_per_table) {
525 $odd_row = true;
526 if ($countRows === $rows_per_table) {
527 echo ' </tbody>' . "\n";
528 echo ' </table>' . "\n";
531 <table id="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
532 <col class="namecol" />
533 <col class="valuecol" span="3" />
534 <thead>
535 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
536 <th>&oslash; <?php echo $strPerHour; ?></th>
537 <th>%</th>
538 </tr>
539 </thead>
540 <tbody>
541 <?php
542 } else {
543 $odd_row = !$odd_row;
545 $countRows++;
547 // For the percentage column, use Questions - Connections, because
548 // the number of connections is not an item of the Query types
549 // but is included in Questions. Then the total of the percentages is 100.
550 $name = str_replace('Com_', '', $name);
551 $name = str_replace('_', ' ', $name);
553 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
554 <th class="name"><?php echo htmlspecialchars($name); ?></th>
555 <td class="value"><?php echo PMA_formatNumber($value, 4, 0); ?></td>
556 <td class="value"><?php echo
557 PMA_formatNumber($value * $hour_factor, 4, 2); ?></td>
558 <td class="value"><?php echo
559 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
560 </tr>
561 <?php
564 </tbody>
565 </table>
566 </div>
568 <div id="serverstatussection">
569 <?php
570 //Unset used variables
571 unset(
572 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
573 $hour_factor, $sections['com'],
574 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
575 $server_status['Max_used_connections'], $server_status['Bytes_received'],
576 $server_status['Bytes_sent'], $server_status['Connections'],
577 $server_status['Questions'], $server_status['Uptime']
580 foreach ($sections as $section_name => $section) {
581 if (! empty($section['vars'])) {
583 <table class="data" id="serverstatussection<?php echo $section_name; ?>">
584 <caption class="tblHeaders">
585 <a class="top"
586 href="<?php echo $PMA_PHP_SELF . '?' .
587 PMA_generate_common_url() . '#serverstatus'; ?>"
588 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
589 <?php echo
590 ($GLOBALS['cfg']['MainPageIconic']
591 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
592 's_asc.png" width="11" height="9" align="middle" alt="" />'
593 : ''); ?>
594 </a>
595 <?php
596 if (! empty($section['title'])) {
597 echo $section['title'];
600 </caption>
601 <col class="namecol" />
602 <col class="valuecol" />
603 <col class="descrcol" />
604 <thead>
605 <tr>
606 <th><?php echo $strVar; ?></th>
607 <th><?php echo $strValue; ?></th>
608 <th><?php echo $strDescription; ?></th>
609 </tr>
610 </thead>
611 <?php
612 if (! empty($links[$section_name])) {
614 <tfoot>
615 <tr class="tblFooters">
616 <th colspan="3" class="tblFooters">
617 <?php
618 foreach ($links[$section_name] as $link_name => $link_url) {
619 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
621 unset($link_url, $link_name);
623 </th>
624 </tr>
625 </tfoot>
626 <?php
629 <tbody>
630 <?php
631 $odd_row = false;
632 foreach ($section['vars'] as $name => $value) {
633 $odd_row = !$odd_row;
635 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
636 <th class="name"><?php echo htmlspecialchars($name); ?></th>
637 <td class="value"><?php
638 if (isset($alerts[$name])) {
639 if ($value > $alerts[$name]) {
640 echo '<span class="attention">';
641 } else {
642 echo '<span class="allfine">';
645 if ('%' === substr($name, -1, 1)) {
646 echo PMA_formatNumber($value, 0, 2) . ' %';
647 } elseif (is_numeric($value) && $value == (int) $value) {
648 echo PMA_formatNumber($value, 4, 0);
649 } elseif (is_numeric($value)) {
650 echo PMA_formatNumber($value, 4, 2);
651 } else {
652 echo htmlspecialchars($value);
654 if (isset($alerts[$name])) {
655 echo '</span>';
657 ?></td>
658 <td class="descr">
659 <?php
660 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
661 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
664 if (isset($links[$name])) {
665 foreach ($links[$name] as $link_name => $link_url) {
666 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
667 "\n";
669 unset($link_url, $link_name);
672 </td>
673 </tr>
674 <?php
676 unset($name, $value);
678 </tbody>
679 </table>
680 <?php
683 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
685 </div>
686 </div>
687 <?php
691 * Sends the footer
693 require_once './libraries/footer.inc.php';