Hungarian update
[phpmyadmin/crack.git] / server_status.php
blob78c91b3f7bdbd5652c65fddf87ddfec526c3c49c
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 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
66 /**
67 * for some calculations we require also some server settings
69 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
72 /**
73 * starttime calculation
75 $start_time = PMA_DBI_fetch_value(
76 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
79 /**
80 * cleanup some deprecated values
82 $deprecated = array(
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]);
94 unset($deprecated);
97 /**
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']
109 * 100;
110 } elseif (
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']
115 * 1024
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']
138 * 100;
143 * define some alerts
145 // name => max value before alert
146 $alerts = array(
147 // lower is better
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,
167 'Slow_queries' => 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']
189 // higher is better
190 // variable => min value
191 //'Handler read key' => '> ',
196 * split variables in sections
198 $allocations = array(
199 // variable name => section
201 'Com_' => 'com',
202 'Innodb_' => 'innodb',
203 'Ndb_' => 'ndb',
204 'Ssl_' => 'ssl',
205 'Handler_' => 'handler',
206 'Qcache_' => 'qcache',
207 'Threads_' => 'threads',
208 'Slow_launch_threads' => 'threads',
210 'Binlog_cache_' => 'binlog_cache',
211 'Created_tmp_' => 'created_tmp',
212 'Key_' => 'key',
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',
222 'Sort_' => 'sort',
224 'Open_tables' => 'table',
225 'Opened_tables' => 'table',
226 'Table_locks_' => 'table',
228 'Rpl_status' => 'repl',
229 'Slave_' => 'repl',
231 'Tc_' => 'tc',
234 $sections = array(
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)
260 $links = array();
262 $links['table'][$strFlushTables]
263 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
264 $links['table'][$strShowOpenTables]
265 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
266 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
268 $links['repl'][$strShowSlaveHosts]
269 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
270 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
271 $links['repl'][$strShowSlaveStatus]
272 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE STATUS') .
273 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
274 $links['repl']['doc'] = 'replication';
276 $links['qcache'][$strFlushQueryCache]
277 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
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&amp;' . PMA_generate_common_url();
293 $links['innodb'][$strInnodbStat]
294 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
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]);
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 $PMA_PHP_SELF . '?' . PMA_generate_common_url(); ?>"
328 ><?php echo $strRefresh; ?></a>
329 <a href="<?php echo
330 $PMA_PHP_SELF . '?flush=STATUS&amp;' . PMA_generate_common_url(); ?>"
331 ><?php echo $strShowStatusReset; ?></a>
332 <?php echo PMA_showMySQLDocu('server_status_variables','server_status_variables'); ?>
333 </div>
336 <?php
337 echo sprintf($strServerStatusUptime,
338 PMA_timespanFormat($server_status['Uptime']),
339 PMA_localisedDate($start_time)) . "\n";
341 </p>
343 <div id="sectionlinks">
344 <?php
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";
353 </div>
355 <h3><?php echo $strServerTrafficNotes; ?></h3>
357 <table id="serverstatustraffic" class="data">
358 <thead>
359 <tr>
360 <th colspan="2"><?php echo $strTraffic . '&nbsp;' . PMA_showHint($strStatisticsOverrun); ?></th>
361 <th>&oslash; <?php echo $strPerHour; ?></th>
362 </tr>
363 </thead>
364 <tbody>
365 <tr class="odd">
366 <th class="name"><?php echo $strReceived; ?></th>
367 <td class="value"><?php echo
368 implode(' ',
369 PMA_formatByteDown($server_status['Bytes_received'], 4)); ?></td>
370 <td class="value"><?php echo
371 implode(' ',
372 PMA_formatByteDown(
373 $server_status['Bytes_received'] * $hour_factor, 4)); ?></td>
374 </tr>
375 <tr class="even">
376 <th class="name"><?php echo $strSent; ?></th>
377 <td class="value"><?php echo
378 implode(' ',
379 PMA_formatByteDown($server_status['Bytes_sent'], 4)); ?></td>
380 <td class="value"><?php echo
381 implode(' ',
382 PMA_formatByteDown(
383 $server_status['Bytes_sent'] * $hour_factor, 4)); ?></td>
384 </tr>
385 <tr class="odd">
386 <th class="name"><?php echo $strTotalUC; ?></th>
387 <td class="value"><?php echo
388 implode(' ',
389 PMA_formatByteDown(
390 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 4)
391 ); ?></td>
392 <td class="value"><?php echo
393 implode(' ',
394 PMA_formatByteDown(
395 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
396 * $hour_factor, 4)
397 ); ?></td>
398 </tr>
399 </tbody>
400 </table>
402 <table id="serverstatusconnections" class="data">
403 <thead>
404 <tr>
405 <th colspan="2"><?php echo $strConnections; ?></th>
406 <th>&oslash; <?php echo $strPerHour; ?></th>
407 <th>%</th>
408 </tr>
409 </thead>
410 <tbody>
411 <tr class="odd">
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>
417 </tr>
418 <tr class="even">
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,
424 4, 2); ?></td>
425 <td class="value"><?php echo
426 $server_status['Connections'] > 0
427 ? PMA_formatNumber(
428 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
429 0, 2) . '%'
430 : '--- '; ?></td>
431 </tr>
432 <tr class="odd">
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,
438 4, 2); ?></td>
439 <td class="value"><?php echo
440 $server_status['Connections'] > 0
441 ? PMA_formatNumber(
442 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
443 0, 2) . '%'
444 : '--- '; ?></td>
445 </tr>
446 <tr class="even">
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,
452 4, 2); ?></td>
453 <td class="value"><?php echo
454 PMA_formatNumber(100, 0, 2); ?>%</td>
455 </tr>
456 </tbody>
457 </table>
459 <hr class="clearfloat" />
461 <h3><?php echo
462 sprintf($strQueryStatistics,
463 PMA_formatNumber($server_status['Questions'], 0)); ?></h3>
465 <table id="serverstatusqueriessummary" class="data">
466 <thead>
467 <tr>
468 <th><?php echo $strTotalUC; ?></th>
469 <th>&oslash; <?php echo $strPerHour; ?></th>
470 <th>&oslash; <?php echo $strPerMinute; ?></th>
471 <th>&oslash; <?php echo $strPerSecond; ?></th>
472 </tr>
473 </thead>
474 <tbody>
475 <tr class="odd">
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,
480 3, 2); ?></td>
481 <td class="value"><?php echo
482 PMA_formatNumber(
483 $server_status['Questions'] * 60 / $server_status['Uptime'],
484 3, 2); ?></td>
485 <td class="value"><?php echo
486 PMA_formatNumber(
487 $server_status['Questions'] / $server_status['Uptime'],
488 3, 2); ?></td>
489 </tr>
490 </tbody>
491 </table>
493 <div id="serverstatusqueriesdetails">
494 <?php
495 // number of tables to split values into
496 $tables = 2;
497 $rows_per_table = (int) ceil(count($sections['com']['vars']) / $tables);
498 $current_table = 0;
499 $odd_row = true;
500 $countRows = 0;
501 $perc_factor = 100 / ($server_status['Questions'] - $server_status['Connections']);
502 foreach ($sections['com']['vars'] as $name => $value) {
503 $current_table++;
504 if ($countRows === 0 || $countRows === $rows_per_table) {
505 $odd_row = true;
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" />
514 <thead>
515 <tr><th colspan="2"><?php echo $strQueryType; ?></th>
516 <th>&oslash; <?php echo $strPerHour; ?></th>
517 <th>%</th>
518 </tr>
519 </thead>
520 <tbody>
521 <?php
522 } else {
523 $odd_row = !$odd_row;
525 $countRows++;
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>
540 </tr>
541 <?php
544 </tbody>
545 </table>
546 </div>
548 <div id="serverstatussection">
549 <?php
550 //Unset used variables
551 unset(
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">
565 <a class="top"
566 href="<?php echo $PMA_PHP_SELF . '?' .
567 PMA_generate_common_url() . '#serverstatus'; ?>"
568 name="<?php echo $section_name; ?>"><?php echo $strPos1; ?>
569 <?php echo
570 ($GLOBALS['cfg']['MainPageIconic']
571 ? '<img src="' . $GLOBALS['pmaThemeImage'] .
572 's_asc.png" width="11" height="9" align="middle" alt="" />'
573 : ''); ?>
574 </a>
575 <?php
576 if (! empty($section['title'])) {
577 echo $section['title'];
580 </caption>
581 <col class="namecol" />
582 <col class="valuecol" />
583 <col class="descrcol" />
584 <thead>
585 <tr>
586 <th><?php echo $strVar; ?></th>
587 <th><?php echo $strValue; ?></th>
588 <th><?php echo $strDescription; ?></th>
589 </tr>
590 </thead>
591 <?php
592 if (! empty($links[$section_name])) {
594 <tfoot>
595 <tr class="tblFooters">
596 <th colspan="3" class="tblFooters">
597 <?php
598 foreach ($links[$section_name] as $link_name => $link_url) {
599 if ('doc' == $link_name) {
600 echo PMA_showMySQLDocu($link_url, $link_url);
601 } else {
602 echo '<a href="' . $link_url . '">' . $link_name . '</a>' . "\n";
605 unset($link_url, $link_name);
607 </th>
608 </tr>
609 </tfoot>
610 <?php
613 <tbody>
614 <?php
615 $odd_row = false;
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">';
625 } else {
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);
635 } else {
636 echo htmlspecialchars($value);
638 if (isset($alerts[$name])) {
639 echo '</span>';
641 ?></td>
642 <td class="descr">
643 <?php
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);
652 } else {
653 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
654 "\n";
657 unset($link_url, $link_name);
660 </td>
661 </tr>
662 <?php
664 unset($name, $value);
666 </tbody>
667 </table>
668 <?php
671 unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
673 </div>
674 </div>
675 <?php
679 * Sends the footer
681 require_once './libraries/footer.inc.php';