sorry, wrong version checked in
[phpmyadmin/arisferyanto.git] / server_status.php
blobdc1a7f933f21cdcf7da8e28069f3726444f705b9
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 vriales
7 */
9 require_once('./libraries/common.lib.php');
11 /**
12 * Does the common work
14 require './server_common.inc.php';
17 /**
18 * Displays the links
20 require './server_links.inc.php';
23 /**
24 * Displays the sub-page heading
26 echo '<a name="_top"></a>' . "\n";
27 echo '<div id="serverstatus">' . "\n";
28 echo '<h2>' . "\n"
29 . ($GLOBALS['cfg']['MainPageIconic']
30 ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
31 's_status.png" width="16" height="16" alt="" />'
32 : '' )
33 . $strServerStatus . "\n"
34 . '</h2>' . "\n";
37 /**
38 * flush status variables if requested
40 if ( isset( $_REQUEST['flush'] ) ) {
41 $_flush_commands = array(
42 'STATUS',
43 'TABLES',
44 'QUERY CACHE',
47 if ( in_array( $_REQUEST['flush'], $_flush_commands ) ) {
48 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
50 unset( $_flush_commands );
54 /**
55 * get status from server
57 if ( PMA_MYSQL_INT_VERSION >= 50002 ) {
58 $server_status = PMA_DBI_fetch_result( 'SHOW GLOBAL STATUS', 0, 1 );
59 } else {
60 $server_status = PMA_DBI_fetch_result( 'SHOW STATUS', 0, 1 );
64 /**
65 * for some calculations we require also some server settings
67 if ( PMA_MYSQL_INT_VERSION >= 40003 ) {
68 $server_variables = PMA_DBI_fetch_result( 'SHOW GLOBAL VARIABLES', 0, 1 );
69 } else {
70 $server_variables = PMA_DBI_fetch_result( 'SHOW VARIABLES', 0, 1 );
74 /**
75 * starttime calculation
77 $start_time = PMA_DBI_fetch_value(
78 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime'] );
81 /**
82 * cleanup some deprecated values
84 $deprecated = array(
85 'Com_prepare_sql' => 'Com_stmt_prepare',
86 'Com_execute_sql' => 'Com_stmt_execute',
87 'Com_dealloc_sql' => 'Com_stmt_close',
90 foreach ( $deprecated as $old => $new ) {
91 if ( isset( $server_status[$old] )
92 && isset( $server_status[$new] ) ) {
93 unset( $server_status[$old] );
96 unset( $deprecated );
99 /**
100 * calculate some values
102 // Key_buffer_fraction
103 if ( isset( $server_status['Key_blocks_unused'] )
104 && isset( $server_variables['key_cache_block_size'] )
105 && isset( $server_variables['key_buffer_size'] ) ) {
106 $server_status['Key_buffer_fraction_%'] =
108 - $server_status['Key_blocks_unused']
109 * $server_variables['key_cache_block_size']
110 / $server_variables['key_buffer_size']
111 * 100;
112 } elseif (
113 isset( $server_status['Key_blocks_used'] )
114 && isset( $server_variables['key_buffer_size'] ) ) {
115 $server_status['Key_buffer_fraction_%'] =
116 $server_status['Key_blocks_used']
117 * 1024
118 / $server_variables['key_buffer_size'];
120 // Threads_cache_hitrate
121 if ( isset( $server_status['Threads_created'] )
122 && isset( $server_status['Connections'] ) ) {
123 $server_status['Threads_cache_hitrate_%'] =
125 - $server_status['Threads_created']
126 / $server_status['Connections']
127 * 100;
132 * define some alerts
134 // name => max value before alert
135 $alerts = array(
136 // lower is better
137 // variable => max value
138 'Aborted_clients' => 0,
139 'Aborted_connects' => 0,
141 'Binlog_cache_disk_use' => 0,
143 'Created_tmp_disk_tables' => 0,
145 'Handler_read_rnd' => 0,
146 'Handler_read_rnd_next' => 0,
148 'Innodb_buffer_pool_pages_dirty' => 0,
149 'Innodb_buffer_pool_reads' => 0,
150 'Innodb_buffer_pool_wait_free' => 0,
151 'Innodb_log_waits' => 0,
152 'Innodb_row_lock_time_avg' => 10, // ms
153 'Innodb_row_lock_time_max' => 50, // ms
154 'Innodb_row_lock_waits' => 0,
156 'Slow_queries' => 0,
157 'Delayed_errors' => 0,
158 'Select_full_join' => 0,
159 'Select_range_check' => 0,
160 'Sort_merge_passes' => 0,
161 'Opened_tables' => 0,
162 'Table_locks_waited' => 0,
163 'Qcache_lowmem_prunes' => 0,
164 'Slow_launch_threads' => 0,
166 // depends on Key_read_requests
167 // normaly lower then 1:0.01
168 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
169 // depends on Key_write_requests
170 // normaly nearly 1:1
171 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
173 'Key_buffer_fraction' => 0.5,
175 // alert if more than 95% of thread cache is in use
176 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
178 // higher is better
179 // variable => min value
180 //'Handler read key' => '> ',
185 * split variables in sections
187 $allocations = array(
188 // variable name => section
190 'Com_' => 'com',
191 'Innodb_' => 'innodb',
192 'Ndb_' => 'ndb',
193 'Ssl_' => 'ssl',
194 'Handler_' => 'handler',
195 'Qcache_' => 'qcache',
196 'Threads_' => 'threads',
197 'Slow_launch_threads' => 'threads',
199 'Binlog_cache_' => 'binlog_cache',
200 'Created_tmp_' => 'created_tmp',
201 'Key_' => 'key',
203 'Delayed_' => 'delayed',
204 'Not_flushed_delayed_rows' => 'delayed',
206 'Flush_commands' => 'query',
207 'Last_query_cost' => 'query',
208 'Slow_queries' => 'query',
210 'Select_' => 'select',
211 'Sort_' => 'sort',
213 'Open_tables' => 'table',
214 'Opened_tables' => 'table',
215 'Table_locks_' => 'table',
217 'Rpl_status' => 'repl',
218 'Slave_' => 'repl',
220 'Tc_' => 'tc',
223 $sections = array(
224 // section => section name (description)
225 'com' => array( 'title' => '' ),
226 'query' => array( 'title' => '' ),
227 'innodb' => array( 'title' => 'InnoDB' ),
228 'ndb' => array( 'title' => 'NDB' ),
229 'ssl' => array( 'title' => 'SSL' ),
230 'handler' => array( 'title' => $strHandler ),
231 'qcache' => array( 'title' => $strQueryCache ),
232 'threads' => array( 'title' => $strThreads ),
233 'binlog_cache' => array( 'title' => $strBinaryLog ),
234 'created_tmp' => array( 'title' => $strTempData ),
235 'delayed' => array( 'title' => $strServerStatusDelayedInserts ),
236 'key' => array( 'title' => $strKeyCache ),
237 'select' => array( 'title' => $strJoins ),
238 'repl' => array( 'title' => $strReplication ),
239 'sort' => array( 'title' => $strSorting ),
240 'table' => array( 'title' => $strNumTables ),
241 'tc' => array( 'title' => $strTransactionCoordinator ),
246 * define some needfull links/commands
248 // variable or section name => (name => url)
249 $links = array();
251 $links['table'][$strFlushTables]
252 = $PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
253 $links['table'][$strShowOpenTables]
254 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
255 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
257 $links['repl'][$strShowSlaveHosts]
258 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
259 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
260 $links['repl'][$strShowSlaveStatus]
261 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
262 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
263 $links['repl']['MySQL - ' . $strDocu]
264 = $cfg['MySQLManualBase'] . '/replication.html';
266 $links['qcache'][$strFlushQueryCache]
267 = $PHP_SELF . '?flush=QUERY CACHE&amp;' .
268 PMA_generate_common_url();
269 $links['qcache']['MySQL - ' . $strDocu]
270 = $cfg['MySQLManualBase'] . '/query-cache.html';
272 $links['threads'][$strMySQLShowProcess]
273 = 'server_processlist.php?' . PMA_generate_common_url();
274 $links['threads']['MySQL - ' . $strDocu]
275 = $cfg['MySQLManualBase'] . '/mysql-threads.html';
277 $links['key']['MySQL - ' . $strDocu]
278 = $cfg['MySQLManualBase'] . '/myisam-key-cache.html';
280 $links['slow_queries']['MySQL - ' . $strDocu]
281 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
283 $links['binlog_cache']['MySQL - ' . $strDocu]
284 = $cfg['MySQLManualBase'] . '/binary-log.html';
286 $links['Slow_queries']['MySQL - ' . $strDocu]
287 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
289 $links['innodb'][$strServerTabVariables]
290 = 'server_engines.php?engine=innodb&amp;' . PMA_generate_common_url();
291 $links['innodb'][$strInnodbStat]
292 = 'server_engines.php?engine=innodb&amp;page=status&amp;' .
293 PMA_generate_common_url();
294 $links['innodb']['MySQL - ' . $strDocu]
295 = $cfg['MySQLManualBase'] . '/innodb.html';
298 // sort status vars into arrays
299 foreach ( $server_status as $name => $value ) {
300 if ( isset( $allocations[$name] ) ) {
301 $sections[$allocations[$name]]['vars'][$name] = $value;
302 unset( $server_status[$name] );
303 } else {
304 foreach ( $allocations as $filter => $section ) {
305 if ( preg_match( '°^' . $filter . '°i', $name )
306 && isset( $server_status[$name] ) ) {
307 unset( $server_status[$name] );
308 $sections[$section]['vars'][$name] = $value;
313 unset( $name, $value, $filter, $section, $allocations );
315 // rest
316 $sections['all']['vars'] =& $server_status;
318 $hour_factor = 3600 / $server_status['Uptime'];
321 * start output
324 <div id="statuslinks">
325 <a href="<?php echo
326 $PHP_SELF . '?' . PMA_generate_common_url(); ?>"
327 ><?php echo $strRefresh; ?></a>
328 <a href="<?php echo
329 $PHP_SELF . '?flush=STATUS&amp;' . PMA_generate_common_url(); ?>"
330 ><?php echo $strShowStatusReset; ?></a>
331 <a href="<?php echo
332 $cfg['MySQLManualBase']; ?>/server-status-variables.html"
333 target="documentation">MySQL - <?php echo $strDocu; ?></a>
334 </div>
337 <?php
338 echo sprintf( $strServerStatusUptime,
339 PMA_timespanFormat( $server_status['Uptime'] ),
340 PMA_localisedDate( $start_time ) ) . "\n";
342 </p>
344 <div id="sectionlinks">
345 <?php
346 foreach ( $sections as $section_name => $section ) {
347 if ( ! empty( $section['vars'] ) && ! empty( $section['title'] ) ) {
348 echo '<a href="' . $PHP_SELF . '?' .
349 PMA_generate_common_url() . '#' . $section_name . '">' .
350 $section['title'] . '</a>' . "\n";
354 </div>
356 <h3><?php echo $strServerTrafficNotes; ?></h3>
358 <table id="serverstatustraffic" class="data">
359 <thead>
360 <tr>
361 <th colspan="2"><?php echo $strTraffic; ?></th>
362 <th>&oslash; <?php echo $strPerHour; ?></th>
363 </tr>
364 </thead>
365 <tbody>
366 <tr class="odd">
367 <th class="name"><?php echo $strReceived; ?></th>
368 <td class="value"><?php echo
369 implode(' ',
370 PMA_formatByteDown( $server_status['Bytes_received'], 3 ) ); ?></td>
371 <td class="value"><?php echo
372 implode(' ',
373 PMA_formatByteDown(
374 $server_status['Bytes_received'] * $hour_factor, 3 ) ); ?></td>
375 </tr>
376 <tr class="even">
377 <th class="name"><?php echo $strSent; ?></th>
378 <td class="value"><?php echo
379 implode(' ',
380 PMA_formatByteDown( $server_status['Bytes_sent'], 3 ) ); ?></td>
381 <td class="value"><?php echo
382 implode(' ',
383 PMA_formatByteDown(
384 $server_status['Bytes_sent'] * $hour_factor, 3 ) ); ?></td>
385 </tr>
386 <tr class="odd">
387 <th class="name"><?php echo $strTotalUC; ?></th>
388 <td class="value"><?php echo
389 implode(' ',
390 PMA_formatByteDown(
391 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3 )
392 ); ?></td>
393 <td class="value"><?php echo
394 implode(' ',
395 PMA_formatByteDown(
396 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
397 * $hour_factor, 3 )
398 ); ?></td>
399 </tr>
400 </tbody>
401 </table>
403 <table id="serverstatusconnections" class="data">
404 <thead>
405 <tr>
406 <th colspan="2"><?php echo $strConnections; ?></th>
407 <th>&oslash; <?php echo $strPerHour; ?></th>
408 <th>%</th>
409 </tr>
410 </thead>
411 <tbody>
412 <tr class="odd">
413 <th class="name"><?php echo $strMaxConnects; ?></th>
414 <td class="value"><?php echo
415 number_format( $server_status['Max_used_connections'], 0,
416 $GLOBALS['number_decimal_separator'],
417 $GLOBALS['number_thousands_separator']); ?> </td>
418 <td class="value">--- </td>
419 <td class="value">--- </td>
420 </tr>
421 <tr class="even">
422 <th class="name"><?php echo $strFailedAttempts; ?></th>
423 <td class="value"><?php echo
424 PMA_formatNumber( $server_status['Aborted_connects'], 4, 0 ); ?></td>
425 <td class="value"><?php echo
426 PMA_formatNumber( $server_status['Aborted_connects'] * $hour_factor,
427 4, 2 ); ?></td>
428 <td class="value"><?php echo
429 $server_status['Connections'] > 0
430 ? number_format(
431 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
432 2, $GLOBALS['number_decimal_separator'],
433 $GLOBALS['number_thousands_separator'] ) . '%'
434 : '--- '; ?></td>
435 </tr>
436 <tr class="odd">
437 <th class="name"><?php echo $strAbortedClients; ?></th>
438 <td class="value"><?php echo
439 PMA_formatNumber( $server_status['Aborted_clients'], 4, 0 ); ?></td>
440 <td class="value"><?php echo
441 PMA_formatNumber( $server_status['Aborted_clients'] * $hour_factor,
442 4, 2 ); ?></td>
443 <td class="value"><?php echo
444 $server_status['Connections'] > 0
445 ? number_format(
446 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
447 2 , $GLOBALS['number_decimal_separator'],
448 $GLOBALS['number_thousands_separator']) . '%'
449 : '--- '; ?></td>
450 </tr>
451 <tr class="even">
452 <th class="name"><?php echo $strTotalUC; ?></th>
453 <td class="value"><?php echo
454 PMA_formatNumber( $server_status['Connections'], 4, 0 ); ?></td>
455 <td class="value"><?php echo
456 PMA_formatNumber( $server_status['Connections'] * $hour_factor,
457 4, 2 ); ?></td>
458 <td class="value"><?php echo
459 number_format( 100, 2, $GLOBALS['number_decimal_separator'],
460 $GLOBALS['number_thousands_separator'] ); ?>%</td>
461 </tr>
462 </tbody>
463 </table>
465 <hr class="clearfloat" />
467 <h3><?php echo
468 sprintf( $strQueryStatistics,
469 number_format($server_status['Questions'],
470 0, $GLOBALS['number_decimal_separator'],
471 $GLOBALS['number_thousands_separator'] ) ); ?></h3>
473 <table id="serverstatusqueriessummary" class="data">
474 <thead>
475 <tr>
476 <th><?php echo $strTotalUC; ?></th>
477 <th>&oslash; <?php echo $strPerHour; ?></th>
478 <th>&oslash; <?php echo $strPerMinute; ?></th>
479 <th>&oslash; <?php echo $strPerSecond; ?></th>
480 </tr>
481 </thead>
482 <tbody>
483 <tr class="odd">
484 <td class="value"><?php echo
485 PMA_formatNumber( $server_status['Questions'], 3, 0 ); ?></td>
486 <td class="value"><?php echo
487 PMA_formatNumber( $server_status['Questions'] * $hour_factor,
488 3, 2 ); ?></td>
489 <td class="value"><?php echo
490 PMA_formatNumber(
491 $server_status['Questions'] * 60 / $server_status['Uptime'],
492 3, 2 ); ?></td>
493 <td class="value"><?php echo
494 PMA_formatNumber(
495 $server_status['Questions'] / $server_status['Uptime'],
496 3, 2 ); ?></td>
497 </tr>
498 </tbody>
499 </table>
501 <div id="serverstatusqueriesdetails">
502 <?php
503 // number of tables to split values into
504 $tables = 2;
505 $rows_per_table = (int) ceil( count( $sections['com']['vars'] ) / $tables );
506 $current_table = 0;
507 $odd_row = true;
508 $countRows = 0;
509 $perc_factor = 100 / ( $server_status['Questions'] - $server_status['Connections'] );
510 foreach ( $sections['com']['vars'] as $name => $value ) {
511 $current_table++;
512 if ( $countRows === 0 || $countRows === $rows_per_table ) {
513 $odd_row = true;
514 if ( $countRows === $rows_per_table ) {
515 echo ' </tbody>' . "\n";
516 echo ' </table>' . "\n";
519 <table id="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
520 <col class="namecol" />
521 <col class="valuecol" span="3" />
522 <thead>
523 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
524 <th>&oslash; <?php echo $strPerHour; ?></th>
525 <th>%</th>
526 </tr>
527 </thead>
528 <tbody>
529 <?php
530 } else {
531 $odd_row = !$odd_row;
533 $countRows++;
535 // For the percentage column, use Questions - Connections, because
536 // the number of connections is not an item of the Query types
537 // but is included in Questions. Then the total of the percentages is 100.
538 $name = str_replace( 'Com_', '', $name );
539 $name = str_replace( '_', ' ', $name );
541 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
542 <th class="name"><?php echo htmlspecialchars( $name ); ?></th>
543 <td class="value"><?php echo PMA_formatNumber( $value, 3, 0 ); ?></td>
544 <td class="value"><?php echo
545 PMA_formatNumber( $value * $hour_factor, 3, 2 ); ?></td>
546 <td class="value"><?php echo
547 number_format( $value * $perc_factor, 2,
548 $GLOBALS['number_decimal_separator'],
549 $GLOBALS['number_thousands_separator'] ); ?>%</td>
550 </tr>
551 <?php
554 </tbody>
555 </table>
556 </div>
558 <div id="serverstatussection">
559 <?php
560 //Unset used variables
561 unset(
562 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
563 $hour_factor, $sections['com'],
564 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
565 $server_status['Max_used_connections'], $server_status['Bytes_received'],
566 $server_status['Bytes_sent'], $server_status['Connections'],
567 $server_status['Questions'], $server_status['Uptime']
570 foreach ( $sections as $section_name => $section ) {
571 if ( ! empty( $section['vars'] ) ) {
573 <table class="data" id="serverstatussection<?php echo $section_name; ?>">
574 <caption class="tblHeaders">
575 <a class="top"
576 href="<?php echo $PHP_SELF . '?' .
577 PMA_generate_common_url() . '#_top'; ?>"
578 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
579 <?php echo
580 ($GLOBALS['cfg']['MainPageIconic']
581 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
582 's_asc.png" width="11" height="9" align="middle" alt="" />'
583 : '' ); ?>
584 </a>
585 <?php
586 if ( ! empty( $section['title'] ) ) {
587 echo $section['title'];
590 </caption>
591 <col class="namecol" />
592 <col class="valuecol" />
593 <col class="descrcol" />
594 <thead>
595 <tr>
596 <th><?php echo $strVar; ?></th>
597 <th><?php echo $strValue; ?></th>
598 <th><?php echo $strDescription; ?></th>
599 </tr>
600 </thead>
601 <?php
602 if ( ! empty( $links[$section_name] ) ) {
604 <tfoot>
605 <tr class="tblFooters">
606 <th colspan="3" class="tblFooters">
607 <?php
608 foreach ( $links[$section_name] as $link_name => $link_url ) {
609 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
611 unset( $link_url, $link_name );
613 </th>
614 </tr>
615 </tfoot>
616 <?php
619 <tbody>
620 <?php
621 $odd_row = false;
622 foreach ( $section['vars'] as $name => $value ) {
623 $odd_row = !$odd_row;
625 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
626 <th class="name"><?php echo htmlspecialchars($name); ?></th>
627 <td class="value"><?php
628 if ( isset( $alerts[$name] ) ) {
629 if ( $value > $alerts[$name] ) {
630 echo '<span class="attention">';
631 } else {
632 echo '<span class="allfine">';
635 if ( '%' === substr( $name, -1, 1 ) ) {
636 echo number_format( $value, 2,
637 $GLOBALS['number_decimal_separator'],
638 $GLOBALS['number_thousands_separator'] ) . ' %';
639 } elseif ( is_numeric( $value ) && $value == (int) $value ) {
640 echo PMA_formatNumber( $value, 3, 0 );
641 } elseif ( is_numeric( $value ) ) {
642 echo PMA_formatNumber( $value, 3, 2 );
643 } else {
644 echo htmlspecialchars( $value );
646 if ( isset( $alerts[$name] ) ) {
647 echo '</span>';
649 ?></td>
650 <td class="descr">
651 <?php
652 if ( isset( $GLOBALS['strShowStatus' . $name . 'Descr'] ) ) {
653 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
656 if ( isset( $links[$name] ) ) {
657 foreach ( $links[$name] as $link_name => $link_url ) {
658 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
659 "\n";
661 unset( $link_url, $link_name );
664 </td>
665 </tr>
666 <?php
668 unset( $name, $value );
670 </tbody>
671 </table>
672 <?php
675 unset( $section_name, $section, $sections, $server_status, $odd_row, $alerts );
677 </div>
678 </div>
679 <?php
683 * Sends the footer
685 require_once './footer.inc.php';