3 // vim: expandtab sw=4 ts=4 sts=4:
5 * displays status variables with descriptions and some hints an optmizing
6 * + reset status variables
8 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
9 define('PMA_NO_VARIABLES_IMPORT', true);
11 require_once './libraries/common.lib.php';
14 * Does the common work
16 require './libraries/server_common.inc.php';
22 require './libraries/server_links.inc.php';
26 * Displays the sub-page heading
28 echo '<div id="serverstatus">' . "\n";
30 . ($GLOBALS['cfg']['MainPageIconic']
31 ?
'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
32 's_status.png" width="16" height="16" alt="" />'
34 . $strServerStatus . "\n"
39 * flush status variables if requested
41 if (isset($_REQUEST['flush'])) {
42 $_flush_commands = array(
48 if (in_array($_REQUEST['flush'], $_flush_commands)) {
49 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
51 unset($_flush_commands);
56 * get status from server
58 if (PMA_MYSQL_INT_VERSION
>= 50002) {
59 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
61 $server_status = PMA_DBI_fetch_result('SHOW STATUS', 0, 1);
66 * for some calculations we require also some server settings
68 if (PMA_MYSQL_INT_VERSION
>= 40003) {
69 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
71 $server_variables = PMA_DBI_fetch_result('SHOW VARIABLES', 0, 1);
76 * starttime calculation
78 $start_time = PMA_DBI_fetch_value(
79 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
83 * cleanup some deprecated values
86 'Com_prepare_sql' => 'Com_stmt_prepare',
87 'Com_execute_sql' => 'Com_stmt_execute',
88 'Com_dealloc_sql' => 'Com_stmt_close',
91 foreach ($deprecated as $old => $new) {
92 if (isset($server_status[$old])
93 && isset($server_status[$new])) {
94 unset($server_status[$old]);
101 * calculate some values
103 // Key_buffer_fraction
104 if (isset($server_status['Key_blocks_unused'])
105 && isset($server_variables['key_cache_block_size'])
106 && isset($server_variables['key_buffer_size'])) {
107 $server_status['Key_buffer_fraction_%'] =
109 - $server_status['Key_blocks_unused']
110 * $server_variables['key_cache_block_size']
111 / $server_variables['key_buffer_size']
114 isset($server_status['Key_blocks_used'])
115 && isset($server_variables['key_buffer_size'])) {
116 $server_status['Key_buffer_fraction_%'] =
117 $server_status['Key_blocks_used']
119 / $server_variables['key_buffer_size'];
122 // Ratio for key read/write
123 if (isset($server_status['Key_writes'])
124 && isset($server_status['Key_write_requests'])
125 && $server_status['Key_write_requests'] > 0)
126 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
128 if (isset($server_status['Key_reads'])
129 && isset($server_status['Key_read_requests'])
130 && $server_status['Key_read_requests'] > 0)
131 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
133 // Threads_cache_hitrate
134 if (isset($server_status['Threads_created'])
135 && isset($server_status['Connections'])
136 && $server_status['Connections'] > 0) {
137 $server_status['Threads_cache_hitrate_%'] =
139 - $server_status['Threads_created']
140 / $server_status['Connections']
148 // name => max value before alert
151 // variable => max value
152 'Aborted_clients' => 0,
153 'Aborted_connects' => 0,
155 'Binlog_cache_disk_use' => 0,
157 'Created_tmp_disk_tables' => 0,
159 'Handler_read_rnd' => 0,
160 'Handler_read_rnd_next' => 0,
162 'Innodb_buffer_pool_pages_dirty' => 0,
163 'Innodb_buffer_pool_reads' => 0,
164 'Innodb_buffer_pool_wait_free' => 0,
165 'Innodb_log_waits' => 0,
166 'Innodb_row_lock_time_avg' => 10, // ms
167 'Innodb_row_lock_time_max' => 50, // ms
168 'Innodb_row_lock_waits' => 0,
171 'Delayed_errors' => 0,
172 'Select_full_join' => 0,
173 'Select_range_check' => 0,
174 'Sort_merge_passes' => 0,
175 'Opened_tables' => 0,
176 'Table_locks_waited' => 0,
177 'Qcache_lowmem_prunes' => 0,
178 'Slow_launch_threads' => 0,
180 // depends on Key_read_requests
181 // normaly lower then 1:0.01
182 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
183 // depends on Key_write_requests
184 // normaly nearly 1:1
185 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
187 'Key_buffer_fraction' => 0.5,
189 // alert if more than 95% of thread cache is in use
190 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
193 // variable => min value
194 //'Handler read key' => '> ',
199 * split variables in sections
201 $allocations = array(
202 // variable name => section
205 'Innodb_' => 'innodb',
208 'Handler_' => 'handler',
209 'Qcache_' => 'qcache',
210 'Threads_' => 'threads',
211 'Slow_launch_threads' => 'threads',
213 'Binlog_cache_' => 'binlog_cache',
214 'Created_tmp_' => 'created_tmp',
217 'Delayed_' => 'delayed',
218 'Not_flushed_delayed_rows' => 'delayed',
220 'Flush_commands' => 'query',
221 'Last_query_cost' => 'query',
222 'Slow_queries' => 'query',
224 'Select_' => 'select',
227 'Open_tables' => 'table',
228 'Opened_tables' => 'table',
229 'Table_locks_' => 'table',
231 'Rpl_status' => 'repl',
238 // section => section name (description)
239 'com' => array('title' => ''),
240 'query' => array('title' => ''),
241 'innodb' => array('title' => 'InnoDB'),
242 'ndb' => array('title' => 'NDB'),
243 'ssl' => array('title' => 'SSL'),
244 'handler' => array('title' => $strHandler),
245 'qcache' => array('title' => $strQueryCache),
246 'threads' => array('title' => $strThreads),
247 'binlog_cache' => array('title' => $strBinaryLog),
248 'created_tmp' => array('title' => $strTempData),
249 'delayed' => array('title' => $strServerStatusDelayedInserts),
250 'key' => array('title' => $strKeyCache),
251 'select' => array('title' => $strJoins),
252 'repl' => array('title' => $strReplication),
253 'sort' => array('title' => $strSorting),
254 'table' => array('title' => $strNumTables),
255 'tc' => array('title' => $strTransactionCoordinator),
260 * define some needfull links/commands
262 // variable or section name => (name => url)
265 $links['table'][$strFlushTables]
266 = $PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
267 $links['table'][$strShowOpenTables]
268 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
269 '&goto=server_status.php&' . PMA_generate_common_url();
271 $links['repl'][$strShowSlaveHosts]
272 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
273 '&goto=server_status.php&' . PMA_generate_common_url();
274 $links['repl'][$strShowSlaveStatus]
275 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
276 '&goto=server_status.php&' . PMA_generate_common_url();
277 $links['repl']['MySQL - ' . $strDocu]
278 = $cfg['MySQLManualBase'] . '/replication.html';
280 $links['qcache'][$strFlushQueryCache]
281 = $PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' .
282 PMA_generate_common_url();
283 $links['qcache']['MySQL - ' . $strDocu]
284 = $cfg['MySQLManualBase'] . '/query-cache.html';
286 $links['threads'][$strMySQLShowProcess]
287 = 'server_processlist.php?' . PMA_generate_common_url();
288 $links['threads']['MySQL - ' . $strDocu]
289 = $cfg['MySQLManualBase'] . '/mysql-threads.html';
291 $links['key']['MySQL - ' . $strDocu]
292 = $cfg['MySQLManualBase'] . '/myisam-key-cache.html';
294 $links['slow_queries']['MySQL - ' . $strDocu]
295 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
297 $links['binlog_cache']['MySQL - ' . $strDocu]
298 = $cfg['MySQLManualBase'] . '/binary-log.html';
300 $links['Slow_queries']['MySQL - ' . $strDocu]
301 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
303 $links['innodb'][$strServerTabVariables]
304 = 'server_engines.php?engine=innodb&' . PMA_generate_common_url();
305 $links['innodb'][$strInnodbStat]
306 = 'server_engines.php?engine=innodb&page=status&' .
307 PMA_generate_common_url();
308 $links['innodb']['MySQL - ' . $strDocu]
309 = $cfg['MySQLManualBase'] . '/innodb.html';
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 $PHP_SELF . '?' . PMA_generate_common_url(); ?>"
341 ><?php
echo $strRefresh; ?
></a
>
343 $PHP_SELF . '?flush=STATUS&' . PMA_generate_common_url(); ?>"
344 ><?php
echo $strShowStatusReset; ?
></a
>
346 $cfg['MySQLManualBase']; ?>/server-status-variables.html"
347 target
="documentation">MySQL
- <?php
echo $strDocu; ?
></a
>
352 echo sprintf($strServerStatusUptime,
353 PMA_timespanFormat($server_status['Uptime']),
354 PMA_localisedDate($start_time)) . "\n";
358 <div id
="sectionlinks">
360 foreach ($sections as $section_name => $section) {
361 if (! empty($section['vars']) && ! empty($section['title'])) {
362 echo '<a href="' . $PHP_SELF . '?' .
363 PMA_generate_common_url() . '#' . $section_name . '">' .
364 $section['title'] . '</a>' . "\n";
370 <h3
><?php
echo $strServerTrafficNotes; ?
></h3
>
372 <table id
="serverstatustraffic" class="data">
375 <th colspan
="2"><?php
echo $strTraffic . ' ' . PMA_showHint($strStatisticsOverrun); ?
></th
>
376 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
381 <th
class="name"><?php
echo $strReceived; ?
></th
>
382 <td
class="value"><?php
echo
384 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?
></td
>
385 <td
class="value"><?php
echo
388 $server_status['Bytes_received'] * $hour_factor, 4)); ?
></td
>
391 <th
class="name"><?php
echo $strSent; ?
></th
>
392 <td
class="value"><?php
echo
394 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?
></td
>
395 <td
class="value"><?php
echo
398 $server_status['Bytes_sent'] * $hour_factor, 4)); ?
></td
>
401 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
402 <td
class="value"><?php
echo
405 $server_status['Bytes_received'] +
$server_status['Bytes_sent'], 4)
407 <td
class="value"><?php
echo
410 ($server_status['Bytes_received'] +
$server_status['Bytes_sent'])
417 <table id
="serverstatusconnections" class="data">
420 <th colspan
="2"><?php
echo $strConnections; ?
></th
>
421 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
427 <th
class="name"><?php
echo $strMaxConnects; ?
></th
>
428 <td
class="value"><?php
echo
429 PMA_formatNumber($server_status['Max_used_connections'], 0); ?
> </td
>
430 <td
class="value">--- </td
>
431 <td
class="value">--- </td
>
434 <th
class="name"><?php
echo $strFailedAttempts; ?
></th
>
435 <td
class="value"><?php
echo
436 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?
></td
>
437 <td
class="value"><?php
echo
438 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
440 <td
class="value"><?php
echo
441 $server_status['Connections'] > 0
443 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
448 <th
class="name"><?php
echo $strAbortedClients; ?
></th
>
449 <td
class="value"><?php
echo
450 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?
></td
>
451 <td
class="value"><?php
echo
452 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
454 <td
class="value"><?php
echo
455 $server_status['Connections'] > 0
457 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
462 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
463 <td
class="value"><?php
echo
464 PMA_formatNumber($server_status['Connections'], 4, 0); ?
></td
>
465 <td
class="value"><?php
echo
466 PMA_formatNumber($server_status['Connections'] * $hour_factor,
468 <td
class="value"><?php
echo
469 PMA_formatNumber(100, 0, 2); ?
>%
</td
>
474 <hr
class="clearfloat" />
477 sprintf($strQueryStatistics,
478 PMA_formatNumber($server_status['Questions'], 0)); ?
></h3
>
480 <table id
="serverstatusqueriessummary" class="data">
483 <th
><?php
echo $strTotalUC; ?
></th
>
484 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
485 <th
>ø
; <?php
echo $strPerMinute; ?
></th
>
486 <th
>ø
; <?php
echo $strPerSecond; ?
></th
>
491 <td
class="value"><?php
echo
492 PMA_formatNumber($server_status['Questions'], 4, 0); ?
></td
>
493 <td
class="value"><?php
echo
494 PMA_formatNumber($server_status['Questions'] * $hour_factor,
496 <td
class="value"><?php
echo
498 $server_status['Questions'] * 60 / $server_status['Uptime'],
500 <td
class="value"><?php
echo
502 $server_status['Questions'] / $server_status['Uptime'],
508 <div id
="serverstatusqueriesdetails">
510 // number of tables to split values into
512 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
516 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
517 foreach ($sections['com']['vars'] as $name => $value) {
519 if ($countRows === 0 ||
$countRows === $rows_per_table) {
521 if ($countRows === $rows_per_table) {
522 echo ' </tbody>' . "\n";
523 echo ' </table>' . "\n";
526 <table id
="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
527 <col
class="namecol" />
528 <col
class="valuecol" span
="3" />
530 <tr
><th colspan
="2"><?php
echo $strQueryType; ?
></th
>
531 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
538 $odd_row = !$odd_row;
542 // For the percentage column, use Questions - Connections, because
543 // the number of connections is not an item of the Query types
544 // but is included in Questions. Then the total of the percentages is 100.
545 $name = str_replace('Com_', '', $name);
546 $name = str_replace('_', ' ', $name);
548 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
549 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
550 <td
class="value"><?php
echo PMA_formatNumber($value, 4, 0); ?
></td
>
551 <td
class="value"><?php
echo
552 PMA_formatNumber($value * $hour_factor, 4, 2); ?
></td
>
553 <td
class="value"><?php
echo
554 PMA_formatNumber($value * $perc_factor, 0, 2); ?
>%
</td
>
563 <div id
="serverstatussection">
565 //Unset used variables
567 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
568 $hour_factor, $sections['com'],
569 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
570 $server_status['Max_used_connections'], $server_status['Bytes_received'],
571 $server_status['Bytes_sent'], $server_status['Connections'],
572 $server_status['Questions'], $server_status['Uptime']
575 foreach ($sections as $section_name => $section) {
576 if (! empty($section['vars'])) {
578 <table
class="data" id
="serverstatussection<?php echo $section_name; ?>">
579 <caption
class="tblHeaders">
581 href
="<?php echo $PHP_SELF . '?' .
582 PMA_generate_common_url() . '#serverstatus'; ?>"
583 name
="<?php echo $section_name; ?>"><?php
echo $strPos1; ?
>
585 ($GLOBALS['cfg']['MainPageIconic']
586 ?
'<img src="' . $GLOBALS['pmaThemeImage'] .
587 's_asc.png" width="11" height="9" align="middle" alt="" />'
591 if (! empty($section['title'])) {
592 echo $section['title'];
596 <col
class="namecol" />
597 <col
class="valuecol" />
598 <col
class="descrcol" />
601 <th
><?php
echo $strVar; ?
></th
>
602 <th
><?php
echo $strValue; ?
></th
>
603 <th
><?php
echo $strDescription; ?
></th
>
607 if (! empty($links[$section_name])) {
610 <tr
class="tblFooters">
611 <th colspan
="3" class="tblFooters">
613 foreach ($links[$section_name] as $link_name => $link_url) {
614 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
616 unset($link_url, $link_name);
627 foreach ($section['vars'] as $name => $value) {
628 $odd_row = !$odd_row;
630 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
631 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
632 <td
class="value"><?php
633 if (isset($alerts[$name])) {
634 if ($value > $alerts[$name]) {
635 echo '<span class="attention">';
637 echo '<span class="allfine">';
640 if ('%' === substr($name, -1, 1)) {
641 echo PMA_formatNumber($value, 0, 2) . ' %';
642 } elseif (is_numeric($value) && $value == (int) $value) {
643 echo PMA_formatNumber($value, 4, 0);
644 } elseif (is_numeric($value)) {
645 echo PMA_formatNumber($value, 4, 2);
647 echo htmlspecialchars($value);
649 if (isset($alerts[$name])) {
655 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
656 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
659 if (isset($links[$name])) {
660 foreach ($links[$name] as $link_name => $link_url) {
661 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
664 unset($link_url, $link_name);
671 unset($name, $value);
678 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
688 require_once './libraries/footer.inc.php';