3 // vim: expandtab sw=4 ts=4 sts=4:
5 * displays status variables with descriptions and some hints an optmizing
6 * + reset status vriales
9 require_once('./libraries/common.lib.php');
12 * Does the common work
14 require './server_common.inc.php';
20 require './server_links.inc.php';
24 * Displays the sub-page heading
26 echo '<a name="_top"></a>' . "\n";
27 echo '<div id="serverstatus">' . "\n";
29 . ($GLOBALS['cfg']['MainPageIconic']
30 ?
'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
31 's_status.png" width="16" height="16" alt="" />'
33 . $strServerStatus . "\n"
38 * flush status variables if requested
40 if ( isset( $_REQUEST['flush'] ) ) {
41 $_flush_commands = array(
47 if ( in_array( $_REQUEST['flush'], $_flush_commands ) ) {
48 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
50 unset( $_flush_commands );
55 * get status from server
57 if ( PMA_MYSQL_INT_VERSION
>= 50002 ) {
58 $server_status = PMA_DBI_fetch_result( 'SHOW GLOBAL STATUS', 0, 1 );
60 $server_status = PMA_DBI_fetch_result( 'SHOW STATUS', 0, 1 );
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 );
70 $server_variables = PMA_DBI_fetch_result( 'SHOW VARIABLES', 0, 1 );
75 * starttime calculation
77 $start_time = PMA_DBI_fetch_value(
78 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime'] );
82 * cleanup some deprecated values
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] );
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']
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']
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']
134 // name => max value before alert
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,
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']
179 // variable => min value
180 //'Handler read key' => '> ',
185 * split variables in sections
187 $allocations = array(
188 // variable name => section
191 'Innodb_' => 'innodb',
194 'Handler_' => 'handler',
195 'Qcache_' => 'qcache',
196 'Threads_' => 'threads',
197 'Slow_launch_threads' => 'threads',
199 'Binlog_cache_' => 'binlog_cache',
200 'Created_tmp_' => 'created_tmp',
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',
213 'Open_tables' => 'table',
214 'Opened_tables' => 'table',
215 'Table_locks_' => 'table',
217 'Rpl_status' => 'repl',
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)
251 $links['table'][$strFlushTables]
252 = $PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
253 $links['table'][$strShowOpenTables]
254 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
255 '&goto=server_status.php&' . PMA_generate_common_url();
257 $links['repl'][$strShowSlaveHosts]
258 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
259 '&goto=server_status.php&' . PMA_generate_common_url();
260 $links['repl'][$strShowSlaveStatus]
261 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
262 '&goto=server_status.php&' . PMA_generate_common_url();
263 $links['repl']['MySQL - ' . $strDocu]
264 = $cfg['MySQLManualBase'] . '/replication.html';
266 $links['qcache'][$strFlushQueryCache]
267 = $PHP_SELF . '?flush=QUERY CACHE&' .
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&' . PMA_generate_common_url();
291 $links['innodb'][$strInnodbStat]
292 = 'server_engines.php?engine=innodb&page=status&' .
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] );
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 );
316 $sections['all']['vars'] =& $server_status;
318 $hour_factor = 3600 / $server_status['Uptime'];
324 <div id
="statuslinks">
326 $PHP_SELF . '?' . PMA_generate_common_url(); ?>"
327 ><?php
echo $strRefresh; ?
></a
>
329 $PHP_SELF . '?flush=STATUS&' . PMA_generate_common_url(); ?>"
330 ><?php
echo $strShowStatusReset; ?
></a
>
332 $cfg['MySQLManualBase']; ?>/server-status-variables.html"
333 target
="documentation">MySQL
- <?php
echo $strDocu; ?
></a
>
338 echo sprintf( $strServerStatusUptime,
339 PMA_timespanFormat( $server_status['Uptime'] ),
340 PMA_localisedDate( $start_time ) ) . "\n";
344 <div id
="sectionlinks">
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";
356 <h3
><?php
echo $strServerTrafficNotes; ?
></h3
>
358 <table id
="serverstatustraffic" class="data">
361 <th colspan
="2"><?php
echo $strTraffic; ?
></th
>
362 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
367 <th
class="name"><?php
echo $strReceived; ?
></th
>
368 <td
class="value"><?php
echo
370 PMA_formatByteDown( $server_status['Bytes_received'], 3 ) ); ?
></td
>
371 <td
class="value"><?php
echo
374 $server_status['Bytes_received'] * $hour_factor, 3 ) ); ?
></td
>
377 <th
class="name"><?php
echo $strSent; ?
></th
>
378 <td
class="value"><?php
echo
380 PMA_formatByteDown( $server_status['Bytes_sent'], 3 ) ); ?
></td
>
381 <td
class="value"><?php
echo
384 $server_status['Bytes_sent'] * $hour_factor, 3 ) ); ?
></td
>
387 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
388 <td
class="value"><?php
echo
391 $server_status['Bytes_received'] +
$server_status['Bytes_sent'], 3 )
393 <td
class="value"><?php
echo
396 ($server_status['Bytes_received'] +
$server_status['Bytes_sent'])
403 <table id
="serverstatusconnections" class="data">
406 <th colspan
="2"><?php
echo $strConnections; ?
></th
>
407 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
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
>
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,
428 <td
class="value"><?php
echo
429 $server_status['Connections'] > 0
431 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
432 2, $GLOBALS['number_decimal_separator'],
433 $GLOBALS['number_thousands_separator'] ) . '%'
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,
443 <td
class="value"><?php
echo
444 $server_status['Connections'] > 0
446 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
447 2 , $GLOBALS['number_decimal_separator'],
448 $GLOBALS['number_thousands_separator']) . '%'
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,
458 <td
class="value"><?php
echo
459 number_format( 100, 2, $GLOBALS['number_decimal_separator'],
460 $GLOBALS['number_thousands_separator'] ); ?
>%
</td
>
465 <hr
class="clearfloat" />
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">
476 <th
><?php
echo $strTotalUC; ?
></th
>
477 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
478 <th
>ø
; <?php
echo $strPerMinute; ?
></th
>
479 <th
>ø
; <?php
echo $strPerSecond; ?
></th
>
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,
489 <td
class="value"><?php
echo
491 $server_status['Questions'] * 60 / $server_status['Uptime'],
493 <td
class="value"><?php
echo
495 $server_status['Questions'] / $server_status['Uptime'],
501 <div id
="serverstatusqueriesdetails">
503 // number of tables to split values into
505 $rows_per_table = (int) ceil( count( $sections['com']['vars'] ) / $tables );
509 $perc_factor = 100 / ( $server_status['Questions'] - $server_status['Connections'] );
510 foreach ( $sections['com']['vars'] as $name => $value ) {
512 if ( $countRows === 0 ||
$countRows === $rows_per_table ) {
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" />
523 <tr
><th colspan
="2"><?php
echo $strQueryType; ?
></th
>
524 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
531 $odd_row = !$odd_row;
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
>
558 <div id
="serverstatussection">
560 //Unset used variables
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">
576 href
="<?php echo $PHP_SELF . '?' .
577 PMA_generate_common_url() . '#_top'; ?>"
578 name
="<?php echo $section_name; ?>"><?php
echo $strPos1; ?
>
580 ($GLOBALS['cfg']['MainPageIconic']
581 ?
'<img src="' . $GLOBALS['pmaThemeImage'] .
582 's_asc.png" width="11" height="9" align="middle" alt="" />'
586 if ( ! empty( $section['title'] ) ) {
587 echo $section['title'];
591 <col
class="namecol" />
592 <col
class="valuecol" />
593 <col
class="descrcol" />
596 <th
><?php
echo $strVar; ?
></th
>
597 <th
><?php
echo $strValue; ?
></th
>
598 <th
><?php
echo $strDescription; ?
></th
>
602 if ( ! empty( $links[$section_name] ) ) {
605 <tr
class="tblFooters">
606 <th colspan
="3" class="tblFooters">
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 );
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">';
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 );
644 echo htmlspecialchars( $value );
646 if ( isset( $alerts[$name] ) ) {
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>' .
661 unset( $link_url, $link_name );
668 unset( $name, $value );
675 unset( $section_name, $section, $sections, $server_status, $odd_row, $alerts );
685 require_once './footer.inc.php';