2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * displays status variables with descriptions and some hints an optmizing
5 * + reset status variables
12 * no need for variables importing
15 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
16 define('PMA_NO_VARIABLES_IMPORT', true);
18 require_once './libraries/common.inc.php';
21 * Does the common work
23 require './libraries/server_common.inc.php';
29 require './libraries/server_links.inc.php';
34 require './libraries/replication.inc.php';
35 require_once './libraries/replication_gui.lib.php';
38 * Displays the sub-page heading
40 echo '<div id="serverstatus">' . "\n";
42 . ($GLOBALS['cfg']['MainPageIconic']
43 ?
'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
44 's_status.png" width="16" height="16" alt="" />'
46 . __('Runtime Information') . "\n"
51 * flush status variables if requested
53 if (isset($_REQUEST['flush'])) {
54 $_flush_commands = array(
60 if (in_array($_REQUEST['flush'], $_flush_commands)) {
61 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
63 unset($_flush_commands);
68 * get status from server
70 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
73 * for some calculations we require also some server settings
75 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
78 * starttime calculation
80 $start_time = PMA_DBI_fetch_value(
81 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
85 * cleanup some deprecated values
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]);
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']
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']
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']
146 // Format Uptime_since_flush_status : show as days, hours, minutes, seconds
147 if (isset($server_status['Uptime_since_flush_status'])) {
148 $server_status['Uptime_since_flush_status'] = PMA_timespanFormat($server_status['Uptime_since_flush_status']);
154 // name => max value before alert
157 // variable => max value
158 'Aborted_clients' => 0,
159 'Aborted_connects' => 0,
161 'Binlog_cache_disk_use' => 0,
163 'Created_tmp_disk_tables' => 0,
165 'Handler_read_rnd' => 0,
166 'Handler_read_rnd_next' => 0,
168 'Innodb_buffer_pool_pages_dirty' => 0,
169 'Innodb_buffer_pool_reads' => 0,
170 'Innodb_buffer_pool_wait_free' => 0,
171 'Innodb_log_waits' => 0,
172 'Innodb_row_lock_time_avg' => 10, // ms
173 'Innodb_row_lock_time_max' => 50, // ms
174 'Innodb_row_lock_waits' => 0,
177 'Delayed_errors' => 0,
178 'Select_full_join' => 0,
179 'Select_range_check' => 0,
180 'Sort_merge_passes' => 0,
181 'Opened_tables' => 0,
182 'Table_locks_waited' => 0,
183 'Qcache_lowmem_prunes' => 0,
184 'Slow_launch_threads' => 0,
186 // depends on Key_read_requests
187 // normaly lower then 1:0.01
188 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
189 // depends on Key_write_requests
190 // normaly nearly 1:1
191 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
193 'Key_buffer_fraction' => 0.5,
195 // alert if more than 95% of thread cache is in use
196 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
199 // variable => min value
200 //'Handler read key' => '> ',
205 * split variables in sections
207 $allocations = array(
208 // variable name => section
211 'Innodb_' => 'innodb',
213 'Handler_' => 'handler',
214 'Qcache_' => 'qcache',
215 'Threads_' => 'threads',
216 'Slow_launch_threads' => 'threads',
218 'Binlog_cache_' => 'binlog_cache',
219 'Created_tmp_' => 'created_tmp',
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',
232 'Open_tables' => 'table',
233 'Opened_tables' => 'table',
234 'Table_locks_' => 'table',
236 'Rpl_status' => 'repl',
245 // section => section name (description)
246 'com' => array('title' => ''),
247 'query' => array('title' => __('SQL query')),
248 'innodb' => array('title' => 'InnoDB'),
249 'ndb' => array('title' => 'NDB'),
250 'handler' => array('title' => __('Handler')),
251 'qcache' => array('title' => __('Query cache')),
252 'threads' => array('title' => __('Threads')),
253 'binlog_cache' => array('title' => __('Binary log')),
254 'created_tmp' => array('title' => __('Temporary data')),
255 'delayed' => array('title' => __('Delayed inserts')),
256 'key' => array('title' => __('Key cache')),
257 'select' => array('title' => __('Joins')),
258 'repl' => array('title' => __('Replication')),
259 'sort' => array('title' => __('Sorting')),
260 'table' => array('title' => __('Tables')),
261 'tc' => array('title' => __('Transaction coordinator')),
262 'ssl' => array('title' => 'SSL'),
266 * define some needfull links/commands
268 // variable or section name => (name => url)
271 $links['table'][__('Flush (close) all tables')]
272 = $PMA_PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
273 $links['table'][__('Show open tables')]
274 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
275 '&goto=server_status.php&' . PMA_generate_common_url();
277 if ($server_master_status) {
278 $links['repl'][__('Show slave hosts')]
279 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
280 '&goto=server_status.php&' . PMA_generate_common_url();
281 $links['repl'][__('Show master status')] = '#replication_master';
283 if ($server_slave_status) {
284 $links['repl'][__('Show slave status')] = '#replication_slave';
287 $links['repl']['doc'] = 'replication';
289 $links['qcache'][__('Flush query cache')]
290 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' .
291 PMA_generate_common_url();
292 $links['qcache']['doc'] = 'query_cache';
294 $links['threads'][__('Show processes')]
295 = 'server_processlist.php?' . PMA_generate_common_url();
296 $links['threads']['doc'] = 'mysql_threads';
298 $links['key']['doc'] = 'myisam_key_cache';
300 $links['binlog_cache']['doc'] = 'binary_log';
302 $links['Slow_queries']['doc'] = 'slow_query_log';
304 $links['innodb'][__('Variables')]
305 = 'server_engines.php?engine=InnoDB&' . PMA_generate_common_url();
306 $links['innodb'][__('InnoDB Status')]
307 = 'server_engines.php?engine=InnoDB&page=Status&' .
308 PMA_generate_common_url();
309 $links['innodb']['doc'] = 'innodb';
312 // sort status vars into arrays
313 foreach ($server_status as $name => $value) {
314 if (isset($allocations[$name])) {
315 $sections[$allocations[$name]]['vars'][$name] = $value;
316 unset($server_status[$name]);
318 foreach ($allocations as $filter => $section) {
319 if (preg_match('/^' . $filter . '/', $name)
320 && isset($server_status[$name])) {
321 unset($server_status[$name]);
322 $sections[$section]['vars'][$name] = $value;
327 unset($name, $value, $filter, $section, $allocations);
330 $sections['all']['vars'] =& $server_status;
332 $hour_factor = 3600 / $server_status['Uptime'];
338 <div id
="statuslinks">
340 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
341 ><?php
echo __('Refresh'); ?
></a
>
343 $PMA_PHP_SELF . '?flush=STATUS&' . PMA_generate_common_url(); ?>"
344 ><?php
echo _pgettext('for Show status', 'Reset'); ?
></a
>
345 <?php
echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?
>
350 echo sprintf(__('This MySQL server has been running for %s. It started up on %s.'),
351 PMA_timespanFormat($server_status['Uptime']),
352 PMA_localisedDate($start_time)) . "\n";
357 if ($server_master_status ||
$server_slave_status) {
359 if ($server_master_status && $server_slave_status) {
360 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
361 } elseif ($server_master_status) {
362 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
363 } elseif ($server_slave_status) {
364 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
366 echo __('For further information about replication status on the server, please visit the <a href=#replication>replication section</a>.');
371 <div id
="sectionlinks">
373 foreach ($sections as $section_name => $section) {
374 if (! empty($section['vars']) && ! empty($section['title'])) {
375 echo '<a href="' . $PMA_PHP_SELF . '?' .
376 PMA_generate_common_url() . '#' . $section_name . '">' .
377 $section['title'] . '</a>' . "\n";
383 <h3
><?php
echo __('<b>Server traffic</b>: These tables show the network traffic statistics of this MySQL server since its startup.'); ?
></h3
>
385 <table id
="serverstatustraffic" class="data">
388 <th colspan
="2"><?php
echo __('Traffic') . ' ' . PMA_showHint(__('On a busy server, the byte counters may overrun, so those statistics as reported by the MySQL server may be incorrect.')); ?
></th
>
389 <th
>ø
; <?php
echo __('per hour'); ?
></th
>
394 <th
class="name"><?php
echo __('Received'); ?
></th
>
395 <td
class="value"><?php
echo
397 PMA_formatByteDown($server_status['Bytes_received'], 2, 1)); ?
></td
>
398 <td
class="value"><?php
echo
401 $server_status['Bytes_received'] * $hour_factor, 2, 1)); ?
></td
>
404 <th
class="name"><?php
echo __('Sent'); ?
></th
>
405 <td
class="value"><?php
echo
407 PMA_formatByteDown($server_status['Bytes_sent'], 2, 1)); ?
></td
>
408 <td
class="value"><?php
echo
411 $server_status['Bytes_sent'] * $hour_factor, 2, 1)); ?
></td
>
414 <th
class="name"><?php
echo __('Total'); ?
></th
>
415 <td
class="value"><?php
echo
418 $server_status['Bytes_received'] +
$server_status['Bytes_sent'], 2, 1)
420 <td
class="value"><?php
echo
423 ($server_status['Bytes_received'] +
$server_status['Bytes_sent'])
424 * $hour_factor, 2, 1)
430 <table id
="serverstatusconnections" class="data">
433 <th colspan
="2"><?php
echo __('Connections'); ?
></th
>
434 <th
>ø
; <?php
echo __('per hour'); ?
></th
>
440 <th
class="name"><?php
echo __('max. concurrent connections'); ?
></th
>
441 <td
class="value"><?php
echo
442 PMA_formatNumber($server_status['Max_used_connections'], 0); ?
> </td
>
443 <td
class="value">--- </td
>
444 <td
class="value">--- </td
>
447 <th
class="name"><?php
echo __('Failed attempts'); ?
></th
>
448 <td
class="value"><?php
echo
449 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?
></td
>
450 <td
class="value"><?php
echo
451 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
453 <td
class="value"><?php
echo
454 $server_status['Connections'] > 0
456 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
461 <th
class="name"><?php
echo __('Aborted'); ?
></th
>
462 <td
class="value"><?php
echo
463 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?
></td
>
464 <td
class="value"><?php
echo
465 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
467 <td
class="value"><?php
echo
468 $server_status['Connections'] > 0
470 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
475 <th
class="name"><?php
echo __('Total'); ?
></th
>
476 <td
class="value"><?php
echo
477 PMA_formatNumber($server_status['Connections'], 4, 0); ?
></td
>
478 <td
class="value"><?php
echo
479 PMA_formatNumber($server_status['Connections'] * $hour_factor,
481 <td
class="value"><?php
echo
482 PMA_formatNumber(100, 0, 2); ?
>%
</td
>
487 <hr
class="clearfloat" />
490 sprintf(__('<b>Query statistics</b>: Since its startup, %s queries have been sent to the server.'),
491 PMA_formatNumber($server_status['Questions'], 0)); ?
></h3
>
493 <table id
="serverstatusqueriessummary" class="data">
496 <th
><?php
echo __('Total'); ?
></th
>
497 <th
>ø
; <?php
echo __('per hour'); ?
></th
>
498 <th
>ø
; <?php
echo __('per minute'); ?
></th
>
499 <th
>ø
; <?php
echo __('per second'); ?
></th
>
504 <td
class="value"><?php
echo
505 PMA_formatNumber($server_status['Questions'], 4, 0); ?
></td
>
506 <td
class="value"><?php
echo
507 PMA_formatNumber($server_status['Questions'] * $hour_factor,
509 <td
class="value"><?php
echo
511 $server_status['Questions'] * 60 / $server_status['Uptime'],
513 <td
class="value"><?php
echo
515 $server_status['Questions'] / $server_status['Uptime'],
521 <div id
="serverstatusqueriesdetails">
524 $used_queries = $sections['com']['vars'];
525 // reverse sort by value to show most used statements first
526 arsort($used_queries);
527 // remove all zero values from the end
528 while (end($used_queries) == 0) {
529 array_pop($used_queries);
532 // number of tables to split values into
534 $max_rows_per_table = (int) ceil(count($used_queries) / $tables);
537 $count_displayed_rows = 0;
538 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
540 foreach ($used_queries as $name => $value) {
542 if ($count_displayed_rows === 0 ||
$count_displayed_rows === $max_rows_per_table) {
544 if ($count_displayed_rows === $max_rows_per_table) {
545 echo ' </tbody>' . "\n";
546 echo ' </table>' . "\n";
547 $count_displayed_rows = 0;
550 <table id
="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
551 <col
class="namecol" />
552 <col
class="valuecol" span
="3" />
554 <tr
><th colspan
="2"><?php
echo __('Query type'); ?
></th
>
555 <th
>ø
; <?php
echo __('per hour'); ?
></th
>
562 $odd_row = !$odd_row;
564 $count_displayed_rows++
;
566 // For the percentage column, use Questions - Connections, because
567 // the number of connections is not an item of the Query types
568 // but is included in Questions. Then the total of the percentages is 100.
569 $name = str_replace('Com_', '', $name);
570 $name = str_replace('_', ' ', $name);
572 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
573 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
574 <td
class="value"><?php
echo PMA_formatNumber($value, 4, 0); ?
></td
>
575 <td
class="value"><?php
echo
576 PMA_formatNumber($value * $hour_factor, 3, 3); ?
></td
>
577 <td
class="value"><?php
echo
578 PMA_formatNumber($value * $perc_factor, 0, 2); ?
>%
</td
>
587 <div id
="serverstatussection">
589 //Unset used variables
591 $tables, $max_rows_per_table, $current_table, $count_displayed_rows, $perc_factor,
592 $hour_factor, $sections['com'],
593 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
594 $server_status['Max_used_connections'], $server_status['Bytes_received'],
595 $server_status['Bytes_sent'], $server_status['Connections'],
596 $server_status['Questions'], $server_status['Uptime'],
600 foreach ($sections as $section_name => $section) {
601 if (! empty($section['vars'])) {
603 <table
class="data" id
="serverstatussection<?php echo $section_name; ?>">
604 <caption
class="tblHeaders">
606 href
="<?php echo $PMA_PHP_SELF . '?' .
607 PMA_generate_common_url() . '#serverstatus'; ?>"
608 name
="<?php echo $section_name; ?>"><?php
echo __('Begin'); ?
>
610 ($GLOBALS['cfg']['MainPageIconic']
611 ?
'<img src="' . $GLOBALS['pmaThemeImage'] .
612 's_asc.png" width="11" height="9" align="middle" alt="" />'
616 if (! empty($section['title'])) {
617 echo $section['title'];
621 <col
class="namecol" />
622 <col
class="valuecol" />
623 <col
class="descrcol" />
626 <th
><?php
echo __('Variable'); ?
></th
>
627 <th
><?php
echo __('Value'); ?
></th
>
628 <th
><?php
echo __('Description'); ?
></th
>
632 if (! empty($links[$section_name])) {
635 <tr
class="tblFooters">
636 <th colspan
="3" class="tblFooters">
638 foreach ($links[$section_name] as $link_name => $link_url) {
639 if ('doc' == $link_name) {
640 echo PMA_showMySQLDocu($link_url, $link_url);
642 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
645 unset($link_url, $link_name);
656 foreach ($section['vars'] as $name => $value) {
657 $odd_row = !$odd_row;
659 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
660 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
661 <td
class="value"><?php
662 if (isset($alerts[$name])) {
663 if ($value > $alerts[$name]) {
664 echo '<span class="attention">';
666 echo '<span class="allfine">';
669 if ('%' === substr($name, -1, 1)) {
670 echo PMA_formatNumber($value, 0, 2) . ' %';
671 } elseif (is_numeric($value) && $value == (int) $value) {
672 echo PMA_formatNumber($value, 3, 1);
673 } elseif (is_numeric($value)) {
674 echo PMA_formatNumber($value, 3, 1);
676 echo htmlspecialchars($value);
678 if (isset($alerts[$name])) {
684 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
685 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
688 if (isset($links[$name])) {
689 foreach ($links[$name] as $link_name => $link_url) {
690 if ('doc' == $link_name) {
691 echo PMA_showMySQLDocu($link_url, $link_url);
693 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
697 unset($link_url, $link_name);
704 unset($name, $value);
711 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
715 /* if the server works as master or slave in replication process, display useful information */
716 if ($server_master_status ||
$server_slave_status)
719 <hr
class="clearfloat" />
721 <h3
><a name
="replication"></a
><?php
echo __('Replication status'); ?
></h3
>
724 foreach ($replication_types as $type)
726 if ($
{"server_{$type}_status"}) {
727 PMA_replication_print_status_table($type);
740 require_once './libraries/footer.inc.php';