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 . $strServerStatus . "\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' => $strSQLQuery),
248 'innodb' => array('title' => 'InnoDB'),
249 'ndb' => array('title' => 'NDB'),
250 'handler' => array('title' => $strHandler),
251 'qcache' => array('title' => $strQueryCache),
252 'threads' => array('title' => $strThreads),
253 'binlog_cache' => array('title' => $strBinaryLog),
254 'created_tmp' => array('title' => $strTempData),
255 'delayed' => array('title' => $strServerStatusDelayedInserts),
256 'key' => array('title' => $strKeyCache),
257 'select' => array('title' => $strJoins),
258 'repl' => array('title' => $strReplication),
259 'sort' => array('title' => $strSorting),
260 'table' => array('title' => $strNumTables),
261 'tc' => array('title' => $strTransactionCoordinator),
262 'ssl' => array('title' => 'SSL'),
266 * define some needfull links/commands
268 // variable or section name => (name => url)
271 $links['table'][$strFlushTables]
272 = $PMA_PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
273 $links['table'][$strShowOpenTables]
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'][$strShowSlaveHosts]
279 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
280 '&goto=server_status.php&' . PMA_generate_common_url();
281 $links['repl'][$strShowMasterStatus] = '#replication_master';
283 if ($server_slave_status) {
284 $links['repl'][$strShowSlaveStatus] = '#replication_slave';
287 $links['repl']['doc'] = 'replication';
289 $links['qcache'][$strFlushQueryCache]
290 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' .
291 PMA_generate_common_url();
292 $links['qcache']['doc'] = 'query_cache';
294 $links['threads'][$strMySQLShowProcess]
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'][$strServerTabVariables]
305 = 'server_engines.php?engine=InnoDB&' . PMA_generate_common_url();
306 $links['innodb'][$strInnodbStat]
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 $strRefresh; ?
></a
>
343 $PMA_PHP_SELF . '?flush=STATUS&' . PMA_generate_common_url(); ?>"
344 ><?php
echo $strShowStatusReset; ?
></a
>
345 <?php
echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?
>
350 echo sprintf($strServerStatusUptime,
351 PMA_timespanFormat($server_status['Uptime']),
352 PMA_localisedDate($start_time)) . "\n";
357 if ($server_master_status ||
$server_slave_status)
359 $replicationOut = "";
360 foreach ($replication_types as $type)
362 if ($
{"server_{$type}_status"})
364 if ($replicationOut != "")
365 $replicationOut .= $strAndSmall . ' ';
366 $replicationOut .= '<b>' . $type . '</b> ';
369 echo sprintf('<p>' . $strReplicationStatusInfo . '</p>', $replicationOut);
373 <div id
="sectionlinks">
375 foreach ($sections as $section_name => $section) {
376 if (! empty($section['vars']) && ! empty($section['title'])) {
377 echo '<a href="' . $PMA_PHP_SELF . '?' .
378 PMA_generate_common_url() . '#' . $section_name . '">' .
379 $section['title'] . '</a>' . "\n";
385 <h3
><?php
echo $strServerTrafficNotes; ?
></h3
>
387 <table id
="serverstatustraffic" class="data">
390 <th colspan
="2"><?php
echo $strTraffic . ' ' . PMA_showHint($strStatisticsOverrun); ?
></th
>
391 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
396 <th
class="name"><?php
echo $strReceived; ?
></th
>
397 <td
class="value"><?php
echo
399 PMA_formatByteDown($server_status['Bytes_received'], 2, 1)); ?
></td
>
400 <td
class="value"><?php
echo
403 $server_status['Bytes_received'] * $hour_factor, 2, 1)); ?
></td
>
406 <th
class="name"><?php
echo $strSent; ?
></th
>
407 <td
class="value"><?php
echo
409 PMA_formatByteDown($server_status['Bytes_sent'], 2, 1)); ?
></td
>
410 <td
class="value"><?php
echo
413 $server_status['Bytes_sent'] * $hour_factor, 2, 1)); ?
></td
>
416 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
417 <td
class="value"><?php
echo
420 $server_status['Bytes_received'] +
$server_status['Bytes_sent'], 2, 1)
422 <td
class="value"><?php
echo
425 ($server_status['Bytes_received'] +
$server_status['Bytes_sent'])
426 * $hour_factor, 2, 1)
432 <table id
="serverstatusconnections" class="data">
435 <th colspan
="2"><?php
echo $strConnections; ?
></th
>
436 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
442 <th
class="name"><?php
echo $strMaxConnects; ?
></th
>
443 <td
class="value"><?php
echo
444 PMA_formatNumber($server_status['Max_used_connections'], 0); ?
> </td
>
445 <td
class="value">--- </td
>
446 <td
class="value">--- </td
>
449 <th
class="name"><?php
echo $strFailedAttempts; ?
></th
>
450 <td
class="value"><?php
echo
451 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?
></td
>
452 <td
class="value"><?php
echo
453 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
455 <td
class="value"><?php
echo
456 $server_status['Connections'] > 0
458 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
463 <th
class="name"><?php
echo $strAbortedClients; ?
></th
>
464 <td
class="value"><?php
echo
465 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?
></td
>
466 <td
class="value"><?php
echo
467 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
469 <td
class="value"><?php
echo
470 $server_status['Connections'] > 0
472 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
477 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
478 <td
class="value"><?php
echo
479 PMA_formatNumber($server_status['Connections'], 4, 0); ?
></td
>
480 <td
class="value"><?php
echo
481 PMA_formatNumber($server_status['Connections'] * $hour_factor,
483 <td
class="value"><?php
echo
484 PMA_formatNumber(100, 0, 2); ?
>%
</td
>
489 <hr
class="clearfloat" />
492 sprintf($strQueryStatistics,
493 PMA_formatNumber($server_status['Questions'], 0)); ?
></h3
>
495 <table id
="serverstatusqueriessummary" class="data">
498 <th
><?php
echo $strTotalUC; ?
></th
>
499 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
500 <th
>ø
; <?php
echo $strPerMinute; ?
></th
>
501 <th
>ø
; <?php
echo $strPerSecond; ?
></th
>
506 <td
class="value"><?php
echo
507 PMA_formatNumber($server_status['Questions'], 4, 0); ?
></td
>
508 <td
class="value"><?php
echo
509 PMA_formatNumber($server_status['Questions'] * $hour_factor,
511 <td
class="value"><?php
echo
513 $server_status['Questions'] * 60 / $server_status['Uptime'],
515 <td
class="value"><?php
echo
517 $server_status['Questions'] / $server_status['Uptime'],
523 <div id
="serverstatusqueriesdetails">
526 $used_queries = $sections['com']['vars'];
527 // reverse sort by value to show most used statements first
528 arsort($used_queries);
529 // remove all zero values from the end
530 while (end($used_queries) == 0) {
531 array_pop($used_queries);
534 // number of tables to split values into
536 $max_rows_per_table = (int) ceil(count($used_queries) / $tables);
539 $count_displayed_rows = 0;
540 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
542 foreach ($used_queries as $name => $value) {
544 if ($count_displayed_rows === 0 ||
$count_displayed_rows === $max_rows_per_table) {
546 if ($count_displayed_rows === $max_rows_per_table) {
547 echo ' </tbody>' . "\n";
548 echo ' </table>' . "\n";
549 $count_displayed_rows = 0;
552 <table id
="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
553 <col
class="namecol" />
554 <col
class="valuecol" span
="3" />
556 <tr
><th colspan
="2"><?php
echo $strQueryType; ?
></th
>
557 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
564 $odd_row = !$odd_row;
566 $count_displayed_rows++
;
568 // For the percentage column, use Questions - Connections, because
569 // the number of connections is not an item of the Query types
570 // but is included in Questions. Then the total of the percentages is 100.
571 $name = str_replace('Com_', '', $name);
572 $name = str_replace('_', ' ', $name);
574 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
575 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
576 <td
class="value"><?php
echo PMA_formatNumber($value, 4, 0); ?
></td
>
577 <td
class="value"><?php
echo
578 PMA_formatNumber($value * $hour_factor, 3, 3); ?
></td
>
579 <td
class="value"><?php
echo
580 PMA_formatNumber($value * $perc_factor, 0, 2); ?
>%
</td
>
589 <div id
="serverstatussection">
591 //Unset used variables
593 $tables, $max_rows_per_table, $current_table, $count_displayed_rows, $perc_factor,
594 $hour_factor, $sections['com'],
595 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
596 $server_status['Max_used_connections'], $server_status['Bytes_received'],
597 $server_status['Bytes_sent'], $server_status['Connections'],
598 $server_status['Questions'], $server_status['Uptime'],
602 foreach ($sections as $section_name => $section) {
603 if (! empty($section['vars'])) {
605 <table
class="data" id
="serverstatussection<?php echo $section_name; ?>">
606 <caption
class="tblHeaders">
608 href
="<?php echo $PMA_PHP_SELF . '?' .
609 PMA_generate_common_url() . '#serverstatus'; ?>"
610 name
="<?php echo $section_name; ?>"><?php
echo $strPos1; ?
>
612 ($GLOBALS['cfg']['MainPageIconic']
613 ?
'<img src="' . $GLOBALS['pmaThemeImage'] .
614 's_asc.png" width="11" height="9" align="middle" alt="" />'
618 if (! empty($section['title'])) {
619 echo $section['title'];
623 <col
class="namecol" />
624 <col
class="valuecol" />
625 <col
class="descrcol" />
628 <th
><?php
echo $strVar; ?
></th
>
629 <th
><?php
echo $strValue; ?
></th
>
630 <th
><?php
echo $strDescription; ?
></th
>
634 if (! empty($links[$section_name])) {
637 <tr
class="tblFooters">
638 <th colspan
="3" class="tblFooters">
640 foreach ($links[$section_name] as $link_name => $link_url) {
641 if ('doc' == $link_name) {
642 echo PMA_showMySQLDocu($link_url, $link_url);
644 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
647 unset($link_url, $link_name);
658 foreach ($section['vars'] as $name => $value) {
659 $odd_row = !$odd_row;
661 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
662 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
663 <td
class="value"><?php
664 if (isset($alerts[$name])) {
665 if ($value > $alerts[$name]) {
666 echo '<span class="attention">';
668 echo '<span class="allfine">';
671 if ('%' === substr($name, -1, 1)) {
672 echo PMA_formatNumber($value, 0, 2) . ' %';
673 } elseif (is_numeric($value) && $value == (int) $value) {
674 echo PMA_formatNumber($value, 3, 1);
675 } elseif (is_numeric($value)) {
676 echo PMA_formatNumber($value, 3, 1);
678 echo htmlspecialchars($value);
680 if (isset($alerts[$name])) {
686 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
687 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
690 if (isset($links[$name])) {
691 foreach ($links[$name] as $link_name => $link_url) {
692 if ('doc' == $link_name) {
693 echo PMA_showMySQLDocu($link_url, $link_url);
695 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
699 unset($link_url, $link_name);
706 unset($name, $value);
713 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
717 /* if the server works as master or slave in replication process, display useful information */
718 if ($server_master_status ||
$server_slave_status)
721 <hr
class="clearfloat" />
723 <h3
><a name
="replication"></a
><?php
echo $strReplicationStatus; ?
></h3
>
726 foreach ($replication_types as $type)
728 if ($
{"server_{$type}_status"}) {
729 PMA_replication_print_status_table($type);
742 require_once './libraries/footer.inc.php';