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';
33 * Displays the sub-page heading
35 echo '<div id="serverstatus">' . "\n";
37 . ($GLOBALS['cfg']['MainPageIconic']
38 ?
'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
39 's_status.png" width="16" height="16" alt="" />'
41 . $strServerStatus . "\n"
46 * flush status variables if requested
48 if (isset($_REQUEST['flush'])) {
49 $_flush_commands = array(
55 if (in_array($_REQUEST['flush'], $_flush_commands)) {
56 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
58 unset($_flush_commands);
63 * get status from server
65 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
69 * for some calculations we require also some server settings
71 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
75 * starttime calculation
77 $start_time = PMA_DBI_fetch_value(
78 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
82 * cleanup some deprecated values
85 'Com_prepare_sql' => 'Com_stmt_prepare',
86 'Com_execute_sql' => 'Com_stmt_execute',
87 'Com_dealloc_sql' => 'Com_stmt_close',
90 foreach ($deprecated as $old => $new) {
91 if (isset($server_status[$old])
92 && isset($server_status[$new])) {
93 unset($server_status[$old]);
100 * calculate some values
102 // Key_buffer_fraction
103 if (isset($server_status['Key_blocks_unused'])
104 && isset($server_variables['key_cache_block_size'])
105 && isset($server_variables['key_buffer_size'])) {
106 $server_status['Key_buffer_fraction_%'] =
108 - $server_status['Key_blocks_unused']
109 * $server_variables['key_cache_block_size']
110 / $server_variables['key_buffer_size']
113 isset($server_status['Key_blocks_used'])
114 && isset($server_variables['key_buffer_size'])) {
115 $server_status['Key_buffer_fraction_%'] =
116 $server_status['Key_blocks_used']
118 / $server_variables['key_buffer_size'];
121 // Ratio for key read/write
122 if (isset($server_status['Key_writes'])
123 && isset($server_status['Key_write_requests'])
124 && $server_status['Key_write_requests'] > 0)
125 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
127 if (isset($server_status['Key_reads'])
128 && isset($server_status['Key_read_requests'])
129 && $server_status['Key_read_requests'] > 0)
130 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
132 // Threads_cache_hitrate
133 if (isset($server_status['Threads_created'])
134 && isset($server_status['Connections'])
135 && $server_status['Connections'] > 0) {
136 $server_status['Threads_cache_hitrate_%'] =
138 - $server_status['Threads_created']
139 / $server_status['Connections']
147 // name => max value before alert
150 // variable => max value
151 'Aborted_clients' => 0,
152 'Aborted_connects' => 0,
154 'Binlog_cache_disk_use' => 0,
156 'Created_tmp_disk_tables' => 0,
158 'Handler_read_rnd' => 0,
159 'Handler_read_rnd_next' => 0,
161 'Innodb_buffer_pool_pages_dirty' => 0,
162 'Innodb_buffer_pool_reads' => 0,
163 'Innodb_buffer_pool_wait_free' => 0,
164 'Innodb_log_waits' => 0,
165 'Innodb_row_lock_time_avg' => 10, // ms
166 'Innodb_row_lock_time_max' => 50, // ms
167 'Innodb_row_lock_waits' => 0,
170 'Delayed_errors' => 0,
171 'Select_full_join' => 0,
172 'Select_range_check' => 0,
173 'Sort_merge_passes' => 0,
174 'Opened_tables' => 0,
175 'Table_locks_waited' => 0,
176 'Qcache_lowmem_prunes' => 0,
177 'Slow_launch_threads' => 0,
179 // depends on Key_read_requests
180 // normaly lower then 1:0.01
181 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
182 // depends on Key_write_requests
183 // normaly nearly 1:1
184 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
186 'Key_buffer_fraction' => 0.5,
188 // alert if more than 95% of thread cache is in use
189 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
192 // variable => min value
193 //'Handler read key' => '> ',
198 * split variables in sections
200 $allocations = array(
201 // variable name => section
204 'Innodb_' => 'innodb',
207 'Handler_' => 'handler',
208 'Qcache_' => 'qcache',
209 'Threads_' => 'threads',
210 'Slow_launch_threads' => 'threads',
212 'Binlog_cache_' => 'binlog_cache',
213 'Created_tmp_' => 'created_tmp',
216 'Delayed_' => 'delayed',
217 'Not_flushed_delayed_rows' => 'delayed',
219 'Flush_commands' => 'query',
220 'Last_query_cost' => 'query',
221 'Slow_queries' => 'query',
223 'Select_' => 'select',
226 'Open_tables' => 'table',
227 'Opened_tables' => 'table',
228 'Table_locks_' => 'table',
230 'Rpl_status' => 'repl',
237 // section => section name (description)
238 'com' => array('title' => ''),
239 'query' => array('title' => $strSQLQuery),
240 'innodb' => array('title' => 'InnoDB'),
241 'ndb' => array('title' => 'NDB'),
242 'ssl' => array('title' => 'SSL'),
243 'handler' => array('title' => $strHandler),
244 'qcache' => array('title' => $strQueryCache),
245 'threads' => array('title' => $strThreads),
246 'binlog_cache' => array('title' => $strBinaryLog),
247 'created_tmp' => array('title' => $strTempData),
248 'delayed' => array('title' => $strServerStatusDelayedInserts),
249 'key' => array('title' => $strKeyCache),
250 'select' => array('title' => $strJoins),
251 'repl' => array('title' => $strReplication),
252 'sort' => array('title' => $strSorting),
253 'table' => array('title' => $strNumTables),
254 'tc' => array('title' => $strTransactionCoordinator),
259 * define some needfull links/commands
261 // variable or section name => (name => url)
264 $links['table'][$strFlushTables]
265 = $PMA_PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
266 $links['table'][$strShowOpenTables]
267 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
268 '&goto=server_status.php&' . PMA_generate_common_url();
270 $links['repl'][$strShowSlaveHosts]
271 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
272 '&goto=server_status.php&' . PMA_generate_common_url();
273 $links['repl'][$strShowSlaveStatus]
274 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
275 '&goto=server_status.php&' . PMA_generate_common_url();
276 $links['repl']['doc'] = 'replication';
278 $links['qcache'][$strFlushQueryCache]
279 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' .
280 PMA_generate_common_url();
281 $links['qcache']['doc'] = 'query_cache';
283 $links['threads'][$strMySQLShowProcess]
284 = 'server_processlist.php?' . PMA_generate_common_url();
285 $links['threads']['doc'] = 'mysql_threads';
287 $links['key']['doc'] = 'myisam_key_cache';
289 $links['binlog_cache']['doc'] = 'binary_log';
291 $links['Slow_queries']['doc'] = 'slow_query_log';
293 $links['innodb'][$strServerTabVariables]
294 = 'server_engines.php?engine=InnoDB&' . PMA_generate_common_url();
295 $links['innodb'][$strInnodbStat]
296 = 'server_engines.php?engine=InnoDB&page=Status&' .
297 PMA_generate_common_url();
298 $links['innodb']['doc'] = 'innodb';
301 // sort status vars into arrays
302 foreach ($server_status as $name => $value) {
303 if (isset($allocations[$name])) {
304 $sections[$allocations[$name]]['vars'][$name] = $value;
305 unset($server_status[$name]);
307 foreach ($allocations as $filter => $section) {
308 if (preg_match('/^' . $filter . '/', $name)
309 && isset($server_status[$name])) {
310 unset($server_status[$name]);
311 $sections[$section]['vars'][$name] = $value;
316 unset($name, $value, $filter, $section, $allocations);
319 $sections['all']['vars'] =& $server_status;
321 $hour_factor = 3600 / $server_status['Uptime'];
327 <div id
="statuslinks">
329 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
330 ><?php
echo $strRefresh; ?
></a
>
332 $PMA_PHP_SELF . '?flush=STATUS&' . PMA_generate_common_url(); ?>"
333 ><?php
echo $strShowStatusReset; ?
></a
>
334 <?php
echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?
>
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="' . $PMA_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 $PMA_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 if ('doc' == $link_name) {
602 echo PMA_showMySQLDocu($link_url, $link_url);
604 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
607 unset($link_url, $link_name);
618 foreach ($section['vars'] as $name => $value) {
619 $odd_row = !$odd_row;
621 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
622 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
623 <td
class="value"><?php
624 if (isset($alerts[$name])) {
625 if ($value > $alerts[$name]) {
626 echo '<span class="attention">';
628 echo '<span class="allfine">';
631 if ('%' === substr($name, -1, 1)) {
632 echo PMA_formatNumber($value, 0, 2) . ' %';
633 } elseif (is_numeric($value) && $value == (int) $value) {
634 echo PMA_formatNumber($value, 4, 0);
635 } elseif (is_numeric($value)) {
636 echo PMA_formatNumber($value, 4, 2);
638 echo htmlspecialchars($value);
640 if (isset($alerts[$name])) {
646 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
647 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
650 if (isset($links[$name])) {
651 foreach ($links[$name] as $link_name => $link_url) {
652 if ('doc' == $link_name) {
653 echo PMA_showMySQLDocu($link_url, $link_url);
655 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
659 unset($link_url, $link_name);
666 unset($name, $value);
673 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
683 require_once './libraries/footer.inc.php';