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
13 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
14 define('PMA_NO_VARIABLES_IMPORT', true);
16 require_once './libraries/common.inc.php';
19 * Does the common work
21 require './libraries/server_common.inc.php';
27 require './libraries/server_links.inc.php';
31 * Displays the sub-page heading
33 echo '<div id="serverstatus">' . "\n";
35 . ($GLOBALS['cfg']['MainPageIconic']
36 ?
'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
37 's_status.png" width="16" height="16" alt="" />'
39 . $strServerStatus . "\n"
44 * flush status variables if requested
46 if (isset($_REQUEST['flush'])) {
47 $_flush_commands = array(
53 if (in_array($_REQUEST['flush'], $_flush_commands)) {
54 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
56 unset($_flush_commands);
61 * get status from server
63 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
67 * for some calculations we require also some server settings
69 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
73 * starttime calculation
75 $start_time = PMA_DBI_fetch_value(
76 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
80 * cleanup some deprecated values
83 'Com_prepare_sql' => 'Com_stmt_prepare',
84 'Com_execute_sql' => 'Com_stmt_execute',
85 'Com_dealloc_sql' => 'Com_stmt_close',
88 foreach ($deprecated as $old => $new) {
89 if (isset($server_status[$old])
90 && isset($server_status[$new])) {
91 unset($server_status[$old]);
98 * calculate some values
100 // Key_buffer_fraction
101 if (isset($server_status['Key_blocks_unused'])
102 && isset($server_variables['key_cache_block_size'])
103 && isset($server_variables['key_buffer_size'])) {
104 $server_status['Key_buffer_fraction_%'] =
106 - $server_status['Key_blocks_unused']
107 * $server_variables['key_cache_block_size']
108 / $server_variables['key_buffer_size']
111 isset($server_status['Key_blocks_used'])
112 && isset($server_variables['key_buffer_size'])) {
113 $server_status['Key_buffer_fraction_%'] =
114 $server_status['Key_blocks_used']
116 / $server_variables['key_buffer_size'];
119 // Ratio for key read/write
120 if (isset($server_status['Key_writes'])
121 && isset($server_status['Key_write_requests'])
122 && $server_status['Key_write_requests'] > 0)
123 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
125 if (isset($server_status['Key_reads'])
126 && isset($server_status['Key_read_requests'])
127 && $server_status['Key_read_requests'] > 0)
128 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
130 // Threads_cache_hitrate
131 if (isset($server_status['Threads_created'])
132 && isset($server_status['Connections'])
133 && $server_status['Connections'] > 0) {
134 $server_status['Threads_cache_hitrate_%'] =
136 - $server_status['Threads_created']
137 / $server_status['Connections']
145 // name => max value before alert
148 // variable => max value
149 'Aborted_clients' => 0,
150 'Aborted_connects' => 0,
152 'Binlog_cache_disk_use' => 0,
154 'Created_tmp_disk_tables' => 0,
156 'Handler_read_rnd' => 0,
157 'Handler_read_rnd_next' => 0,
159 'Innodb_buffer_pool_pages_dirty' => 0,
160 'Innodb_buffer_pool_reads' => 0,
161 'Innodb_buffer_pool_wait_free' => 0,
162 'Innodb_log_waits' => 0,
163 'Innodb_row_lock_time_avg' => 10, // ms
164 'Innodb_row_lock_time_max' => 50, // ms
165 'Innodb_row_lock_waits' => 0,
168 'Delayed_errors' => 0,
169 'Select_full_join' => 0,
170 'Select_range_check' => 0,
171 'Sort_merge_passes' => 0,
172 'Opened_tables' => 0,
173 'Table_locks_waited' => 0,
174 'Qcache_lowmem_prunes' => 0,
175 'Slow_launch_threads' => 0,
177 // depends on Key_read_requests
178 // normaly lower then 1:0.01
179 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
180 // depends on Key_write_requests
181 // normaly nearly 1:1
182 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
184 'Key_buffer_fraction' => 0.5,
186 // alert if more than 95% of thread cache is in use
187 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
190 // variable => min value
191 //'Handler read key' => '> ',
196 * split variables in sections
198 $allocations = array(
199 // variable name => section
202 'Innodb_' => 'innodb',
205 'Handler_' => 'handler',
206 'Qcache_' => 'qcache',
207 'Threads_' => 'threads',
208 'Slow_launch_threads' => 'threads',
210 'Binlog_cache_' => 'binlog_cache',
211 'Created_tmp_' => 'created_tmp',
214 'Delayed_' => 'delayed',
215 'Not_flushed_delayed_rows' => 'delayed',
217 'Flush_commands' => 'query',
218 'Last_query_cost' => 'query',
219 'Slow_queries' => 'query',
221 'Select_' => 'select',
224 'Open_tables' => 'table',
225 'Opened_tables' => 'table',
226 'Table_locks_' => 'table',
228 'Rpl_status' => 'repl',
235 // section => section name (description)
236 'com' => array('title' => ''),
237 'query' => array('title' => $strSQLQuery),
238 'innodb' => array('title' => 'InnoDB'),
239 'ndb' => array('title' => 'NDB'),
240 'ssl' => array('title' => 'SSL'),
241 'handler' => array('title' => $strHandler),
242 'qcache' => array('title' => $strQueryCache),
243 'threads' => array('title' => $strThreads),
244 'binlog_cache' => array('title' => $strBinaryLog),
245 'created_tmp' => array('title' => $strTempData),
246 'delayed' => array('title' => $strServerStatusDelayedInserts),
247 'key' => array('title' => $strKeyCache),
248 'select' => array('title' => $strJoins),
249 'repl' => array('title' => $strReplication),
250 'sort' => array('title' => $strSorting),
251 'table' => array('title' => $strNumTables),
252 'tc' => array('title' => $strTransactionCoordinator),
257 * define some needfull links/commands
259 // variable or section name => (name => url)
262 $links['table'][$strFlushTables]
263 = $PMA_PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
264 $links['table'][$strShowOpenTables]
265 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
266 '&goto=server_status.php&' . PMA_generate_common_url();
268 $links['repl'][$strShowSlaveHosts]
269 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
270 '&goto=server_status.php&' . PMA_generate_common_url();
271 $links['repl'][$strShowSlaveStatus]
272 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
273 '&goto=server_status.php&' . PMA_generate_common_url();
274 $links['repl']['doc'] = 'replication';
276 $links['qcache'][$strFlushQueryCache]
277 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' .
278 PMA_generate_common_url();
279 $links['qcache']['doc'] = 'query_cache';
281 $links['threads'][$strMySQLShowProcess]
282 = 'server_processlist.php?' . PMA_generate_common_url();
283 $links['threads']['doc'] = 'mysql_threads';
285 $links['key']['doc'] = 'myisam_key_cache';
287 $links['binlog_cache']['doc'] = 'binary_log';
289 $links['Slow_queries']['doc'] = 'slow_query_log';
291 $links['innodb'][$strServerTabVariables]
292 = 'server_engines.php?engine=InnoDB&' . PMA_generate_common_url();
293 $links['innodb'][$strInnodbStat]
294 = 'server_engines.php?engine=InnoDB&page=Status&' .
295 PMA_generate_common_url();
296 $links['innodb']['doc'] = 'innodb';
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 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
328 ><?php
echo $strRefresh; ?
></a
>
330 $PMA_PHP_SELF . '?flush=STATUS&' . PMA_generate_common_url(); ?>"
331 ><?php
echo $strShowStatusReset; ?
></a
>
332 <?php
echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?
>
337 echo sprintf($strServerStatusUptime,
338 PMA_timespanFormat($server_status['Uptime']),
339 PMA_localisedDate($start_time)) . "\n";
343 <div id
="sectionlinks">
345 foreach ($sections as $section_name => $section) {
346 if (! empty($section['vars']) && ! empty($section['title'])) {
347 echo '<a href="' . $PMA_PHP_SELF . '?' .
348 PMA_generate_common_url() . '#' . $section_name . '">' .
349 $section['title'] . '</a>' . "\n";
355 <h3
><?php
echo $strServerTrafficNotes; ?
></h3
>
357 <table id
="serverstatustraffic" class="data">
360 <th colspan
="2"><?php
echo $strTraffic . ' ' . PMA_showHint($strStatisticsOverrun); ?
></th
>
361 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
366 <th
class="name"><?php
echo $strReceived; ?
></th
>
367 <td
class="value"><?php
echo
369 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?
></td
>
370 <td
class="value"><?php
echo
373 $server_status['Bytes_received'] * $hour_factor, 4)); ?
></td
>
376 <th
class="name"><?php
echo $strSent; ?
></th
>
377 <td
class="value"><?php
echo
379 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?
></td
>
380 <td
class="value"><?php
echo
383 $server_status['Bytes_sent'] * $hour_factor, 4)); ?
></td
>
386 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
387 <td
class="value"><?php
echo
390 $server_status['Bytes_received'] +
$server_status['Bytes_sent'], 4)
392 <td
class="value"><?php
echo
395 ($server_status['Bytes_received'] +
$server_status['Bytes_sent'])
402 <table id
="serverstatusconnections" class="data">
405 <th colspan
="2"><?php
echo $strConnections; ?
></th
>
406 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
412 <th
class="name"><?php
echo $strMaxConnects; ?
></th
>
413 <td
class="value"><?php
echo
414 PMA_formatNumber($server_status['Max_used_connections'], 0); ?
> </td
>
415 <td
class="value">--- </td
>
416 <td
class="value">--- </td
>
419 <th
class="name"><?php
echo $strFailedAttempts; ?
></th
>
420 <td
class="value"><?php
echo
421 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?
></td
>
422 <td
class="value"><?php
echo
423 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
425 <td
class="value"><?php
echo
426 $server_status['Connections'] > 0
428 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
433 <th
class="name"><?php
echo $strAbortedClients; ?
></th
>
434 <td
class="value"><?php
echo
435 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?
></td
>
436 <td
class="value"><?php
echo
437 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
439 <td
class="value"><?php
echo
440 $server_status['Connections'] > 0
442 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
447 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
448 <td
class="value"><?php
echo
449 PMA_formatNumber($server_status['Connections'], 4, 0); ?
></td
>
450 <td
class="value"><?php
echo
451 PMA_formatNumber($server_status['Connections'] * $hour_factor,
453 <td
class="value"><?php
echo
454 PMA_formatNumber(100, 0, 2); ?
>%
</td
>
459 <hr
class="clearfloat" />
462 sprintf($strQueryStatistics,
463 PMA_formatNumber($server_status['Questions'], 0)); ?
></h3
>
465 <table id
="serverstatusqueriessummary" class="data">
468 <th
><?php
echo $strTotalUC; ?
></th
>
469 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
470 <th
>ø
; <?php
echo $strPerMinute; ?
></th
>
471 <th
>ø
; <?php
echo $strPerSecond; ?
></th
>
476 <td
class="value"><?php
echo
477 PMA_formatNumber($server_status['Questions'], 4, 0); ?
></td
>
478 <td
class="value"><?php
echo
479 PMA_formatNumber($server_status['Questions'] * $hour_factor,
481 <td
class="value"><?php
echo
483 $server_status['Questions'] * 60 / $server_status['Uptime'],
485 <td
class="value"><?php
echo
487 $server_status['Questions'] / $server_status['Uptime'],
493 <div id
="serverstatusqueriesdetails">
495 // number of tables to split values into
497 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
501 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
502 foreach ($sections['com']['vars'] as $name => $value) {
504 if ($countRows === 0 ||
$countRows === $rows_per_table) {
506 if ($countRows === $rows_per_table) {
507 echo ' </tbody>' . "\n";
508 echo ' </table>' . "\n";
511 <table id
="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
512 <col
class="namecol" />
513 <col
class="valuecol" span
="3" />
515 <tr
><th colspan
="2"><?php
echo $strQueryType; ?
></th
>
516 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
523 $odd_row = !$odd_row;
527 // For the percentage column, use Questions - Connections, because
528 // the number of connections is not an item of the Query types
529 // but is included in Questions. Then the total of the percentages is 100.
530 $name = str_replace('Com_', '', $name);
531 $name = str_replace('_', ' ', $name);
533 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
534 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
535 <td
class="value"><?php
echo PMA_formatNumber($value, 4, 0); ?
></td
>
536 <td
class="value"><?php
echo
537 PMA_formatNumber($value * $hour_factor, 4, 2); ?
></td
>
538 <td
class="value"><?php
echo
539 PMA_formatNumber($value * $perc_factor, 0, 2); ?
>%
</td
>
548 <div id
="serverstatussection">
550 //Unset used variables
552 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
553 $hour_factor, $sections['com'],
554 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
555 $server_status['Max_used_connections'], $server_status['Bytes_received'],
556 $server_status['Bytes_sent'], $server_status['Connections'],
557 $server_status['Questions'], $server_status['Uptime']
560 foreach ($sections as $section_name => $section) {
561 if (! empty($section['vars'])) {
563 <table
class="data" id
="serverstatussection<?php echo $section_name; ?>">
564 <caption
class="tblHeaders">
566 href
="<?php echo $PMA_PHP_SELF . '?' .
567 PMA_generate_common_url() . '#serverstatus'; ?>"
568 name
="<?php echo $section_name; ?>"><?php
echo $strPos1; ?
>
570 ($GLOBALS['cfg']['MainPageIconic']
571 ?
'<img src="' . $GLOBALS['pmaThemeImage'] .
572 's_asc.png" width="11" height="9" align="middle" alt="" />'
576 if (! empty($section['title'])) {
577 echo $section['title'];
581 <col
class="namecol" />
582 <col
class="valuecol" />
583 <col
class="descrcol" />
586 <th
><?php
echo $strVar; ?
></th
>
587 <th
><?php
echo $strValue; ?
></th
>
588 <th
><?php
echo $strDescription; ?
></th
>
592 if (! empty($links[$section_name])) {
595 <tr
class="tblFooters">
596 <th colspan
="3" class="tblFooters">
598 foreach ($links[$section_name] as $link_name => $link_url) {
599 if ('doc' == $link_name) {
600 echo PMA_showMySQLDocu($link_url, $link_url);
602 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
605 unset($link_url, $link_name);
616 foreach ($section['vars'] as $name => $value) {
617 $odd_row = !$odd_row;
619 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
620 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
621 <td
class="value"><?php
622 if (isset($alerts[$name])) {
623 if ($value > $alerts[$name]) {
624 echo '<span class="attention">';
626 echo '<span class="allfine">';
629 if ('%' === substr($name, -1, 1)) {
630 echo PMA_formatNumber($value, 0, 2) . ' %';
631 } elseif (is_numeric($value) && $value == (int) $value) {
632 echo PMA_formatNumber($value, 4, 0);
633 } elseif (is_numeric($value)) {
634 echo PMA_formatNumber($value, 4, 2);
636 echo htmlspecialchars($value);
638 if (isset($alerts[$name])) {
644 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
645 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
648 if (isset($links[$name])) {
649 foreach ($links[$name] as $link_name => $link_url) {
650 if ('doc' == $link_name) {
651 echo PMA_showMySQLDocu($link_url, $link_url);
653 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
657 unset($link_url, $link_name);
664 unset($name, $value);
671 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
681 require_once './libraries/footer.inc.php';