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']
150 // name => max value before alert
153 // variable => max value
154 'Aborted_clients' => 0,
155 'Aborted_connects' => 0,
157 'Binlog_cache_disk_use' => 0,
159 'Created_tmp_disk_tables' => 0,
161 'Handler_read_rnd' => 0,
162 'Handler_read_rnd_next' => 0,
164 'Innodb_buffer_pool_pages_dirty' => 0,
165 'Innodb_buffer_pool_reads' => 0,
166 'Innodb_buffer_pool_wait_free' => 0,
167 'Innodb_log_waits' => 0,
168 'Innodb_row_lock_time_avg' => 10, // ms
169 'Innodb_row_lock_time_max' => 50, // ms
170 'Innodb_row_lock_waits' => 0,
173 'Delayed_errors' => 0,
174 'Select_full_join' => 0,
175 'Select_range_check' => 0,
176 'Sort_merge_passes' => 0,
177 'Opened_tables' => 0,
178 'Table_locks_waited' => 0,
179 'Qcache_lowmem_prunes' => 0,
180 'Slow_launch_threads' => 0,
182 // depends on Key_read_requests
183 // normaly lower then 1:0.01
184 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
185 // depends on Key_write_requests
186 // normaly nearly 1:1
187 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
189 'Key_buffer_fraction' => 0.5,
191 // alert if more than 95% of thread cache is in use
192 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
195 // variable => min value
196 //'Handler read key' => '> ',
201 * split variables in sections
203 $allocations = array(
204 // variable name => section
207 'Innodb_' => 'innodb',
210 'Handler_' => 'handler',
211 'Qcache_' => 'qcache',
212 'Threads_' => 'threads',
213 'Slow_launch_threads' => 'threads',
215 'Binlog_cache_' => 'binlog_cache',
216 'Created_tmp_' => 'created_tmp',
219 'Delayed_' => 'delayed',
220 'Not_flushed_delayed_rows' => 'delayed',
222 'Flush_commands' => 'query',
223 'Last_query_cost' => 'query',
224 'Slow_queries' => 'query',
226 'Select_' => 'select',
229 'Open_tables' => 'table',
230 'Opened_tables' => 'table',
231 'Table_locks_' => 'table',
233 'Rpl_status' => 'repl',
240 // section => section name (description)
241 'com' => array('title' => ''),
242 'query' => array('title' => $strSQLQuery),
243 'innodb' => array('title' => 'InnoDB'),
244 'ndb' => array('title' => 'NDB'),
245 'ssl' => array('title' => 'SSL'),
246 'handler' => array('title' => $strHandler),
247 'qcache' => array('title' => $strQueryCache),
248 'threads' => array('title' => $strThreads),
249 'binlog_cache' => array('title' => $strBinaryLog),
250 'created_tmp' => array('title' => $strTempData),
251 'delayed' => array('title' => $strServerStatusDelayedInserts),
252 'key' => array('title' => $strKeyCache),
253 'select' => array('title' => $strJoins),
254 'repl' => array('title' => $strReplication),
255 'sort' => array('title' => $strSorting),
256 'table' => array('title' => $strNumTables),
257 'tc' => array('title' => $strTransactionCoordinator),
261 * define some needfull links/commands
263 // variable or section name => (name => url)
266 $links['table'][$strFlushTables]
267 = $PMA_PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
268 $links['table'][$strShowOpenTables]
269 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
270 '&goto=server_status.php&' . PMA_generate_common_url();
272 if ($server_master_status) {
273 $links['repl'][$strShowSlaveHosts]
274 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
275 '&goto=server_status.php&' . PMA_generate_common_url();
276 $links['repl'][$strShowMasterStatus] = '#replication_master';
278 if ($server_slave_status) {
279 $links['repl'][$strShowSlaveStatus] = '#replication_slave';
282 $links['repl']['doc'] = 'replication';
284 $links['qcache'][$strFlushQueryCache]
285 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' .
286 PMA_generate_common_url();
287 $links['qcache']['doc'] = 'query_cache';
289 $links['threads'][$strMySQLShowProcess]
290 = 'server_processlist.php?' . PMA_generate_common_url();
291 $links['threads']['doc'] = 'mysql_threads';
293 $links['key']['doc'] = 'myisam_key_cache';
295 $links['binlog_cache']['doc'] = 'binary_log';
297 $links['Slow_queries']['doc'] = 'slow_query_log';
299 $links['innodb'][$strServerTabVariables]
300 = 'server_engines.php?engine=InnoDB&' . PMA_generate_common_url();
301 $links['innodb'][$strInnodbStat]
302 = 'server_engines.php?engine=InnoDB&page=Status&' .
303 PMA_generate_common_url();
304 $links['innodb']['doc'] = 'innodb';
307 // sort status vars into arrays
308 foreach ($server_status as $name => $value) {
309 if (isset($allocations[$name])) {
310 $sections[$allocations[$name]]['vars'][$name] = $value;
311 unset($server_status[$name]);
313 foreach ($allocations as $filter => $section) {
314 if (preg_match('/^' . $filter . '/', $name)
315 && isset($server_status[$name])) {
316 unset($server_status[$name]);
317 $sections[$section]['vars'][$name] = $value;
322 unset($name, $value, $filter, $section, $allocations);
325 $sections['all']['vars'] =& $server_status;
327 $hour_factor = 3600 / $server_status['Uptime'];
333 <div id
="statuslinks">
335 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
336 ><?php
echo $strRefresh; ?
></a
>
338 $PMA_PHP_SELF . '?flush=STATUS&' . PMA_generate_common_url(); ?>"
339 ><?php
echo $strShowStatusReset; ?
></a
>
340 <?php
echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?
>
345 echo sprintf($strServerStatusUptime,
346 PMA_timespanFormat($server_status['Uptime']),
347 PMA_localisedDate($start_time)) . "\n";
352 if ($server_master_status ||
$server_slave_status)
354 $replicationOut = "";
355 foreach ($replication_types as $type)
357 if ($
{"server_{$type}_status"})
359 if ($replicationOut != "")
360 $replicationOut .= $strAndSmall . ' ';
361 $replicationOut .= '<b>' . $type . '</b> ';
364 echo sprintf('<p>' . $strReplicationStatusInfo . '</p>', $replicationOut);
368 <div id
="sectionlinks">
370 foreach ($sections as $section_name => $section) {
371 if (! empty($section['vars']) && ! empty($section['title'])) {
372 echo '<a href="' . $PMA_PHP_SELF . '?' .
373 PMA_generate_common_url() . '#' . $section_name . '">' .
374 $section['title'] . '</a>' . "\n";
380 <h3
><?php
echo $strServerTrafficNotes; ?
></h3
>
382 <table id
="serverstatustraffic" class="data">
385 <th colspan
="2"><?php
echo $strTraffic . ' ' . PMA_showHint($strStatisticsOverrun); ?
></th
>
386 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
391 <th
class="name"><?php
echo $strReceived; ?
></th
>
392 <td
class="value"><?php
echo
394 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?
></td
>
395 <td
class="value"><?php
echo
398 $server_status['Bytes_received'] * $hour_factor, 4)); ?
></td
>
401 <th
class="name"><?php
echo $strSent; ?
></th
>
402 <td
class="value"><?php
echo
404 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?
></td
>
405 <td
class="value"><?php
echo
408 $server_status['Bytes_sent'] * $hour_factor, 4)); ?
></td
>
411 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
412 <td
class="value"><?php
echo
415 $server_status['Bytes_received'] +
$server_status['Bytes_sent'], 4)
417 <td
class="value"><?php
echo
420 ($server_status['Bytes_received'] +
$server_status['Bytes_sent'])
427 <table id
="serverstatusconnections" class="data">
430 <th colspan
="2"><?php
echo $strConnections; ?
></th
>
431 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
437 <th
class="name"><?php
echo $strMaxConnects; ?
></th
>
438 <td
class="value"><?php
echo
439 PMA_formatNumber($server_status['Max_used_connections'], 0); ?
> </td
>
440 <td
class="value">--- </td
>
441 <td
class="value">--- </td
>
444 <th
class="name"><?php
echo $strFailedAttempts; ?
></th
>
445 <td
class="value"><?php
echo
446 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?
></td
>
447 <td
class="value"><?php
echo
448 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
450 <td
class="value"><?php
echo
451 $server_status['Connections'] > 0
453 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
458 <th
class="name"><?php
echo $strAbortedClients; ?
></th
>
459 <td
class="value"><?php
echo
460 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?
></td
>
461 <td
class="value"><?php
echo
462 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
464 <td
class="value"><?php
echo
465 $server_status['Connections'] > 0
467 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
472 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
473 <td
class="value"><?php
echo
474 PMA_formatNumber($server_status['Connections'], 4, 0); ?
></td
>
475 <td
class="value"><?php
echo
476 PMA_formatNumber($server_status['Connections'] * $hour_factor,
478 <td
class="value"><?php
echo
479 PMA_formatNumber(100, 0, 2); ?
>%
</td
>
484 <hr
class="clearfloat" />
487 sprintf($strQueryStatistics,
488 PMA_formatNumber($server_status['Questions'], 0)); ?
></h3
>
490 <table id
="serverstatusqueriessummary" class="data">
493 <th
><?php
echo $strTotalUC; ?
></th
>
494 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
495 <th
>ø
; <?php
echo $strPerMinute; ?
></th
>
496 <th
>ø
; <?php
echo $strPerSecond; ?
></th
>
501 <td
class="value"><?php
echo
502 PMA_formatNumber($server_status['Questions'], 4, 0); ?
></td
>
503 <td
class="value"><?php
echo
504 PMA_formatNumber($server_status['Questions'] * $hour_factor,
506 <td
class="value"><?php
echo
508 $server_status['Questions'] * 60 / $server_status['Uptime'],
510 <td
class="value"><?php
echo
512 $server_status['Questions'] / $server_status['Uptime'],
518 <div id
="serverstatusqueriesdetails">
521 $used_queries = $sections['com']['vars'];
522 // reverse sort by value to show most used statements first
523 arsort($used_queries);
524 // remove all zero values from the end
525 while (end($used_queries) == 0) {
526 array_pop($used_queries);
529 // number of tables to split values into
531 $max_rows_per_table = (int) ceil(count($used_queries) / $tables);
534 $count_displayed_rows = 0;
535 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
537 foreach ($used_queries as $name => $value) {
539 if ($count_displayed_rows === 0 ||
$count_displayed_rows === $max_rows_per_table) {
541 if ($count_displayed_rows === $max_rows_per_table) {
542 echo ' </tbody>' . "\n";
543 echo ' </table>' . "\n";
544 $count_displayed_rows = 0;
547 <table id
="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
548 <col
class="namecol" />
549 <col
class="valuecol" span
="3" />
551 <tr
><th colspan
="2"><?php
echo $strQueryType; ?
></th
>
552 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
559 $odd_row = !$odd_row;
561 $count_displayed_rows++
;
563 // For the percentage column, use Questions - Connections, because
564 // the number of connections is not an item of the Query types
565 // but is included in Questions. Then the total of the percentages is 100.
566 $name = str_replace('Com_', '', $name);
567 $name = str_replace('_', ' ', $name);
569 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
570 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
571 <td
class="value"><?php
echo PMA_formatNumber($value, 4, 0); ?
></td
>
572 <td
class="value"><?php
echo
573 PMA_formatNumber($value * $hour_factor, 4, 2); ?
></td
>
574 <td
class="value"><?php
echo
575 PMA_formatNumber($value * $perc_factor, 0, 2); ?
>%
</td
>
584 <div id
="serverstatussection">
586 //Unset used variables
588 $tables, $max_rows_per_table, $current_table, $count_displayed_rows, $perc_factor,
589 $hour_factor, $sections['com'],
590 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
591 $server_status['Max_used_connections'], $server_status['Bytes_received'],
592 $server_status['Bytes_sent'], $server_status['Connections'],
593 $server_status['Questions'], $server_status['Uptime'],
597 foreach ($sections as $section_name => $section) {
598 if (! empty($section['vars'])) {
600 <table
class="data" id
="serverstatussection<?php echo $section_name; ?>">
601 <caption
class="tblHeaders">
603 href
="<?php echo $PMA_PHP_SELF . '?' .
604 PMA_generate_common_url() . '#serverstatus'; ?>"
605 name
="<?php echo $section_name; ?>"><?php
echo $strPos1; ?
>
607 ($GLOBALS['cfg']['MainPageIconic']
608 ?
'<img src="' . $GLOBALS['pmaThemeImage'] .
609 's_asc.png" width="11" height="9" align="middle" alt="" />'
613 if (! empty($section['title'])) {
614 echo $section['title'];
618 <col
class="namecol" />
619 <col
class="valuecol" />
620 <col
class="descrcol" />
623 <th
><?php
echo $strVar; ?
></th
>
624 <th
><?php
echo $strValue; ?
></th
>
625 <th
><?php
echo $strDescription; ?
></th
>
629 if (! empty($links[$section_name])) {
632 <tr
class="tblFooters">
633 <th colspan
="3" class="tblFooters">
635 foreach ($links[$section_name] as $link_name => $link_url) {
636 if ('doc' == $link_name) {
637 echo PMA_showMySQLDocu($link_url, $link_url);
639 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
642 unset($link_url, $link_name);
653 foreach ($section['vars'] as $name => $value) {
654 $odd_row = !$odd_row;
656 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
657 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
658 <td
class="value"><?php
659 if (isset($alerts[$name])) {
660 if ($value > $alerts[$name]) {
661 echo '<span class="attention">';
663 echo '<span class="allfine">';
666 if ('%' === substr($name, -1, 1)) {
667 echo PMA_formatNumber($value, 0, 2) . ' %';
668 } elseif (is_numeric($value) && $value == (int) $value) {
669 echo PMA_formatNumber($value, 4, 0);
670 } elseif (is_numeric($value)) {
671 echo PMA_formatNumber($value, 4, 2);
673 echo htmlspecialchars($value);
675 if (isset($alerts[$name])) {
681 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
682 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
685 if (isset($links[$name])) {
686 foreach ($links[$name] as $link_name => $link_url) {
687 if ('doc' == $link_name) {
688 echo PMA_showMySQLDocu($link_url, $link_url);
690 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
694 unset($link_url, $link_name);
701 unset($name, $value);
708 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
712 /* if the server works as master or slave in replication process, display useful information */
713 if ($server_master_status ||
$server_slave_status)
716 <hr
class="clearfloat" />
718 <h3
><a name
="replication"></a
><?php
echo $strReplicationStatus; ?
></h3
>
721 foreach ($replication_types as $type)
723 if ($
{"server_{$type}_status"}) {
724 PMA_replication_print_status_table($type);
737 require_once './libraries/footer.inc.php';