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);
68 * get master status from server
70 $server_master_status = PMA_DBI_fetch_result('SHOW MASTER STATUS');
73 * get slave status from server
75 $server_slave_status = PMA_DBI_fetch_result('SHOW SLAVE STATUS');
79 * for some calculations we require also some server settings
81 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
84 * starttime calculation
86 $start_time = PMA_DBI_fetch_value(
87 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
91 * cleanup some deprecated values
94 'Com_prepare_sql' => 'Com_stmt_prepare',
95 'Com_execute_sql' => 'Com_stmt_execute',
96 'Com_dealloc_sql' => 'Com_stmt_close',
99 foreach ($deprecated as $old => $new) {
100 if (isset($server_status[$old])
101 && isset($server_status[$new])) {
102 unset($server_status[$old]);
109 * calculate some values
111 // Key_buffer_fraction
112 if (isset($server_status['Key_blocks_unused'])
113 && isset($server_variables['key_cache_block_size'])
114 && isset($server_variables['key_buffer_size'])) {
115 $server_status['Key_buffer_fraction_%'] =
117 - $server_status['Key_blocks_unused']
118 * $server_variables['key_cache_block_size']
119 / $server_variables['key_buffer_size']
122 isset($server_status['Key_blocks_used'])
123 && isset($server_variables['key_buffer_size'])) {
124 $server_status['Key_buffer_fraction_%'] =
125 $server_status['Key_blocks_used']
127 / $server_variables['key_buffer_size'];
130 // Ratio for key read/write
131 if (isset($server_status['Key_writes'])
132 && isset($server_status['Key_write_requests'])
133 && $server_status['Key_write_requests'] > 0)
134 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
136 if (isset($server_status['Key_reads'])
137 && isset($server_status['Key_read_requests'])
138 && $server_status['Key_read_requests'] > 0)
139 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
141 // Threads_cache_hitrate
142 if (isset($server_status['Threads_created'])
143 && isset($server_status['Connections'])
144 && $server_status['Connections'] > 0) {
145 $server_status['Threads_cache_hitrate_%'] =
147 - $server_status['Threads_created']
148 / $server_status['Connections']
156 // name => max value before alert
159 // variable => max value
160 'Aborted_clients' => 0,
161 'Aborted_connects' => 0,
163 'Binlog_cache_disk_use' => 0,
165 'Created_tmp_disk_tables' => 0,
167 'Handler_read_rnd' => 0,
168 'Handler_read_rnd_next' => 0,
170 'Innodb_buffer_pool_pages_dirty' => 0,
171 'Innodb_buffer_pool_reads' => 0,
172 'Innodb_buffer_pool_wait_free' => 0,
173 'Innodb_log_waits' => 0,
174 'Innodb_row_lock_time_avg' => 10, // ms
175 'Innodb_row_lock_time_max' => 50, // ms
176 'Innodb_row_lock_waits' => 0,
179 'Delayed_errors' => 0,
180 'Select_full_join' => 0,
181 'Select_range_check' => 0,
182 'Sort_merge_passes' => 0,
183 'Opened_tables' => 0,
184 'Table_locks_waited' => 0,
185 'Qcache_lowmem_prunes' => 0,
186 'Slow_launch_threads' => 0,
188 // depends on Key_read_requests
189 // normaly lower then 1:0.01
190 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
191 // depends on Key_write_requests
192 // normaly nearly 1:1
193 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
195 'Key_buffer_fraction' => 0.5,
197 // alert if more than 95% of thread cache is in use
198 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
201 // variable => min value
202 //'Handler read key' => '> ',
207 * split variables in sections
209 $allocations = array(
210 // variable name => section
213 'Innodb_' => 'innodb',
216 'Handler_' => 'handler',
217 'Qcache_' => 'qcache',
218 'Threads_' => 'threads',
219 'Slow_launch_threads' => 'threads',
221 'Binlog_cache_' => 'binlog_cache',
222 'Created_tmp_' => 'created_tmp',
225 'Delayed_' => 'delayed',
226 'Not_flushed_delayed_rows' => 'delayed',
228 'Flush_commands' => 'query',
229 'Last_query_cost' => 'query',
230 'Slow_queries' => 'query',
232 'Select_' => 'select',
235 'Open_tables' => 'table',
236 'Opened_tables' => 'table',
237 'Table_locks_' => 'table',
239 'Rpl_status' => 'repl',
246 // section => section name (description)
247 'com' => array('title' => ''),
248 'query' => array('title' => $strSQLQuery),
249 'innodb' => array('title' => 'InnoDB'),
250 'ndb' => array('title' => 'NDB'),
251 'ssl' => array('title' => 'SSL'),
252 'handler' => array('title' => $strHandler),
253 'qcache' => array('title' => $strQueryCache),
254 'threads' => array('title' => $strThreads),
255 'binlog_cache' => array('title' => $strBinaryLog),
256 'created_tmp' => array('title' => $strTempData),
257 'delayed' => array('title' => $strServerStatusDelayedInserts),
258 'key' => array('title' => $strKeyCache),
259 'select' => array('title' => $strJoins),
260 'repl' => array('title' => $strReplication),
261 'sort' => array('title' => $strSorting),
262 'table' => array('title' => $strNumTables),
263 'tc' => array('title' => $strTransactionCoordinator),
269 $replication_types = array('master', 'slave');
272 * define variables for master status
274 $master_variables = array(
282 * Define variables for slave status
284 $slave_variables = array(
291 'Read_Master_Log_Pos',
294 'Relay_Master_Log_File',
298 'Replicate_Ignore_DB',
299 'Replicate_Do_Table',
300 'Replicate_Ignore_Table',
301 'Replicate_Wild_Do_Table',
302 'Replicate_Wild_Ignore_Table',
306 'Exec_Master_Log_Pos',
311 'Master_SSL_Allowed',
312 'Master_SSL_CA_File',
313 'Master_SSL_CA_Path',
317 'Seconds_Behind_Master'
320 * define important variables, which need to be watched for correct running of replication in slave mode
322 $slave_variables_alerts = array(
323 'Slave_IO_Running' => 'No',
324 'Slave_SQL_Running' => 'No'
326 $slave_variables_oks = array(
327 'Slave_IO_Running' => 'Yes',
328 'Slave_SQL_Running' => 'Yes'
331 * define some needfull links/commands
333 // variable or section name => (name => url)
336 $links['table'][$strFlushTables]
337 = $PMA_PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
338 $links['table'][$strShowOpenTables]
339 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
340 '&goto=server_status.php&' . PMA_generate_common_url();
342 $links['repl'][$strShowSlaveHosts]
343 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
344 '&goto=server_status.php&' . PMA_generate_common_url();
345 $links['repl'][$strShowSlaveStatus]
346 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
347 '&goto=server_status.php&' . PMA_generate_common_url();
348 $links['repl']['doc'] = 'replication';
350 $links['qcache'][$strFlushQueryCache]
351 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' .
352 PMA_generate_common_url();
353 $links['qcache']['doc'] = 'query_cache';
355 $links['threads'][$strMySQLShowProcess]
356 = 'server_processlist.php?' . PMA_generate_common_url();
357 $links['threads']['doc'] = 'mysql_threads';
359 $links['key']['doc'] = 'myisam_key_cache';
361 $links['binlog_cache']['doc'] = 'binary_log';
363 $links['Slow_queries']['doc'] = 'slow_query_log';
365 $links['innodb'][$strServerTabVariables]
366 = 'server_engines.php?engine=InnoDB&' . PMA_generate_common_url();
367 $links['innodb'][$strInnodbStat]
368 = 'server_engines.php?engine=InnoDB&page=Status&' .
369 PMA_generate_common_url();
370 $links['innodb']['doc'] = 'innodb';
373 // sort status vars into arrays
374 foreach ($server_status as $name => $value) {
375 if (isset($allocations[$name])) {
376 $sections[$allocations[$name]]['vars'][$name] = $value;
377 unset($server_status[$name]);
379 foreach ($allocations as $filter => $section) {
380 if (preg_match('/^' . $filter . '/', $name)
381 && isset($server_status[$name])) {
382 unset($server_status[$name]);
383 $sections[$section]['vars'][$name] = $value;
388 unset($name, $value, $filter, $section, $allocations);
390 // check which replication is available
391 foreach ($replication_types as $type)
393 if (count($
{"server_{$type}_status"}) > 0)
394 $
{"server_{$type}_status_run"} = true;
396 $
{"server_{$type}_status_run"} = false;
399 $sections['all']['vars'] =& $server_status;
401 $hour_factor = 3600 / $server_status['Uptime'];
407 <div id
="statuslinks">
409 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
410 ><?php
echo $strRefresh; ?
></a
>
412 $PMA_PHP_SELF . '?flush=STATUS&' . PMA_generate_common_url(); ?>"
413 ><?php
echo $strShowStatusReset; ?
></a
>
414 <?php
echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?
>
419 echo sprintf($strServerStatusUptime,
420 PMA_timespanFormat($server_status['Uptime']),
421 PMA_localisedDate($start_time)) . "\n";
426 if ($server_master_status_run ||
$server_slave_status_run) {
427 $replicationOut = "";
428 foreach ($replication_types as $type) {
429 if ($
{"server_{$type}_status_run"}) {
430 if ($replicationOut != "") {
431 $replicationOut .= $strAndSmall . ' ';
433 $replicationOut .= '<b>' . $type . '</b> ';
436 echo sprintf('<p>' . $strReplicationStatusInfo . '</p>', $replicationOut);
440 <div id
="sectionlinks">
442 foreach ($sections as $section_name => $section) {
443 if (! empty($section['vars']) && ! empty($section['title'])) {
444 echo '<a href="' . $PMA_PHP_SELF . '?' .
445 PMA_generate_common_url() . '#' . $section_name . '">' .
446 $section['title'] . '</a>' . "\n";
452 <h3
><?php
echo $strServerTrafficNotes; ?
></h3
>
454 <table id
="serverstatustraffic" class="data">
457 <th colspan
="2"><?php
echo $strTraffic . ' ' . PMA_showHint($strStatisticsOverrun); ?
></th
>
458 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
463 <th
class="name"><?php
echo $strReceived; ?
></th
>
464 <td
class="value"><?php
echo
466 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?
></td
>
467 <td
class="value"><?php
echo
470 $server_status['Bytes_received'] * $hour_factor, 4)); ?
></td
>
473 <th
class="name"><?php
echo $strSent; ?
></th
>
474 <td
class="value"><?php
echo
476 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?
></td
>
477 <td
class="value"><?php
echo
480 $server_status['Bytes_sent'] * $hour_factor, 4)); ?
></td
>
483 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
484 <td
class="value"><?php
echo
487 $server_status['Bytes_received'] +
$server_status['Bytes_sent'], 4)
489 <td
class="value"><?php
echo
492 ($server_status['Bytes_received'] +
$server_status['Bytes_sent'])
499 <table id
="serverstatusconnections" class="data">
502 <th colspan
="2"><?php
echo $strConnections; ?
></th
>
503 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
509 <th
class="name"><?php
echo $strMaxConnects; ?
></th
>
510 <td
class="value"><?php
echo
511 PMA_formatNumber($server_status['Max_used_connections'], 0); ?
> </td
>
512 <td
class="value">--- </td
>
513 <td
class="value">--- </td
>
516 <th
class="name"><?php
echo $strFailedAttempts; ?
></th
>
517 <td
class="value"><?php
echo
518 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?
></td
>
519 <td
class="value"><?php
echo
520 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
522 <td
class="value"><?php
echo
523 $server_status['Connections'] > 0
525 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
530 <th
class="name"><?php
echo $strAbortedClients; ?
></th
>
531 <td
class="value"><?php
echo
532 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?
></td
>
533 <td
class="value"><?php
echo
534 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
536 <td
class="value"><?php
echo
537 $server_status['Connections'] > 0
539 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
544 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
545 <td
class="value"><?php
echo
546 PMA_formatNumber($server_status['Connections'], 4, 0); ?
></td
>
547 <td
class="value"><?php
echo
548 PMA_formatNumber($server_status['Connections'] * $hour_factor,
550 <td
class="value"><?php
echo
551 PMA_formatNumber(100, 0, 2); ?
>%
</td
>
556 <hr
class="clearfloat" />
559 sprintf($strQueryStatistics,
560 PMA_formatNumber($server_status['Questions'], 0)); ?
></h3
>
562 <table id
="serverstatusqueriessummary" class="data">
565 <th
><?php
echo $strTotalUC; ?
></th
>
566 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
567 <th
>ø
; <?php
echo $strPerMinute; ?
></th
>
568 <th
>ø
; <?php
echo $strPerSecond; ?
></th
>
573 <td
class="value"><?php
echo
574 PMA_formatNumber($server_status['Questions'], 4, 0); ?
></td
>
575 <td
class="value"><?php
echo
576 PMA_formatNumber($server_status['Questions'] * $hour_factor,
578 <td
class="value"><?php
echo
580 $server_status['Questions'] * 60 / $server_status['Uptime'],
582 <td
class="value"><?php
echo
584 $server_status['Questions'] / $server_status['Uptime'],
590 <div id
="serverstatusqueriesdetails">
592 // number of tables to split values into
594 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
598 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
599 foreach ($sections['com']['vars'] as $name => $value) {
601 if ($countRows === 0 ||
$countRows === $rows_per_table) {
603 if ($countRows === $rows_per_table) {
604 echo ' </tbody>' . "\n";
605 echo ' </table>' . "\n";
608 <table id
="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
609 <col
class="namecol" />
610 <col
class="valuecol" span
="3" />
612 <tr
><th colspan
="2"><?php
echo $strQueryType; ?
></th
>
613 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
620 $odd_row = !$odd_row;
624 // For the percentage column, use Questions - Connections, because
625 // the number of connections is not an item of the Query types
626 // but is included in Questions. Then the total of the percentages is 100.
627 $name = str_replace('Com_', '', $name);
628 $name = str_replace('_', ' ', $name);
630 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
631 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
632 <td
class="value"><?php
echo PMA_formatNumber($value, 4, 0); ?
></td
>
633 <td
class="value"><?php
echo
634 PMA_formatNumber($value * $hour_factor, 4, 2); ?
></td
>
635 <td
class="value"><?php
echo
636 PMA_formatNumber($value * $perc_factor, 0, 2); ?
>%
</td
>
645 <div id
="serverstatussection">
647 //Unset used variables
649 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
650 $hour_factor, $sections['com'],
651 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
652 $server_status['Max_used_connections'], $server_status['Bytes_received'],
653 $server_status['Bytes_sent'], $server_status['Connections'],
654 $server_status['Questions'], $server_status['Uptime']
657 foreach ($sections as $section_name => $section) {
658 if (! empty($section['vars'])) {
660 <table
class="data" id
="serverstatussection<?php echo $section_name; ?>">
661 <caption
class="tblHeaders">
663 href
="<?php echo $PMA_PHP_SELF . '?' .
664 PMA_generate_common_url() . '#serverstatus'; ?>"
665 name
="<?php echo $section_name; ?>"><?php
echo $strPos1; ?
>
667 ($GLOBALS['cfg']['MainPageIconic']
668 ?
'<img src="' . $GLOBALS['pmaThemeImage'] .
669 's_asc.png" width="11" height="9" align="middle" alt="" />'
673 if (! empty($section['title'])) {
674 echo $section['title'];
678 <col
class="namecol" />
679 <col
class="valuecol" />
680 <col
class="descrcol" />
683 <th
><?php
echo $strVar; ?
></th
>
684 <th
><?php
echo $strValue; ?
></th
>
685 <th
><?php
echo $strDescription; ?
></th
>
689 if (! empty($links[$section_name])) {
692 <tr
class="tblFooters">
693 <th colspan
="3" class="tblFooters">
695 foreach ($links[$section_name] as $link_name => $link_url) {
696 if ('doc' == $link_name) {
697 echo PMA_showMySQLDocu($link_url, $link_url);
699 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
702 unset($link_url, $link_name);
713 foreach ($section['vars'] as $name => $value) {
714 $odd_row = !$odd_row;
716 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
717 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
718 <td
class="value"><?php
719 if (isset($alerts[$name])) {
720 if ($value > $alerts[$name]) {
721 echo '<span class="attention">';
723 echo '<span class="allfine">';
726 if ('%' === substr($name, -1, 1)) {
727 echo PMA_formatNumber($value, 0, 2) . ' %';
728 } elseif (is_numeric($value) && $value == (int) $value) {
729 echo PMA_formatNumber($value, 4, 0);
730 } elseif (is_numeric($value)) {
731 echo PMA_formatNumber($value, 4, 2);
733 echo htmlspecialchars($value);
735 if (isset($alerts[$name])) {
741 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
742 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
745 if (isset($links[$name])) {
746 foreach ($links[$name] as $link_name => $link_url) {
747 if ('doc' == $link_name) {
748 echo PMA_showMySQLDocu($link_url, $link_url);
750 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
754 unset($link_url, $link_name);
761 unset($name, $value);
768 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
772 /* if the server works as master or slave in replication process, display useful information */
773 if ($server_master_status_run ||
$server_slave_status_run)
776 <hr
class="clearfloat" />
778 <h3
><a name
="replication"></a
><?php
echo $strReplicationStatus; ?
></h3
>
781 foreach ($replication_types as $type)
783 if ($
{"server_{$type}_status_run"})
786 <h4
><?php
echo $
{"strReplicationStatus_{$type}"}; ?
></h4
>
789 <table id
="server<?php echo $type; ?>replicationsummary" class="data">
793 <th
><?php
echo $strVar; ?
></th
>
794 <th
><?php
echo $strValue; ?
></th
>
800 foreach($
{"{$type}_variables"} as $variable)
803 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
805 <?php
echo $variable; ?
>
809 if (isset($
{"{$type}_variables_alerts"}[$variable])
810 && $
{"{$type}_variables_alerts"}[$variable] == $
{"server_{$type}_status"}[0][$variable]) {
811 echo '<span class="attention">';
813 } elseif (isset($
{"{$type}_variables_oks"}[$variable])
814 && $
{"{$type}_variables_oks"}[$variable] == $
{"server_{$type}_status"}[0][$variable]) {
815 echo '<span class="allfine">';
819 echo $
{"server_{$type}_status"}[0][$variable];
825 $odd_row = ! $odd_row;
827 unset($
{"server_{$type}_status"});
844 require_once './libraries/footer.inc.php';