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'];
121 // Threads_cache_hitrate
122 if (isset($server_status['Threads_created'])
123 && isset($server_status['Connections'])) {
124 $server_status['Threads_cache_hitrate_%'] =
126 - $server_status['Threads_created']
127 / $server_status['Connections']
135 // name => max value before alert
138 // variable => max value
139 'Aborted_clients' => 0,
140 'Aborted_connects' => 0,
142 'Binlog_cache_disk_use' => 0,
144 'Created_tmp_disk_tables' => 0,
146 'Handler_read_rnd' => 0,
147 'Handler_read_rnd_next' => 0,
149 'Innodb_buffer_pool_pages_dirty' => 0,
150 'Innodb_buffer_pool_reads' => 0,
151 'Innodb_buffer_pool_wait_free' => 0,
152 'Innodb_log_waits' => 0,
153 'Innodb_row_lock_time_avg' => 10, // ms
154 'Innodb_row_lock_time_max' => 50, // ms
155 'Innodb_row_lock_waits' => 0,
158 'Delayed_errors' => 0,
159 'Select_full_join' => 0,
160 'Select_range_check' => 0,
161 'Sort_merge_passes' => 0,
162 'Opened_tables' => 0,
163 'Table_locks_waited' => 0,
164 'Qcache_lowmem_prunes' => 0,
165 'Slow_launch_threads' => 0,
167 // depends on Key_read_requests
168 // normaly lower then 1:0.01
169 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
170 // depends on Key_write_requests
171 // normaly nearly 1:1
172 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
174 'Key_buffer_fraction' => 0.5,
176 // alert if more than 95% of thread cache is in use
177 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
180 // variable => min value
181 //'Handler read key' => '> ',
186 * split variables in sections
188 $allocations = array(
189 // variable name => section
192 'Innodb_' => 'innodb',
195 'Handler_' => 'handler',
196 'Qcache_' => 'qcache',
197 'Threads_' => 'threads',
198 'Slow_launch_threads' => 'threads',
200 'Binlog_cache_' => 'binlog_cache',
201 'Created_tmp_' => 'created_tmp',
204 'Delayed_' => 'delayed',
205 'Not_flushed_delayed_rows' => 'delayed',
207 'Flush_commands' => 'query',
208 'Last_query_cost' => 'query',
209 'Slow_queries' => 'query',
211 'Select_' => 'select',
214 'Open_tables' => 'table',
215 'Opened_tables' => 'table',
216 'Table_locks_' => 'table',
218 'Rpl_status' => 'repl',
225 // section => section name (description)
226 'com' => array('title' => ''),
227 'query' => array('title' => ''),
228 'innodb' => array('title' => 'InnoDB'),
229 'ndb' => array('title' => 'NDB'),
230 'ssl' => array('title' => 'SSL'),
231 'handler' => array('title' => $strHandler),
232 'qcache' => array('title' => $strQueryCache),
233 'threads' => array('title' => $strThreads),
234 'binlog_cache' => array('title' => $strBinaryLog),
235 'created_tmp' => array('title' => $strTempData),
236 'delayed' => array('title' => $strServerStatusDelayedInserts),
237 'key' => array('title' => $strKeyCache),
238 'select' => array('title' => $strJoins),
239 'repl' => array('title' => $strReplication),
240 'sort' => array('title' => $strSorting),
241 'table' => array('title' => $strNumTables),
242 'tc' => array('title' => $strTransactionCoordinator),
247 * define some needfull links/commands
249 // variable or section name => (name => url)
252 $links['table'][$strFlushTables]
253 = $PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
254 $links['table'][$strShowOpenTables]
255 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
256 '&goto=server_status.php&' . PMA_generate_common_url();
258 $links['repl'][$strShowSlaveHosts]
259 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
260 '&goto=server_status.php&' . PMA_generate_common_url();
261 $links['repl'][$strShowSlaveStatus]
262 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
263 '&goto=server_status.php&' . PMA_generate_common_url();
264 $links['repl']['MySQL - ' . $strDocu]
265 = $cfg['MySQLManualBase'] . '/replication.html';
267 $links['qcache'][$strFlushQueryCache]
268 = $PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' .
269 PMA_generate_common_url();
270 $links['qcache']['MySQL - ' . $strDocu]
271 = $cfg['MySQLManualBase'] . '/query-cache.html';
273 $links['threads'][$strMySQLShowProcess]
274 = 'server_processlist.php?' . PMA_generate_common_url();
275 $links['threads']['MySQL - ' . $strDocu]
276 = $cfg['MySQLManualBase'] . '/mysql-threads.html';
278 $links['key']['MySQL - ' . $strDocu]
279 = $cfg['MySQLManualBase'] . '/myisam-key-cache.html';
281 $links['slow_queries']['MySQL - ' . $strDocu]
282 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
284 $links['binlog_cache']['MySQL - ' . $strDocu]
285 = $cfg['MySQLManualBase'] . '/binary-log.html';
287 $links['Slow_queries']['MySQL - ' . $strDocu]
288 = $cfg['MySQLManualBase'] . '/slow-query-log.html';
290 $links['innodb'][$strServerTabVariables]
291 = 'server_engines.php?engine=innodb&' . PMA_generate_common_url();
292 $links['innodb'][$strInnodbStat]
293 = 'server_engines.php?engine=innodb&page=status&' .
294 PMA_generate_common_url();
295 $links['innodb']['MySQL - ' . $strDocu]
296 = $cfg['MySQLManualBase'] . '/innodb.html';
299 // sort status vars into arrays
300 foreach ($server_status as $name => $value) {
301 if (isset($allocations[$name])) {
302 $sections[$allocations[$name]]['vars'][$name] = $value;
303 unset($server_status[$name]);
305 foreach ($allocations as $filter => $section) {
306 if (preg_match('/^' . $filter . '/', $name)
307 && isset($server_status[$name])) {
308 unset($server_status[$name]);
309 $sections[$section]['vars'][$name] = $value;
314 unset($name, $value, $filter, $section, $allocations);
317 $sections['all']['vars'] =& $server_status;
319 $hour_factor = 3600 / $server_status['Uptime'];
325 <div id
="statuslinks">
327 $PHP_SELF . '?' . PMA_generate_common_url(); ?>"
328 ><?php
echo $strRefresh; ?
></a
>
330 $PHP_SELF . '?flush=STATUS&' . PMA_generate_common_url(); ?>"
331 ><?php
echo $strShowStatusReset; ?
></a
>
333 $cfg['MySQLManualBase']; ?>/server-status-variables.html"
334 target
="documentation">MySQL
- <?php
echo $strDocu; ?
></a
>
339 echo sprintf($strServerStatusUptime,
340 PMA_timespanFormat($server_status['Uptime']),
341 PMA_localisedDate($start_time)) . "\n";
345 <div id
="sectionlinks">
347 foreach ($sections as $section_name => $section) {
348 if (! empty($section['vars']) && ! empty($section['title'])) {
349 echo '<a href="' . $PHP_SELF . '?' .
350 PMA_generate_common_url() . '#' . $section_name . '">' .
351 $section['title'] . '</a>' . "\n";
357 <h3
><?php
echo $strServerTrafficNotes; ?
></h3
>
359 <table id
="serverstatustraffic" class="data">
362 <th colspan
="2"><?php
echo $strTraffic . ' ' . PMA_showHint($strStatisticsOverrun); ?
></th
>
363 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
368 <th
class="name"><?php
echo $strReceived; ?
></th
>
369 <td
class="value"><?php
echo
371 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?
></td
>
372 <td
class="value"><?php
echo
375 $server_status['Bytes_received'] * $hour_factor, 4)); ?
></td
>
378 <th
class="name"><?php
echo $strSent; ?
></th
>
379 <td
class="value"><?php
echo
381 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?
></td
>
382 <td
class="value"><?php
echo
385 $server_status['Bytes_sent'] * $hour_factor, 4)); ?
></td
>
388 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
389 <td
class="value"><?php
echo
392 $server_status['Bytes_received'] +
$server_status['Bytes_sent'], 4)
394 <td
class="value"><?php
echo
397 ($server_status['Bytes_received'] +
$server_status['Bytes_sent'])
404 <table id
="serverstatusconnections" class="data">
407 <th colspan
="2"><?php
echo $strConnections; ?
></th
>
408 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
414 <th
class="name"><?php
echo $strMaxConnects; ?
></th
>
415 <td
class="value"><?php
echo
416 PMA_formatNumber($server_status['Max_used_connections'], 0); ?
> </td
>
417 <td
class="value">--- </td
>
418 <td
class="value">--- </td
>
421 <th
class="name"><?php
echo $strFailedAttempts; ?
></th
>
422 <td
class="value"><?php
echo
423 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?
></td
>
424 <td
class="value"><?php
echo
425 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
427 <td
class="value"><?php
echo
428 $server_status['Connections'] > 0
430 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
435 <th
class="name"><?php
echo $strAbortedClients; ?
></th
>
436 <td
class="value"><?php
echo
437 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?
></td
>
438 <td
class="value"><?php
echo
439 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
441 <td
class="value"><?php
echo
442 $server_status['Connections'] > 0
444 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
449 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
450 <td
class="value"><?php
echo
451 PMA_formatNumber($server_status['Connections'], 4, 0); ?
></td
>
452 <td
class="value"><?php
echo
453 PMA_formatNumber($server_status['Connections'] * $hour_factor,
455 <td
class="value"><?php
echo
456 PMA_formatNumber(100, 0, 2); ?
>%
</td
>
461 <hr
class="clearfloat" />
464 sprintf($strQueryStatistics,
465 PMA_formatNumber($server_status['Questions'], 0)); ?
></h3
>
467 <table id
="serverstatusqueriessummary" class="data">
470 <th
><?php
echo $strTotalUC; ?
></th
>
471 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
472 <th
>ø
; <?php
echo $strPerMinute; ?
></th
>
473 <th
>ø
; <?php
echo $strPerSecond; ?
></th
>
478 <td
class="value"><?php
echo
479 PMA_formatNumber($server_status['Questions'], 4, 0); ?
></td
>
480 <td
class="value"><?php
echo
481 PMA_formatNumber($server_status['Questions'] * $hour_factor,
483 <td
class="value"><?php
echo
485 $server_status['Questions'] * 60 / $server_status['Uptime'],
487 <td
class="value"><?php
echo
489 $server_status['Questions'] / $server_status['Uptime'],
495 <div id
="serverstatusqueriesdetails">
497 // number of tables to split values into
499 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
503 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
504 foreach ($sections['com']['vars'] as $name => $value) {
506 if ($countRows === 0 ||
$countRows === $rows_per_table) {
508 if ($countRows === $rows_per_table) {
509 echo ' </tbody>' . "\n";
510 echo ' </table>' . "\n";
513 <table id
="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
514 <col
class="namecol" />
515 <col
class="valuecol" span
="3" />
517 <tr
><th colspan
="2"><?php
echo $strQueryType; ?
></th
>
518 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
525 $odd_row = !$odd_row;
529 // For the percentage column, use Questions - Connections, because
530 // the number of connections is not an item of the Query types
531 // but is included in Questions. Then the total of the percentages is 100.
532 $name = str_replace('Com_', '', $name);
533 $name = str_replace('_', ' ', $name);
535 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
536 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
537 <td
class="value"><?php
echo PMA_formatNumber($value, 4, 0); ?
></td
>
538 <td
class="value"><?php
echo
539 PMA_formatNumber($value * $hour_factor, 4, 2); ?
></td
>
540 <td
class="value"><?php
echo
541 PMA_formatNumber($value * $perc_factor, 0, 2); ?
>%
</td
>
550 <div id
="serverstatussection">
552 //Unset used variables
554 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
555 $hour_factor, $sections['com'],
556 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
557 $server_status['Max_used_connections'], $server_status['Bytes_received'],
558 $server_status['Bytes_sent'], $server_status['Connections'],
559 $server_status['Questions'], $server_status['Uptime']
562 foreach ($sections as $section_name => $section) {
563 if (! empty($section['vars'])) {
565 <table
class="data" id
="serverstatussection<?php echo $section_name; ?>">
566 <caption
class="tblHeaders">
568 href
="<?php echo $PHP_SELF . '?' .
569 PMA_generate_common_url() . '#serverstatus'; ?>"
570 name
="<?php echo $section_name; ?>"><?php
echo $strPos1; ?
>
572 ($GLOBALS['cfg']['MainPageIconic']
573 ?
'<img src="' . $GLOBALS['pmaThemeImage'] .
574 's_asc.png" width="11" height="9" align="middle" alt="" />'
578 if (! empty($section['title'])) {
579 echo $section['title'];
583 <col
class="namecol" />
584 <col
class="valuecol" />
585 <col
class="descrcol" />
588 <th
><?php
echo $strVar; ?
></th
>
589 <th
><?php
echo $strValue; ?
></th
>
590 <th
><?php
echo $strDescription; ?
></th
>
594 if (! empty($links[$section_name])) {
597 <tr
class="tblFooters">
598 <th colspan
="3" class="tblFooters">
600 foreach ($links[$section_name] as $link_name => $link_url) {
601 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
603 unset($link_url, $link_name);
614 foreach ($section['vars'] as $name => $value) {
615 $odd_row = !$odd_row;
617 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
618 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
619 <td
class="value"><?php
620 if (isset($alerts[$name])) {
621 if ($value > $alerts[$name]) {
622 echo '<span class="attention">';
624 echo '<span class="allfine">';
627 if ('%' === substr($name, -1, 1)) {
628 echo PMA_formatNumber($value, 0, 2) . ' %';
629 } elseif (is_numeric($value) && $value == (int) $value) {
630 echo PMA_formatNumber($value, 4, 0);
631 } elseif (is_numeric($value)) {
632 echo PMA_formatNumber($value, 4, 2);
634 echo htmlspecialchars($value);
636 if (isset($alerts[$name])) {
642 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
643 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
646 if (isset($links[$name])) {
647 foreach ($links[$name] as $link_name => $link_url) {
648 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
651 unset($link_url, $link_name);
658 unset($name, $value);
665 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
675 require_once './libraries/footer.inc.php';