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',
209 'Handler_' => 'handler',
210 'Qcache_' => 'qcache',
211 'Threads_' => 'threads',
212 'Slow_launch_threads' => 'threads',
214 'Binlog_cache_' => 'binlog_cache',
215 'Created_tmp_' => 'created_tmp',
218 'Delayed_' => 'delayed',
219 'Not_flushed_delayed_rows' => 'delayed',
221 'Flush_commands' => 'query',
222 'Last_query_cost' => 'query',
223 'Slow_queries' => 'query',
225 'Select_' => 'select',
228 'Open_tables' => 'table',
229 'Opened_tables' => 'table',
230 'Table_locks_' => 'table',
232 'Rpl_status' => 'repl',
241 // section => section name (description)
242 'com' => array('title' => ''),
243 'query' => array('title' => $strSQLQuery),
244 'innodb' => array('title' => 'InnoDB'),
245 'ndb' => array('title' => 'NDB'),
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),
258 'ssl' => array('title' => 'SSL'),
262 * define some needfull links/commands
264 // variable or section name => (name => url)
267 $links['table'][$strFlushTables]
268 = $PMA_PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
269 $links['table'][$strShowOpenTables]
270 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
271 '&goto=server_status.php&' . PMA_generate_common_url();
273 if ($server_master_status) {
274 $links['repl'][$strShowSlaveHosts]
275 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
276 '&goto=server_status.php&' . PMA_generate_common_url();
277 $links['repl'][$strShowMasterStatus] = '#replication_master';
279 if ($server_slave_status) {
280 $links['repl'][$strShowSlaveStatus] = '#replication_slave';
283 $links['repl']['doc'] = 'replication';
285 $links['qcache'][$strFlushQueryCache]
286 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' .
287 PMA_generate_common_url();
288 $links['qcache']['doc'] = 'query_cache';
290 $links['threads'][$strMySQLShowProcess]
291 = 'server_processlist.php?' . PMA_generate_common_url();
292 $links['threads']['doc'] = 'mysql_threads';
294 $links['key']['doc'] = 'myisam_key_cache';
296 $links['binlog_cache']['doc'] = 'binary_log';
298 $links['Slow_queries']['doc'] = 'slow_query_log';
300 $links['innodb'][$strServerTabVariables]
301 = 'server_engines.php?engine=InnoDB&' . PMA_generate_common_url();
302 $links['innodb'][$strInnodbStat]
303 = 'server_engines.php?engine=InnoDB&page=Status&' .
304 PMA_generate_common_url();
305 $links['innodb']['doc'] = 'innodb';
308 // sort status vars into arrays
309 foreach ($server_status as $name => $value) {
310 if (isset($allocations[$name])) {
311 $sections[$allocations[$name]]['vars'][$name] = $value;
312 unset($server_status[$name]);
314 foreach ($allocations as $filter => $section) {
315 if (preg_match('/^' . $filter . '/', $name)
316 && isset($server_status[$name])) {
317 unset($server_status[$name]);
318 $sections[$section]['vars'][$name] = $value;
323 unset($name, $value, $filter, $section, $allocations);
326 $sections['all']['vars'] =& $server_status;
328 $hour_factor = 3600 / $server_status['Uptime'];
334 <div id
="statuslinks">
336 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
337 ><?php
echo $strRefresh; ?
></a
>
339 $PMA_PHP_SELF . '?flush=STATUS&' . PMA_generate_common_url(); ?>"
340 ><?php
echo $strShowStatusReset; ?
></a
>
341 <?php
echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?
>
346 echo sprintf($strServerStatusUptime,
347 PMA_timespanFormat($server_status['Uptime']),
348 PMA_localisedDate($start_time)) . "\n";
353 if ($server_master_status ||
$server_slave_status)
355 $replicationOut = "";
356 foreach ($replication_types as $type)
358 if ($
{"server_{$type}_status"})
360 if ($replicationOut != "")
361 $replicationOut .= $strAndSmall . ' ';
362 $replicationOut .= '<b>' . $type . '</b> ';
365 echo sprintf('<p>' . $strReplicationStatusInfo . '</p>', $replicationOut);
369 <div id
="sectionlinks">
371 foreach ($sections as $section_name => $section) {
372 if (! empty($section['vars']) && ! empty($section['title'])) {
373 echo '<a href="' . $PMA_PHP_SELF . '?' .
374 PMA_generate_common_url() . '#' . $section_name . '">' .
375 $section['title'] . '</a>' . "\n";
381 <h3
><?php
echo $strServerTrafficNotes; ?
></h3
>
383 <table id
="serverstatustraffic" class="data">
386 <th colspan
="2"><?php
echo $strTraffic . ' ' . PMA_showHint($strStatisticsOverrun); ?
></th
>
387 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
392 <th
class="name"><?php
echo $strReceived; ?
></th
>
393 <td
class="value"><?php
echo
395 PMA_formatByteDown($server_status['Bytes_received'], 2, 1)); ?
></td
>
396 <td
class="value"><?php
echo
399 $server_status['Bytes_received'] * $hour_factor, 2, 1)); ?
></td
>
402 <th
class="name"><?php
echo $strSent; ?
></th
>
403 <td
class="value"><?php
echo
405 PMA_formatByteDown($server_status['Bytes_sent'], 2, 1)); ?
></td
>
406 <td
class="value"><?php
echo
409 $server_status['Bytes_sent'] * $hour_factor, 2, 1)); ?
></td
>
412 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
413 <td
class="value"><?php
echo
416 $server_status['Bytes_received'] +
$server_status['Bytes_sent'], 2, 1)
418 <td
class="value"><?php
echo
421 ($server_status['Bytes_received'] +
$server_status['Bytes_sent'])
422 * $hour_factor, 2, 1)
428 <table id
="serverstatusconnections" class="data">
431 <th colspan
="2"><?php
echo $strConnections; ?
></th
>
432 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
438 <th
class="name"><?php
echo $strMaxConnects; ?
></th
>
439 <td
class="value"><?php
echo
440 PMA_formatNumber($server_status['Max_used_connections'], 0); ?
> </td
>
441 <td
class="value">--- </td
>
442 <td
class="value">--- </td
>
445 <th
class="name"><?php
echo $strFailedAttempts; ?
></th
>
446 <td
class="value"><?php
echo
447 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?
></td
>
448 <td
class="value"><?php
echo
449 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
451 <td
class="value"><?php
echo
452 $server_status['Connections'] > 0
454 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
459 <th
class="name"><?php
echo $strAbortedClients; ?
></th
>
460 <td
class="value"><?php
echo
461 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?
></td
>
462 <td
class="value"><?php
echo
463 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
465 <td
class="value"><?php
echo
466 $server_status['Connections'] > 0
468 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
473 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
474 <td
class="value"><?php
echo
475 PMA_formatNumber($server_status['Connections'], 4, 0); ?
></td
>
476 <td
class="value"><?php
echo
477 PMA_formatNumber($server_status['Connections'] * $hour_factor,
479 <td
class="value"><?php
echo
480 PMA_formatNumber(100, 0, 2); ?
>%
</td
>
485 <hr
class="clearfloat" />
488 sprintf($strQueryStatistics,
489 PMA_formatNumber($server_status['Questions'], 0)); ?
></h3
>
491 <table id
="serverstatusqueriessummary" class="data">
494 <th
><?php
echo $strTotalUC; ?
></th
>
495 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
496 <th
>ø
; <?php
echo $strPerMinute; ?
></th
>
497 <th
>ø
; <?php
echo $strPerSecond; ?
></th
>
502 <td
class="value"><?php
echo
503 PMA_formatNumber($server_status['Questions'], 4, 0); ?
></td
>
504 <td
class="value"><?php
echo
505 PMA_formatNumber($server_status['Questions'] * $hour_factor,
507 <td
class="value"><?php
echo
509 $server_status['Questions'] * 60 / $server_status['Uptime'],
511 <td
class="value"><?php
echo
513 $server_status['Questions'] / $server_status['Uptime'],
519 <div id
="serverstatusqueriesdetails">
522 $used_queries = $sections['com']['vars'];
523 // reverse sort by value to show most used statements first
524 arsort($used_queries);
525 // remove all zero values from the end
526 while (end($used_queries) == 0) {
527 array_pop($used_queries);
530 // number of tables to split values into
532 $max_rows_per_table = (int) ceil(count($used_queries) / $tables);
535 $count_displayed_rows = 0;
536 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
538 foreach ($used_queries as $name => $value) {
540 if ($count_displayed_rows === 0 ||
$count_displayed_rows === $max_rows_per_table) {
542 if ($count_displayed_rows === $max_rows_per_table) {
543 echo ' </tbody>' . "\n";
544 echo ' </table>' . "\n";
545 $count_displayed_rows = 0;
548 <table id
="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
549 <col
class="namecol" />
550 <col
class="valuecol" span
="3" />
552 <tr
><th colspan
="2"><?php
echo $strQueryType; ?
></th
>
553 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
560 $odd_row = !$odd_row;
562 $count_displayed_rows++
;
564 // For the percentage column, use Questions - Connections, because
565 // the number of connections is not an item of the Query types
566 // but is included in Questions. Then the total of the percentages is 100.
567 $name = str_replace('Com_', '', $name);
568 $name = str_replace('_', ' ', $name);
570 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
571 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
572 <td
class="value"><?php
echo PMA_formatNumber($value, 4, 0); ?
></td
>
573 <td
class="value"><?php
echo
574 PMA_formatNumber($value * $hour_factor, 3, 3); ?
></td
>
575 <td
class="value"><?php
echo
576 PMA_formatNumber($value * $perc_factor, 0, 2); ?
>%
</td
>
585 <div id
="serverstatussection">
587 //Unset used variables
589 $tables, $max_rows_per_table, $current_table, $count_displayed_rows, $perc_factor,
590 $hour_factor, $sections['com'],
591 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
592 $server_status['Max_used_connections'], $server_status['Bytes_received'],
593 $server_status['Bytes_sent'], $server_status['Connections'],
594 $server_status['Questions'], $server_status['Uptime'],
598 foreach ($sections as $section_name => $section) {
599 if (! empty($section['vars'])) {
601 <table
class="data" id
="serverstatussection<?php echo $section_name; ?>">
602 <caption
class="tblHeaders">
604 href
="<?php echo $PMA_PHP_SELF . '?' .
605 PMA_generate_common_url() . '#serverstatus'; ?>"
606 name
="<?php echo $section_name; ?>"><?php
echo $strPos1; ?
>
608 ($GLOBALS['cfg']['MainPageIconic']
609 ?
'<img src="' . $GLOBALS['pmaThemeImage'] .
610 's_asc.png" width="11" height="9" align="middle" alt="" />'
614 if (! empty($section['title'])) {
615 echo $section['title'];
619 <col
class="namecol" />
620 <col
class="valuecol" />
621 <col
class="descrcol" />
624 <th
><?php
echo $strVar; ?
></th
>
625 <th
><?php
echo $strValue; ?
></th
>
626 <th
><?php
echo $strDescription; ?
></th
>
630 if (! empty($links[$section_name])) {
633 <tr
class="tblFooters">
634 <th colspan
="3" class="tblFooters">
636 foreach ($links[$section_name] as $link_name => $link_url) {
637 if ('doc' == $link_name) {
638 echo PMA_showMySQLDocu($link_url, $link_url);
640 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
643 unset($link_url, $link_name);
654 foreach ($section['vars'] as $name => $value) {
655 $odd_row = !$odd_row;
657 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
658 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
659 <td
class="value"><?php
660 if (isset($alerts[$name])) {
661 if ($value > $alerts[$name]) {
662 echo '<span class="attention">';
664 echo '<span class="allfine">';
667 if ('%' === substr($name, -1, 1)) {
668 echo PMA_formatNumber($value, 0, 2) . ' %';
669 } elseif (is_numeric($value) && $value == (int) $value) {
670 echo PMA_formatNumber($value, 3, 1);
671 } elseif (is_numeric($value)) {
672 echo PMA_formatNumber($value, 3, 1);
674 echo htmlspecialchars($value);
676 if (isset($alerts[$name])) {
682 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
683 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
686 if (isset($links[$name])) {
687 foreach ($links[$name] as $link_name => $link_url) {
688 if ('doc' == $link_name) {
689 echo PMA_showMySQLDocu($link_url, $link_url);
691 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
695 unset($link_url, $link_name);
702 unset($name, $value);
709 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
713 /* if the server works as master or slave in replication process, display useful information */
714 if ($server_master_status ||
$server_slave_status)
717 <hr
class="clearfloat" />
719 <h3
><a name
="replication"></a
><?php
echo $strReplicationStatus; ?
></h3
>
722 foreach ($replication_types as $type)
724 if ($
{"server_{$type}_status"}) {
725 PMA_replication_print_status_table($type);
738 require_once './libraries/footer.inc.php';