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)
428 $replicationOut = "";
429 foreach ($replication_types as $type)
431 if ($replicationOut != "")
432 $replicationOut .= $strAndSmall . ' ';
433 if ($
{"server_{$type}_status_run"})
435 $replicationOut .= '<b>' . $type . '</b> ';
438 echo sprintf('<p>' . $strReplicationStatusInfo . '</p>', $replicationOut);
442 <div id
="sectionlinks">
444 foreach ($sections as $section_name => $section) {
445 if (! empty($section['vars']) && ! empty($section['title'])) {
446 echo '<a href="' . $PMA_PHP_SELF . '?' .
447 PMA_generate_common_url() . '#' . $section_name . '">' .
448 $section['title'] . '</a>' . "\n";
454 <h3
><?php
echo $strServerTrafficNotes; ?
></h3
>
456 <table id
="serverstatustraffic" class="data">
459 <th colspan
="2"><?php
echo $strTraffic . ' ' . PMA_showHint($strStatisticsOverrun); ?
></th
>
460 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
465 <th
class="name"><?php
echo $strReceived; ?
></th
>
466 <td
class="value"><?php
echo
468 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?
></td
>
469 <td
class="value"><?php
echo
472 $server_status['Bytes_received'] * $hour_factor, 4)); ?
></td
>
475 <th
class="name"><?php
echo $strSent; ?
></th
>
476 <td
class="value"><?php
echo
478 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?
></td
>
479 <td
class="value"><?php
echo
482 $server_status['Bytes_sent'] * $hour_factor, 4)); ?
></td
>
485 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
486 <td
class="value"><?php
echo
489 $server_status['Bytes_received'] +
$server_status['Bytes_sent'], 4)
491 <td
class="value"><?php
echo
494 ($server_status['Bytes_received'] +
$server_status['Bytes_sent'])
501 <table id
="serverstatusconnections" class="data">
504 <th colspan
="2"><?php
echo $strConnections; ?
></th
>
505 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
511 <th
class="name"><?php
echo $strMaxConnects; ?
></th
>
512 <td
class="value"><?php
echo
513 PMA_formatNumber($server_status['Max_used_connections'], 0); ?
> </td
>
514 <td
class="value">--- </td
>
515 <td
class="value">--- </td
>
518 <th
class="name"><?php
echo $strFailedAttempts; ?
></th
>
519 <td
class="value"><?php
echo
520 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?
></td
>
521 <td
class="value"><?php
echo
522 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
524 <td
class="value"><?php
echo
525 $server_status['Connections'] > 0
527 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
532 <th
class="name"><?php
echo $strAbortedClients; ?
></th
>
533 <td
class="value"><?php
echo
534 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?
></td
>
535 <td
class="value"><?php
echo
536 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
538 <td
class="value"><?php
echo
539 $server_status['Connections'] > 0
541 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
546 <th
class="name"><?php
echo $strTotalUC; ?
></th
>
547 <td
class="value"><?php
echo
548 PMA_formatNumber($server_status['Connections'], 4, 0); ?
></td
>
549 <td
class="value"><?php
echo
550 PMA_formatNumber($server_status['Connections'] * $hour_factor,
552 <td
class="value"><?php
echo
553 PMA_formatNumber(100, 0, 2); ?
>%
</td
>
558 <hr
class="clearfloat" />
561 sprintf($strQueryStatistics,
562 PMA_formatNumber($server_status['Questions'], 0)); ?
></h3
>
564 <table id
="serverstatusqueriessummary" class="data">
567 <th
><?php
echo $strTotalUC; ?
></th
>
568 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
569 <th
>ø
; <?php
echo $strPerMinute; ?
></th
>
570 <th
>ø
; <?php
echo $strPerSecond; ?
></th
>
575 <td
class="value"><?php
echo
576 PMA_formatNumber($server_status['Questions'], 4, 0); ?
></td
>
577 <td
class="value"><?php
echo
578 PMA_formatNumber($server_status['Questions'] * $hour_factor,
580 <td
class="value"><?php
echo
582 $server_status['Questions'] * 60 / $server_status['Uptime'],
584 <td
class="value"><?php
echo
586 $server_status['Questions'] / $server_status['Uptime'],
592 <div id
="serverstatusqueriesdetails">
594 // number of tables to split values into
596 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
600 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
601 foreach ($sections['com']['vars'] as $name => $value) {
603 if ($countRows === 0 ||
$countRows === $rows_per_table) {
605 if ($countRows === $rows_per_table) {
606 echo ' </tbody>' . "\n";
607 echo ' </table>' . "\n";
610 <table id
="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
611 <col
class="namecol" />
612 <col
class="valuecol" span
="3" />
614 <tr
><th colspan
="2"><?php
echo $strQueryType; ?
></th
>
615 <th
>ø
; <?php
echo $strPerHour; ?
></th
>
622 $odd_row = !$odd_row;
626 // For the percentage column, use Questions - Connections, because
627 // the number of connections is not an item of the Query types
628 // but is included in Questions. Then the total of the percentages is 100.
629 $name = str_replace('Com_', '', $name);
630 $name = str_replace('_', ' ', $name);
632 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
633 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
634 <td
class="value"><?php
echo PMA_formatNumber($value, 4, 0); ?
></td
>
635 <td
class="value"><?php
echo
636 PMA_formatNumber($value * $hour_factor, 4, 2); ?
></td
>
637 <td
class="value"><?php
echo
638 PMA_formatNumber($value * $perc_factor, 0, 2); ?
>%
</td
>
647 <div id
="serverstatussection">
649 //Unset used variables
651 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
652 $hour_factor, $sections['com'],
653 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
654 $server_status['Max_used_connections'], $server_status['Bytes_received'],
655 $server_status['Bytes_sent'], $server_status['Connections'],
656 $server_status['Questions'], $server_status['Uptime']
659 foreach ($sections as $section_name => $section) {
660 if (! empty($section['vars'])) {
662 <table
class="data" id
="serverstatussection<?php echo $section_name; ?>">
663 <caption
class="tblHeaders">
665 href
="<?php echo $PMA_PHP_SELF . '?' .
666 PMA_generate_common_url() . '#serverstatus'; ?>"
667 name
="<?php echo $section_name; ?>"><?php
echo $strPos1; ?
>
669 ($GLOBALS['cfg']['MainPageIconic']
670 ?
'<img src="' . $GLOBALS['pmaThemeImage'] .
671 's_asc.png" width="11" height="9" align="middle" alt="" />'
675 if (! empty($section['title'])) {
676 echo $section['title'];
680 <col
class="namecol" />
681 <col
class="valuecol" />
682 <col
class="descrcol" />
685 <th
><?php
echo $strVar; ?
></th
>
686 <th
><?php
echo $strValue; ?
></th
>
687 <th
><?php
echo $strDescription; ?
></th
>
691 if (! empty($links[$section_name])) {
694 <tr
class="tblFooters">
695 <th colspan
="3" class="tblFooters">
697 foreach ($links[$section_name] as $link_name => $link_url) {
698 if ('doc' == $link_name) {
699 echo PMA_showMySQLDocu($link_url, $link_url);
701 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
704 unset($link_url, $link_name);
715 foreach ($section['vars'] as $name => $value) {
716 $odd_row = !$odd_row;
718 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
719 <th
class="name"><?php
echo htmlspecialchars($name); ?
></th
>
720 <td
class="value"><?php
721 if (isset($alerts[$name])) {
722 if ($value > $alerts[$name]) {
723 echo '<span class="attention">';
725 echo '<span class="allfine">';
728 if ('%' === substr($name, -1, 1)) {
729 echo PMA_formatNumber($value, 0, 2) . ' %';
730 } elseif (is_numeric($value) && $value == (int) $value) {
731 echo PMA_formatNumber($value, 4, 0);
732 } elseif (is_numeric($value)) {
733 echo PMA_formatNumber($value, 4, 2);
735 echo htmlspecialchars($value);
737 if (isset($alerts[$name])) {
743 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
744 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
747 if (isset($links[$name])) {
748 foreach ($links[$name] as $link_name => $link_url) {
749 if ('doc' == $link_name) {
750 echo PMA_showMySQLDocu($link_url, $link_url);
752 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
756 unset($link_url, $link_name);
763 unset($name, $value);
770 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
774 /* if the server works as master or slave in replication process, display useful information */
775 if ($server_master_status_run ||
$server_slave_status_run)
778 <hr
class="clearfloat" />
780 <h3
><a name
="replication"></a
><?php
echo $strReplicationStatus; ?
></h3
>
783 foreach ($replication_types as $type)
785 if ($
{"server_{$type}_status_run"})
788 <h4
><?php
echo $
{"strReplicationStatus_{$type}"}; ?
></h4
>
791 <table id
="server<?php echo $type; ?>replicationsummary" class="data">
795 <th
><?php
echo $strVar; ?
></th
>
796 <th
><?php
echo $strValue; ?
></th
>
802 foreach($
{"{$type}_variables"} as $variable)
805 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
807 <?php
echo $variable; ?
>
811 if ($
{"{$type}_variables_alerts"}[$variable] == $
{"server_{$type}_status"}[0][$variable])
812 echo '<span class="attention">';
813 if ($
{"{$type}_variables_oks"}[$variable] == $
{"server_{$type}_status"}[0][$variable])
814 echo '<span class="allfine">';
817 echo $
{"server_{$type}_status"}[0][$variable];
823 $odd_row = ! $odd_row;
825 unset($
{"server_{$type}_status"});
842 require_once './libraries/footer.inc.php';