2.11.11.3 release
[phpmyadmin/sankalp_k.git] / server_status.php
blobc6b37c6674397b6209b115950600dd3589479280
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * displays status variables with descriptions and some hints an optmizing
5 * + reset status variables
7 * @version $Id$
8 */
10 /**
13 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
14 define('PMA_NO_VARIABLES_IMPORT', true);
16 require_once './libraries/common.inc.php';
18 /**
19 * Does the common work
21 require './libraries/server_common.inc.php';
24 /**
25 * Displays the links
27 require './libraries/server_links.inc.php';
30 /**
31 * Displays the sub-page heading
33 echo '<div id="serverstatus">' . "\n";
34 echo '<h2>' . "\n"
35 . ($GLOBALS['cfg']['MainPageIconic']
36 ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] .
37 's_status.png" width="16" height="16" alt="" />'
38 : '')
39 . $strServerStatus . "\n"
40 . '</h2>' . "\n";
43 /**
44 * flush status variables if requested
46 if (isset($_REQUEST['flush'])) {
47 $_flush_commands = array(
48 'STATUS',
49 'TABLES',
50 'QUERY CACHE',
53 if (in_array($_REQUEST['flush'], $_flush_commands)) {
54 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
56 unset($_flush_commands);
60 /**
61 * get status from server
63 if (PMA_MYSQL_INT_VERSION >= 50002) {
64 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
65 } else {
66 $server_status = PMA_DBI_fetch_result('SHOW STATUS', 0, 1);
70 /**
71 * for some calculations we require also some server settings
73 if (PMA_MYSQL_INT_VERSION >= 40003) {
74 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
75 } else {
76 $server_variables = PMA_DBI_fetch_result('SHOW VARIABLES', 0, 1);
80 /**
81 * starttime calculation
83 $start_time = PMA_DBI_fetch_value(
84 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
87 /**
88 * cleanup some deprecated values
90 $deprecated = array(
91 'Com_prepare_sql' => 'Com_stmt_prepare',
92 'Com_execute_sql' => 'Com_stmt_execute',
93 'Com_dealloc_sql' => 'Com_stmt_close',
96 foreach ($deprecated as $old => $new) {
97 if (isset($server_status[$old])
98 && isset($server_status[$new])) {
99 unset($server_status[$old]);
102 unset($deprecated);
106 * calculate some values
108 // Key_buffer_fraction
109 if (isset($server_status['Key_blocks_unused'])
110 && isset($server_variables['key_cache_block_size'])
111 && isset($server_variables['key_buffer_size'])) {
112 $server_status['Key_buffer_fraction_%'] =
114 - $server_status['Key_blocks_unused']
115 * $server_variables['key_cache_block_size']
116 / $server_variables['key_buffer_size']
117 * 100;
118 } elseif (
119 isset($server_status['Key_blocks_used'])
120 && isset($server_variables['key_buffer_size'])) {
121 $server_status['Key_buffer_fraction_%'] =
122 $server_status['Key_blocks_used']
123 * 1024
124 / $server_variables['key_buffer_size'];
127 // Ratio for key read/write
128 if (isset($server_status['Key_writes'])
129 && isset($server_status['Key_write_requests'])
130 && $server_status['Key_write_requests'] > 0)
131 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
133 if (isset($server_status['Key_reads'])
134 && isset($server_status['Key_read_requests'])
135 && $server_status['Key_read_requests'] > 0)
136 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
138 // Threads_cache_hitrate
139 if (isset($server_status['Threads_created'])
140 && isset($server_status['Connections'])
141 && $server_status['Connections'] > 0) {
142 $server_status['Threads_cache_hitrate_%'] =
144 - $server_status['Threads_created']
145 / $server_status['Connections']
146 * 100;
151 * define some alerts
153 // name => max value before alert
154 $alerts = array(
155 // lower is better
156 // variable => max value
157 'Aborted_clients' => 0,
158 'Aborted_connects' => 0,
160 'Binlog_cache_disk_use' => 0,
162 'Created_tmp_disk_tables' => 0,
164 'Handler_read_rnd' => 0,
165 'Handler_read_rnd_next' => 0,
167 'Innodb_buffer_pool_pages_dirty' => 0,
168 'Innodb_buffer_pool_reads' => 0,
169 'Innodb_buffer_pool_wait_free' => 0,
170 'Innodb_log_waits' => 0,
171 'Innodb_row_lock_time_avg' => 10, // ms
172 'Innodb_row_lock_time_max' => 50, // ms
173 'Innodb_row_lock_waits' => 0,
175 'Slow_queries' => 0,
176 'Delayed_errors' => 0,
177 'Select_full_join' => 0,
178 'Select_range_check' => 0,
179 'Sort_merge_passes' => 0,
180 'Opened_tables' => 0,
181 'Table_locks_waited' => 0,
182 'Qcache_lowmem_prunes' => 0,
183 'Slow_launch_threads' => 0,
185 // depends on Key_read_requests
186 // normaly lower then 1:0.01
187 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
188 // depends on Key_write_requests
189 // normaly nearly 1:1
190 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
192 'Key_buffer_fraction' => 0.5,
194 // alert if more than 95% of thread cache is in use
195 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
197 // higher is better
198 // variable => min value
199 //'Handler read key' => '> ',
204 * split variables in sections
206 $allocations = array(
207 // variable name => section
209 'Com_' => 'com',
210 'Innodb_' => 'innodb',
211 'Ndb_' => 'ndb',
212 'Ssl_' => 'ssl',
213 'Handler_' => 'handler',
214 'Qcache_' => 'qcache',
215 'Threads_' => 'threads',
216 'Slow_launch_threads' => 'threads',
218 'Binlog_cache_' => 'binlog_cache',
219 'Created_tmp_' => 'created_tmp',
220 'Key_' => 'key',
222 'Delayed_' => 'delayed',
223 'Not_flushed_delayed_rows' => 'delayed',
225 'Flush_commands' => 'query',
226 'Last_query_cost' => 'query',
227 'Slow_queries' => 'query',
229 'Select_' => 'select',
230 'Sort_' => 'sort',
232 'Open_tables' => 'table',
233 'Opened_tables' => 'table',
234 'Table_locks_' => 'table',
236 'Rpl_status' => 'repl',
237 'Slave_' => 'repl',
239 'Tc_' => 'tc',
242 $sections = array(
243 // section => section name (description)
244 'com' => array('title' => ''),
245 'query' => array('title' => $strSQLQuery),
246 'innodb' => array('title' => 'InnoDB'),
247 'ndb' => array('title' => 'NDB'),
248 'ssl' => array('title' => 'SSL'),
249 'handler' => array('title' => $strHandler),
250 'qcache' => array('title' => $strQueryCache),
251 'threads' => array('title' => $strThreads),
252 'binlog_cache' => array('title' => $strBinaryLog),
253 'created_tmp' => array('title' => $strTempData),
254 'delayed' => array('title' => $strServerStatusDelayedInserts),
255 'key' => array('title' => $strKeyCache),
256 'select' => array('title' => $strJoins),
257 'repl' => array('title' => $strReplication),
258 'sort' => array('title' => $strSorting),
259 'table' => array('title' => $strNumTables),
260 'tc' => array('title' => $strTransactionCoordinator),
265 * define some needfull links/commands
267 // variable or section name => (name => url)
268 $links = array();
270 $links['table'][$strFlushTables]
271 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
272 $links['table'][$strShowOpenTables]
273 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
274 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
276 $links['repl'][$strShowSlaveHosts]
277 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
278 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
279 $links['repl'][$strShowSlaveStatus]
280 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
281 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
282 $links['repl']['doc'] = 'replication';
284 $links['qcache'][$strFlushQueryCache]
285 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
286 PMA_generate_common_url();
287 $links['qcache']['doc'] = 'query_cache';
289 $links['threads'][$strMySQLShowProcess]
290 = 'server_processlist.php?' . PMA_generate_common_url();
291 $links['threads']['doc'] = 'mysql_threads';
293 $links['key']['doc'] = 'myisam_key_cache';
295 $links['binlog_cache']['doc'] = 'binary_log';
297 $links['Slow_queries']['doc'] = 'slow_query_log';
299 $links['innodb'][$strServerTabVariables]
300 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
301 $links['innodb'][$strInnodbStat]
302 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
303 PMA_generate_common_url();
304 $links['innodb']['doc'] = 'innodb';
307 // sort status vars into arrays
308 foreach ($server_status as $name => $value) {
309 if (isset($allocations[$name])) {
310 $sections[$allocations[$name]]['vars'][$name] = $value;
311 unset($server_status[$name]);
312 } else {
313 foreach ($allocations as $filter => $section) {
314 if (preg_match('/^' . $filter . '/', $name)
315 && isset($server_status[$name])) {
316 unset($server_status[$name]);
317 $sections[$section]['vars'][$name] = $value;
322 unset($name, $value, $filter, $section, $allocations);
324 // rest
325 $sections['all']['vars'] =& $server_status;
327 $hour_factor = 3600 / $server_status['Uptime'];
330 * start output
333 <div id="statuslinks">
334 <a href="<?php echo
335 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
336 ><?php echo $strRefresh; ?></a>
337 <a href="<?php echo
338 $PMA_PHP_SELF . '?flush=STATUS&amp;' . PMA_generate_common_url(); ?>"
339 ><?php echo $strShowStatusReset; ?></a>
340 <?php echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?>
341 </div>
344 <?php
345 echo sprintf($strServerStatusUptime,
346 PMA_timespanFormat($server_status['Uptime']),
347 PMA_localisedDate($start_time)) . "\n";
349 </p>
351 <div id="sectionlinks">
352 <?php
353 foreach ($sections as $section_name => $section) {
354 if (! empty($section['vars']) && ! empty($section['title'])) {
355 echo '<a href="' . $PMA_PHP_SELF . '?' .
356 PMA_generate_common_url() . '#' . $section_name . '">' .
357 $section['title'] . '</a>' . "\n";
361 </div>
363 <h3><?php echo $strServerTrafficNotes; ?></h3>
365 <table id="serverstatustraffic" class="data">
366 <thead>
367 <tr>
368 <th colspan="2"><?php echo $strTraffic . '&nbsp;' . PMA_showHint($strStatisticsOverrun); ?></th>
369 <th>&oslash; <?php echo $strPerHour; ?></th>
370 </tr>
371 </thead>
372 <tbody>
373 <tr class="odd">
374 <th class="name"><?php echo $strReceived; ?></th>
375 <td class="value"><?php echo
376 implode(' ',
377 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?></td>
378 <td class="value"><?php echo
379 implode(' ',
380 PMA_formatByteDown(
381 $server_status['Bytes_received'] * $hour_factor, 4)); ?></td>
382 </tr>
383 <tr class="even">
384 <th class="name"><?php echo $strSent; ?></th>
385 <td class="value"><?php echo
386 implode(' ',
387 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?></td>
388 <td class="value"><?php echo
389 implode(' ',
390 PMA_formatByteDown(
391 $server_status['Bytes_sent'] * $hour_factor, 4)); ?></td>
392 </tr>
393 <tr class="odd">
394 <th class="name"><?php echo $strTotalUC; ?></th>
395 <td class="value"><?php echo
396 implode(' ',
397 PMA_formatByteDown(
398 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 4)
399 ); ?></td>
400 <td class="value"><?php echo
401 implode(' ',
402 PMA_formatByteDown(
403 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
404 * $hour_factor, 4)
405 ); ?></td>
406 </tr>
407 </tbody>
408 </table>
410 <table id="serverstatusconnections" class="data">
411 <thead>
412 <tr>
413 <th colspan="2"><?php echo $strConnections; ?></th>
414 <th>&oslash; <?php echo $strPerHour; ?></th>
415 <th>%</th>
416 </tr>
417 </thead>
418 <tbody>
419 <tr class="odd">
420 <th class="name"><?php echo $strMaxConnects; ?></th>
421 <td class="value"><?php echo
422 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
423 <td class="value">--- </td>
424 <td class="value">--- </td>
425 </tr>
426 <tr class="even">
427 <th class="name"><?php echo $strFailedAttempts; ?></th>
428 <td class="value"><?php echo
429 PMA_formatNumber($server_status['Aborted_connects'], 4, 0); ?></td>
430 <td class="value"><?php echo
431 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
432 4, 2); ?></td>
433 <td class="value"><?php echo
434 $server_status['Connections'] > 0
435 ? PMA_formatNumber(
436 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
437 0, 2) . '%'
438 : '--- '; ?></td>
439 </tr>
440 <tr class="odd">
441 <th class="name"><?php echo $strAbortedClients; ?></th>
442 <td class="value"><?php echo
443 PMA_formatNumber($server_status['Aborted_clients'], 4, 0); ?></td>
444 <td class="value"><?php echo
445 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
446 4, 2); ?></td>
447 <td class="value"><?php echo
448 $server_status['Connections'] > 0
449 ? PMA_formatNumber(
450 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
451 0, 2) . '%'
452 : '--- '; ?></td>
453 </tr>
454 <tr class="even">
455 <th class="name"><?php echo $strTotalUC; ?></th>
456 <td class="value"><?php echo
457 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
458 <td class="value"><?php echo
459 PMA_formatNumber($server_status['Connections'] * $hour_factor,
460 4, 2); ?></td>
461 <td class="value"><?php echo
462 PMA_formatNumber(100, 0, 2); ?>%</td>
463 </tr>
464 </tbody>
465 </table>
467 <hr class="clearfloat" />
469 <h3><?php echo
470 sprintf($strQueryStatistics,
471 PMA_formatNumber($server_status['Questions'], 0)); ?></h3>
473 <table id="serverstatusqueriessummary" class="data">
474 <thead>
475 <tr>
476 <th><?php echo $strTotalUC; ?></th>
477 <th>&oslash; <?php echo $strPerHour; ?></th>
478 <th>&oslash; <?php echo $strPerMinute; ?></th>
479 <th>&oslash; <?php echo $strPerSecond; ?></th>
480 </tr>
481 </thead>
482 <tbody>
483 <tr class="odd">
484 <td class="value"><?php echo
485 PMA_formatNumber($server_status['Questions'], 4, 0); ?></td>
486 <td class="value"><?php echo
487 PMA_formatNumber($server_status['Questions'] * $hour_factor,
488 3, 2); ?></td>
489 <td class="value"><?php echo
490 PMA_formatNumber(
491 $server_status['Questions'] * 60 / $server_status['Uptime'],
492 3, 2); ?></td>
493 <td class="value"><?php echo
494 PMA_formatNumber(
495 $server_status['Questions'] / $server_status['Uptime'],
496 3, 2); ?></td>
497 </tr>
498 </tbody>
499 </table>
501 <div id="serverstatusqueriesdetails">
502 <?php
503 // number of tables to split values into
504 $tables = 2;
505 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
506 $current_table = 0;
507 $odd_row = true;
508 $countRows = 0;
509 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
510 foreach ($sections['com']['vars'] as $name => $value) {
511 $current_table++;
512 if ($countRows === 0 || $countRows === $rows_per_table) {
513 $odd_row = true;
514 if ($countRows === $rows_per_table) {
515 echo ' </tbody>' . "\n";
516 echo ' </table>' . "\n";
519 <table id="serverstatusqueriesdetails<?php echo $current_table; ?>" class="data">
520 <col class="namecol" />
521 <col class="valuecol" span="3" />
522 <thead>
523 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
524 <th>&oslash; <?php echo $strPerHour; ?></th>
525 <th>%</th>
526 </tr>
527 </thead>
528 <tbody>
529 <?php
530 } else {
531 $odd_row = !$odd_row;
533 $countRows++;
535 // For the percentage column, use Questions - Connections, because
536 // the number of connections is not an item of the Query types
537 // but is included in Questions. Then the total of the percentages is 100.
538 $name = str_replace('Com_', '', $name);
539 $name = str_replace('_', ' ', $name);
541 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
542 <th class="name"><?php echo htmlspecialchars($name); ?></th>
543 <td class="value"><?php echo PMA_formatNumber($value, 4, 0); ?></td>
544 <td class="value"><?php echo
545 PMA_formatNumber($value * $hour_factor, 4, 2); ?></td>
546 <td class="value"><?php echo
547 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
548 </tr>
549 <?php
552 </tbody>
553 </table>
554 </div>
556 <div id="serverstatussection">
557 <?php
558 //Unset used variables
559 unset(
560 $tables, $rows_per_table, $current_table, $countRows, $perc_factor,
561 $hour_factor, $sections['com'],
562 $server_status['Aborted_clients'], $server_status['Aborted_connects'],
563 $server_status['Max_used_connections'], $server_status['Bytes_received'],
564 $server_status['Bytes_sent'], $server_status['Connections'],
565 $server_status['Questions'], $server_status['Uptime']
568 foreach ($sections as $section_name => $section) {
569 if (! empty($section['vars'])) {
571 <table class="data" id="serverstatussection<?php echo $section_name; ?>">
572 <caption class="tblHeaders">
573 <a class="top"
574 href="<?php echo $PMA_PHP_SELF . '?' .
575 PMA_generate_common_url() . '#serverstatus'; ?>"
576 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
577 <?php echo
578 ($GLOBALS['cfg']['MainPageIconic']
579 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
580 's_asc.png" width="11" height="9" align="middle" alt="" />'
581 : ''); ?>
582 </a>
583 <?php
584 if (! empty($section['title'])) {
585 echo $section['title'];
588 </caption>
589 <col class="namecol" />
590 <col class="valuecol" />
591 <col class="descrcol" />
592 <thead>
593 <tr>
594 <th><?php echo $strVar; ?></th>
595 <th><?php echo $strValue; ?></th>
596 <th><?php echo $strDescription; ?></th>
597 </tr>
598 </thead>
599 <?php
600 if (! empty($links[$section_name])) {
602 <tfoot>
603 <tr class="tblFooters">
604 <th colspan="3" class="tblFooters">
605 <?php
606 foreach ($links[$section_name] as $link_name => $link_url) {
607 if ('doc' == $link_name) {
608 echo PMA_showMySQLDocu($link_url, $link_url);
609 } else {
610 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
613 unset($link_url, $link_name);
615 </th>
616 </tr>
617 </tfoot>
618 <?php
621 <tbody>
622 <?php
623 $odd_row = false;
624 foreach ($section['vars'] as $name => $value) {
625 $odd_row = !$odd_row;
627 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
628 <th class="name"><?php echo htmlspecialchars($name); ?></th>
629 <td class="value"><?php
630 if (isset($alerts[$name])) {
631 if ($value > $alerts[$name]) {
632 echo '<span class="attention">';
633 } else {
634 echo '<span class="allfine">';
637 if ('%' === substr($name, -1, 1)) {
638 echo PMA_formatNumber($value, 0, 2) . ' %';
639 } elseif (is_numeric($value) && $value == (int) $value) {
640 echo PMA_formatNumber($value, 4, 0);
641 } elseif (is_numeric($value)) {
642 echo PMA_formatNumber($value, 4, 2);
643 } else {
644 echo htmlspecialchars($value);
646 if (isset($alerts[$name])) {
647 echo '</span>';
649 ?></td>
650 <td class="descr">
651 <?php
652 if (isset($GLOBALS['strShowStatus' . $name . 'Descr'])) {
653 echo $GLOBALS['strShowStatus' . $name . 'Descr'];
656 if (isset($links[$name])) {
657 foreach ($links[$name] as $link_name => $link_url) {
658 if ('doc' == $link_name) {
659 echo PMA_showMySQLDocu($link_url, $link_url);
660 } else {
661 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
662 "\n";
665 unset($link_url, $link_name);
668 </td>
669 </tr>
670 <?php
672 unset($name, $value);
674 </tbody>
675 </table>
676 <?php
679 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
681 </div>
682 </div>
683 <?php
687 * Sends the footer
689 require_once './libraries/footer.inc.php';