Remove obsolete messages, add missing ones.
[phpmyadmin/last10db.git] / server_status.php
blob5352974ba928e14d11b81e470d7d4c66d2bb0357
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4 /**
5 * displays status variables with descriptions and some hints an optmizing
6 * + reset status variables
7 */
8 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
9 define('PMA_NO_VARIABLES_IMPORT', true);
11 require_once './libraries/common.lib.php';
13 /**
14 * Does the common work
16 require './libraries/server_common.inc.php';
19 /**
20 * Displays the links
22 require './libraries/server_links.inc.php';
25 /**
26 * Displays the sub-page heading
28 echo '<div id="serverstatus">' . "\n";
29 echo '<h2>' . "\n"
30 . ($GLOBALS['cfg']['MainPageIconic']
31 ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
32 's_status.png" width="16" height="16" alt="" />'
33 : '')
34 . $strServerStatus . "\n"
35 . '</h2>' . "\n";
38 /**
39 * flush status variables if requested
41 if (isset($_REQUEST['flush'])) {
42 $_flush_commands = array(
43 'STATUS',
44 'TABLES',
45 'QUERY CACHE',
48 if (in_array($_REQUEST['flush'], $_flush_commands)) {
49 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
51 unset($_flush_commands);
55 /**
56 * get status from server
58 if (PMA_MYSQL_INT_VERSION >= 50002) {
59 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
60 } else {
61 $server_status = PMA_DBI_fetch_result('SHOW STATUS', 0, 1);
65 /**
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);
70 } else {
71 $server_variables = PMA_DBI_fetch_result('SHOW VARIABLES', 0, 1);
75 /**
76 * starttime calculation
78 $start_time = PMA_DBI_fetch_value(
79 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
82 /**
83 * cleanup some deprecated values
85 $deprecated = array(
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]);
97 unset($deprecated);
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']
112 * 100;
113 } elseif (
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']
118 * 1024
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']
128 * 100;
133 * define some alerts
135 // name => max value before alert
136 $alerts = array(
137 // lower is better
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,
157 'Slow_queries' => 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']
179 // higher is better
180 // variable => min value
181 //'Handler read key' => '> ',
186 * split variables in sections
188 $allocations = array(
189 // variable name => section
191 'Com_' => 'com',
192 'Innodb_' => 'innodb',
193 'Ndb_' => 'ndb',
194 'Ssl_' => 'ssl',
195 'Handler_' => 'handler',
196 'Qcache_' => 'qcache',
197 'Threads_' => 'threads',
198 'Slow_launch_threads' => 'threads',
200 'Binlog_cache_' => 'binlog_cache',
201 'Created_tmp_' => 'created_tmp',
202 'Key_' => 'key',
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',
212 'Sort_' => 'sort',
214 'Open_tables' => 'table',
215 'Opened_tables' => 'table',
216 'Table_locks_' => 'table',
218 'Rpl_status' => 'repl',
219 'Slave_' => 'repl',
221 'Tc_' => 'tc',
224 $sections = array(
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)
250 $links = array();
252 $links['table'][$strFlushTables]
253 = $PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
254 $links['table'][$strShowOpenTables]
255 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
256 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
258 $links['repl'][$strShowSlaveHosts]
259 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
260 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
261 $links['repl'][$strShowSlaveStatus]
262 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
263 '&amp;goto=server_status.php&amp;' . 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') . '&amp;' .
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&amp;' . PMA_generate_common_url();
292 $links['innodb'][$strInnodbStat]
293 = 'server_engines.php?engine=innodb&amp;page=status&amp;' .
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]);
304 } else {
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);
316 // rest
317 $sections['all']['vars'] =& $server_status;
319 $hour_factor = 3600 / $server_status['Uptime'];
322 * start output
325 <div id="statuslinks">
326 <a href="<?php echo
327 $PHP_SELF . '?' . PMA_generate_common_url(); ?>"
328 ><?php echo $strRefresh; ?></a>
329 <a href="<?php echo
330 $PHP_SELF . '?flush=STATUS&amp;' . PMA_generate_common_url(); ?>"
331 ><?php echo $strShowStatusReset; ?></a>
332 <a href="<?php echo
333 $cfg['MySQLManualBase']; ?>/server-status-variables.html"
334 target="documentation">MySQL - <?php echo $strDocu; ?></a>
335 </div>
338 <?php
339 echo sprintf($strServerStatusUptime,
340 PMA_timespanFormat($server_status['Uptime']),
341 PMA_localisedDate($start_time)) . "\n";
343 </p>
345 <div id="sectionlinks">
346 <?php
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";
355 </div>
357 <h3><?php echo $strServerTrafficNotes; ?></h3>
359 <table id="serverstatustraffic" class="data">
360 <thead>
361 <tr>
362 <th colspan="2"><?php echo $strTraffic . '&nbsp;' . PMA_showHint($strStatisticsOverrun); ?></th>
363 <th>&oslash; <?php echo $strPerHour; ?></th>
364 </tr>
365 </thead>
366 <tbody>
367 <tr class="odd">
368 <th class="name"><?php echo $strReceived; ?></th>
369 <td class="value"><?php echo
370 implode(' ',
371 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?></td>
372 <td class="value"><?php echo
373 implode(' ',
374 PMA_formatByteDown(
375 $server_status['Bytes_received'] * $hour_factor, 4)); ?></td>
376 </tr>
377 <tr class="even">
378 <th class="name"><?php echo $strSent; ?></th>
379 <td class="value"><?php echo
380 implode(' ',
381 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?></td>
382 <td class="value"><?php echo
383 implode(' ',
384 PMA_formatByteDown(
385 $server_status['Bytes_sent'] * $hour_factor, 4)); ?></td>
386 </tr>
387 <tr class="odd">
388 <th class="name"><?php echo $strTotalUC; ?></th>
389 <td class="value"><?php echo
390 implode(' ',
391 PMA_formatByteDown(
392 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 4)
393 ); ?></td>
394 <td class="value"><?php echo
395 implode(' ',
396 PMA_formatByteDown(
397 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
398 * $hour_factor, 4)
399 ); ?></td>
400 </tr>
401 </tbody>
402 </table>
404 <table id="serverstatusconnections" class="data">
405 <thead>
406 <tr>
407 <th colspan="2"><?php echo $strConnections; ?></th>
408 <th>&oslash; <?php echo $strPerHour; ?></th>
409 <th>%</th>
410 </tr>
411 </thead>
412 <tbody>
413 <tr class="odd">
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>
419 </tr>
420 <tr class="even">
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,
426 4, 2); ?></td>
427 <td class="value"><?php echo
428 $server_status['Connections'] > 0
429 ? PMA_formatNumber(
430 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
431 0, 2) . '%'
432 : '--- '; ?></td>
433 </tr>
434 <tr class="odd">
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,
440 4, 2); ?></td>
441 <td class="value"><?php echo
442 $server_status['Connections'] > 0
443 ? PMA_formatNumber(
444 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
445 0, 2) . '%'
446 : '--- '; ?></td>
447 </tr>
448 <tr class="even">
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,
454 4, 2); ?></td>
455 <td class="value"><?php echo
456 PMA_formatNumber(100, 0, 2); ?>%</td>
457 </tr>
458 </tbody>
459 </table>
461 <hr class="clearfloat" />
463 <h3><?php echo
464 sprintf($strQueryStatistics,
465 PMA_formatNumber($server_status['Questions'], 0)); ?></h3>
467 <table id="serverstatusqueriessummary" class="data">
468 <thead>
469 <tr>
470 <th><?php echo $strTotalUC; ?></th>
471 <th>&oslash; <?php echo $strPerHour; ?></th>
472 <th>&oslash; <?php echo $strPerMinute; ?></th>
473 <th>&oslash; <?php echo $strPerSecond; ?></th>
474 </tr>
475 </thead>
476 <tbody>
477 <tr class="odd">
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,
482 3, 2); ?></td>
483 <td class="value"><?php echo
484 PMA_formatNumber(
485 $server_status['Questions'] * 60 / $server_status['Uptime'],
486 3, 2); ?></td>
487 <td class="value"><?php echo
488 PMA_formatNumber(
489 $server_status['Questions'] / $server_status['Uptime'],
490 3, 2); ?></td>
491 </tr>
492 </tbody>
493 </table>
495 <div id="serverstatusqueriesdetails">
496 <?php
497 // number of tables to split values into
498 $tables = 2;
499 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
500 $current_table = 0;
501 $odd_row = true;
502 $countRows = 0;
503 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
504 foreach ($sections['com']['vars'] as $name => $value) {
505 $current_table++;
506 if ($countRows === 0 || $countRows === $rows_per_table) {
507 $odd_row = true;
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" />
516 <thead>
517 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
518 <th>&oslash; <?php echo $strPerHour; ?></th>
519 <th>%</th>
520 </tr>
521 </thead>
522 <tbody>
523 <?php
524 } else {
525 $odd_row = !$odd_row;
527 $countRows++;
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>
542 </tr>
543 <?php
546 </tbody>
547 </table>
548 </div>
550 <div id="serverstatussection">
551 <?php
552 //Unset used variables
553 unset(
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">
567 <a class="top"
568 href="<?php echo $PHP_SELF . '?' .
569 PMA_generate_common_url() . '#serverstatus'; ?>"
570 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
571 <?php echo
572 ($GLOBALS['cfg']['MainPageIconic']
573 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
574 's_asc.png" width="11" height="9" align="middle" alt="" />'
575 : ''); ?>
576 </a>
577 <?php
578 if (! empty($section['title'])) {
579 echo $section['title'];
582 </caption>
583 <col class="namecol" />
584 <col class="valuecol" />
585 <col class="descrcol" />
586 <thead>
587 <tr>
588 <th><?php echo $strVar; ?></th>
589 <th><?php echo $strValue; ?></th>
590 <th><?php echo $strDescription; ?></th>
591 </tr>
592 </thead>
593 <?php
594 if (! empty($links[$section_name])) {
596 <tfoot>
597 <tr class="tblFooters">
598 <th colspan="3" class="tblFooters">
599 <?php
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);
605 </th>
606 </tr>
607 </tfoot>
608 <?php
611 <tbody>
612 <?php
613 $odd_row = false;
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">';
623 } else {
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);
633 } else {
634 echo htmlspecialchars($value);
636 if (isset($alerts[$name])) {
637 echo '</span>';
639 ?></td>
640 <td class="descr">
641 <?php
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>' .
649 "\n";
651 unset($link_url, $link_name);
654 </td>
655 </tr>
656 <?php
658 unset($name, $value);
660 </tbody>
661 </table>
662 <?php
665 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
667 </div>
668 </div>
669 <?php
673 * Sends the footer
675 require_once './libraries/footer.inc.php';