2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays a list of server status variables
9 require_once 'libraries/common.inc.php';
10 require_once 'libraries/server_common.inc.php';
11 require_once 'libraries/ServerStatusData.class.php';
13 $server_master_status = false;
14 $server_slave_status = false;
16 include_once 'libraries/replication.inc.php';
17 include_once 'libraries/replication_gui.lib.php';
21 * flush status variables if requested
23 if (isset($_REQUEST['flush'])) {
24 $_flush_commands = array(
30 if (in_array($_REQUEST['flush'], $_flush_commands)) {
31 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
33 unset($_flush_commands);
36 $ServerStatusData = new PMA_ServerStatusData();
38 $response = PMA_Response
::getInstance();
39 $header = $response->getHeader();
40 $scripts = $header->getScripts();
41 $scripts->addFile('server_status_variables.js');
42 $scripts->addFile('jquery/jquery.tablesorter.js');
43 $scripts->addFile('server_status_sorter.js');
45 $response->addHTML('<div>');
46 $response->addHTML($ServerStatusData->getMenuHtml());
47 $response->addHTML(getFilterHtml($ServerStatusData));
48 $response->addHTML(getLinkSuggestionsHtml($ServerStatusData));
49 $response->addHTML(getVariablesTableHtml($ServerStatusData));
50 $response->addHTML('</div>');
55 * Returns the html for the list filter
57 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
61 function getFilterHtml($ServerStatusData)
64 if (! empty($_REQUEST['filterAlert'])) {
65 $filterAlert = ' checked="checked"';
68 if (! empty($_REQUEST['filterText'])) {
69 $filterText = htmlspecialchars($_REQUEST['filterText']);
72 if (! empty($_REQUEST['dontFormat'])) {
73 $dontFormat = ' checked="checked"';
77 $retval .= '<fieldset id="tableFilter">';
78 $retval .= '<legend>' . __('Filters') . '</legend>';
79 $retval .= '<form action="server_status_variables.php?' . PMA_generate_common_url() . '">';
80 $retval .= '<input type="submit" value="' . __('Refresh') . '" />';
81 $retval .= '<div class="formelement">';
82 $retval .= '<label for="filterText">' . __('Containing the word:') . '</label>';
83 $retval .= '<input name="filterText" type="text" id="filterText" '
84 . 'style="vertical-align: baseline;" value="' . $filterText . '" />';
86 $retval .= '<div class="formelement">';
87 $retval .= '<input' . $filterAlert . ' type="checkbox" name="filterAlert" id="filterAlert" />';
88 $retval .= '<label for="filterAlert">';
89 $retval .= __('Show only alert values');
90 $retval .= '</label>';
92 $retval .= '<div class="formelement">';
93 $retval .= '<select id="filterCategory" name="filterCategory">';
94 $retval .= '<option value="">' . __('Filter by category…') . '</option>';
96 foreach ($ServerStatusData->sections
as $section_id => $section_name) {
97 if (isset($ServerStatusData->categoryUsed
[$section_id])) {
98 if (! empty($_REQUEST['filterCategory'])
99 && $_REQUEST['filterCategory'] == $section_id
101 $selected = ' selected="selected"';
105 $retval .= '<option' . $selected . ' value="' . $section_id. '">';
106 $retval .= htmlspecialchars($section_name) . '</option>';
109 $retval .= '</select>';
111 $retval .= '<div class="formelement">';
112 $retval .= '<input' . $dontFormat . ' type="checkbox" name="dontFormat" id="dontFormat" />';
113 $retval .= '<label for="dontFormat">';
114 $retval .= __('Show unformatted values');
115 $retval .= '</label>';
117 $retval .= '</form>';
118 $retval .= '</fieldset>';
124 * Prints the suggestion links
126 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
130 function getLinkSuggestionsHtml($ServerStatusData)
132 $retval = '<div id="linkSuggestions" class="defaultLinks" style="display:none">';
133 $retval .= '<p class="notice">' . __('Related links:');
134 foreach ($ServerStatusData->links
as $section_name => $section_links) {
135 $retval .= '<span class="status_' . $section_name . '"> ';
137 foreach ($section_links as $link_name => $link_url) {
141 if ('doc' == $link_name) {
142 $retval .= PMA_Util
::showMySQLDocu($link_url, $link_url);
144 $retval .= '<a href="' . $link_url . '">' . $link_name . '</a>';
148 $retval .= '</span>';
150 unset($link_url, $link_name, $i);
158 * Returns a table with variables information
160 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
164 function getVariablesTableHtml($ServerStatusData)
167 $strShowStatus = getStatusVariablesDescriptions();
171 // name => max value before alert
174 // variable => max value
175 'Aborted_clients' => 0,
176 'Aborted_connects' => 0,
178 'Binlog_cache_disk_use' => 0,
180 'Created_tmp_disk_tables' => 0,
182 'Handler_read_rnd' => 0,
183 'Handler_read_rnd_next' => 0,
185 'Innodb_buffer_pool_pages_dirty' => 0,
186 'Innodb_buffer_pool_reads' => 0,
187 'Innodb_buffer_pool_wait_free' => 0,
188 'Innodb_log_waits' => 0,
189 'Innodb_row_lock_time_avg' => 10, // ms
190 'Innodb_row_lock_time_max' => 50, // ms
191 'Innodb_row_lock_waits' => 0,
194 'Delayed_errors' => 0,
195 'Select_full_join' => 0,
196 'Select_range_check' => 0,
197 'Sort_merge_passes' => 0,
198 'Opened_tables' => 0,
199 'Table_locks_waited' => 0,
200 'Qcache_lowmem_prunes' => 0,
202 'Qcache_free_blocks' => isset($ServerStatusData->server_status
['Qcache_total_blocks'])
203 ?
$ServerStatusData->server_status
['Qcache_total_blocks'] / 5 : 0,
204 'Slow_launch_threads' => 0,
206 // depends on Key_read_requests
207 // normaly lower then 1:0.01
208 'Key_reads' => isset($ServerStatusData->status
['Key_read_requests'])
209 ?
(0.01 * $ServerStatusData->status
['Key_read_requests']) : 0,
210 // depends on Key_write_requests
211 // normaly nearly 1:1
212 'Key_writes' => isset($ServerStatusData->status
['Key_write_requests'])
213 ?
(0.9 * $ServerStatusData->status
['Key_write_requests']) : 0,
215 'Key_buffer_fraction' => 0.5,
217 // alert if more than 95% of thread cache is in use
218 'Threads_cached' => isset($ServerStatusData->variables
['thread_cache_size'])
219 ?
0.95 * $ServerStatusData->variables
['thread_cache_size'] : 0
222 // variable => min value
223 //'Handler read key' => '> ',
226 $retval .= '<table class="data sortable noclick" id="serverstatusvariables">';
227 $retval .= '<col class="namecol" />';
228 $retval .= '<col class="valuecol" />';
229 $retval .= '<col class="descrcol" />';
230 $retval .= '<thead>';
232 $retval .= '<th>' . __('Variable') . '</th>';
233 $retval .= '<th>' . __('Value') . '</th>';
234 $retval .= '<th>' . __('Description') . '</th>';
236 $retval .= '</thead>';
237 $retval .= '<tbody>';
240 foreach ($ServerStatusData->status
as $name => $value) {
241 $odd_row = !$odd_row;
242 $retval .= '<tr class="' . ($odd_row ?
'odd' : 'even')
243 . (isset($ServerStatusData->allocationMap
[$name])?
' s_' . $ServerStatusData->allocationMap
[$name] : '')
246 $retval .= '<th class="name">';
247 $retval .= htmlspecialchars(str_replace('_', ' ', $name));
248 /* Fields containing % are calculated, they can not be described in MySQL documentation */
249 if (strpos($name, '%') === false) {
250 $retval .= PMA_Util
::showMySQLDocu(
251 'server-status-variables',
252 'server-status-variables',
259 $retval .= '<td class="value"><span class="formatted">';
260 if (isset($alerts[$name])) {
261 if ($value > $alerts[$name]) {
262 $retval .= '<span class="attention">';
264 $retval .= '<span class="allfine">';
267 if ('%' === substr($name, -1, 1)) {
268 $retval .= htmlspecialchars(PMA_Util
::formatNumber($value, 0, 2)) . ' %';
269 } elseif (strpos($name, 'Uptime') !== false) {
270 $retval .= htmlspecialchars(
271 PMA_Util
::timespanFormat($value)
273 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
274 $retval .= '<abbr title="'
275 // makes available the raw value as a title
276 . htmlspecialchars(PMA_Util
::formatNumber($value, 0))
278 . htmlspecialchars(PMA_Util
::formatNumber($value, 3, 1));
279 } elseif (is_numeric($value) && $value == (int) $value) {
280 $retval .= htmlspecialchars(PMA_Util
::formatNumber($value, 3, 0));
281 } elseif (is_numeric($value)) {
282 $retval .= htmlspecialchars(PMA_Util
::formatNumber($value, 3, 1));
284 $retval .= htmlspecialchars($value);
286 if (isset($alerts[$name])) {
287 $retval .= '</span>';
289 $retval .= '</span>';
290 $retval .= '<span style="display:none;" class="original">';
292 $retval .= '</span>';
294 $retval .= '<td class="descr">';
296 if (isset($strShowStatus[$name])) {
297 $retval .= $strShowStatus[$name];
300 if (isset($ServerStatusData->links
[$name])) {
301 foreach ($ServerStatusData->links
[$name] as $link_name => $link_url) {
302 if ('doc' == $link_name) {
303 $retval .= PMA_Util
::showMySQLDocu($link_url, $link_url);
305 $retval .= ' <a href="' . $link_url . '">' . $link_name . '</a>';
308 unset($link_url, $link_name);
313 $retval .= '</tbody>';
314 $retval .= '</table>';
320 * Returns a list of variable descriptions
324 function getStatusVariablesDescriptions()
327 * Messages are built using the message name
330 'Aborted_clients' => __(
331 'The number of connections that were aborted because the client died'
332 . ' without closing the connection properly.'
334 'Aborted_connects' => __(
335 'The number of failed attempts to connect to the MySQL server.'
337 'Binlog_cache_disk_use' => __(
338 'The number of transactions that used the temporary binary log cache'
339 . ' but that exceeded the value of binlog_cache_size and used a'
340 . ' temporary file to store statements from the transaction.'
342 'Binlog_cache_use' => __(
343 'The number of transactions that used the temporary binary log cache.'
346 'The number of connection attempts (successful or not)'
347 . ' to the MySQL server.'
349 'Created_tmp_disk_tables' => __(
350 'The number of temporary tables on disk created automatically by'
351 . ' the server while executing statements. If'
352 . ' Created_tmp_disk_tables is big, you may want to increase the'
353 . ' tmp_table_size value to cause temporary tables to be'
354 . ' memory-based instead of disk-based.'
356 'Created_tmp_files' => __(
357 'How many temporary files mysqld has created.'
359 'Created_tmp_tables' => __(
360 'The number of in-memory temporary tables created automatically'
361 . ' by the server while executing statements.'
363 'Delayed_errors' => __(
364 'The number of rows written with INSERT DELAYED for which some'
365 . ' error occurred (probably duplicate key).'
367 'Delayed_insert_threads' => __(
368 'The number of INSERT DELAYED handler threads in use. Every'
369 . ' different table on which one uses INSERT DELAYED gets'
372 'Delayed_writes' => __(
373 'The number of INSERT DELAYED rows written.'
375 'Flush_commands' => __(
376 'The number of executed FLUSH statements.'
378 'Handler_commit' => __(
379 'The number of internal COMMIT statements.'
381 'Handler_delete' => __(
382 'The number of times a row was deleted from a table.'
384 'Handler_discover' => __(
385 'The MySQL server can ask the NDB Cluster storage engine if it'
386 . ' knows about a table with a given name. This is called discovery.'
387 . ' Handler_discover indicates the number of time tables have been'
390 'Handler_read_first' => __(
391 'The number of times the first entry was read from an index. If this'
392 . ' is high, it suggests that the server is doing a lot of full'
393 . ' index scans; for example, SELECT col1 FROM foo, assuming that'
394 . ' col1 is indexed.'
396 'Handler_read_key' => __(
397 'The number of requests to read a row based on a key. If this is'
398 . ' high, it is a good indication that your queries and tables'
399 . ' are properly indexed.'
401 'Handler_read_next' => __(
402 'The number of requests to read the next row in key order. This is'
403 . ' incremented if you are querying an index column with a range'
404 . ' constraint or if you are doing an index scan.'
406 'Handler_read_prev' => __(
407 'The number of requests to read the previous row in key order.'
408 . ' This read method is mainly used to optimize ORDER BY … DESC.'
410 'Handler_read_rnd' => __(
411 'The number of requests to read a row based on a fixed position.'
412 . ' This is high if you are doing a lot of queries that require'
413 . ' sorting of the result. You probably have a lot of queries that'
414 . ' require MySQL to scan whole tables or you have joins that'
415 . ' don\'t use keys properly.'
417 'Handler_read_rnd_next' => __(
418 'The number of requests to read the next row in the data file.'
419 . ' This is high if you are doing a lot of table scans. Generally'
420 . ' this suggests that your tables are not properly indexed or that'
421 . ' your queries are not written to take advantage of the indexes'
424 'Handler_rollback' => __(
425 'The number of internal ROLLBACK statements.'
427 'Handler_update' => __(
428 'The number of requests to update a row in a table.'
430 'Handler_write' => __(
431 'The number of requests to insert a row in a table.'
433 'Innodb_buffer_pool_pages_data' => __(
434 'The number of pages containing data (dirty or clean).'
436 'Innodb_buffer_pool_pages_dirty' => __(
437 'The number of pages currently dirty.'
439 'Innodb_buffer_pool_pages_flushed' => __(
440 'The number of buffer pool pages that have been requested'
443 'Innodb_buffer_pool_pages_free' => __(
444 'The number of free pages.'
446 'Innodb_buffer_pool_pages_latched' => __(
447 'The number of latched pages in InnoDB buffer pool. These are pages'
448 . ' currently being read or written or that can\'t be flushed or'
449 . ' removed for some other reason.'
451 'Innodb_buffer_pool_pages_misc' => __(
452 'The number of pages busy because they have been allocated for'
453 . ' administrative overhead such as row locks or the adaptive'
454 . ' hash index. This value can also be calculated as'
455 . ' Innodb_buffer_pool_pages_total - Innodb_buffer_pool_pages_free'
456 . ' - Innodb_buffer_pool_pages_data.'
458 'Innodb_buffer_pool_pages_total' => __(
459 'Total size of buffer pool, in pages.'
461 'Innodb_buffer_pool_read_ahead_rnd' => __(
462 'The number of "random" read-aheads InnoDB initiated. This happens'
463 . ' when a query is to scan a large portion of a table but in'
466 'Innodb_buffer_pool_read_ahead_seq' => __(
467 'The number of sequential read-aheads InnoDB initiated. This'
468 . ' happens when InnoDB does a sequential full table scan.'
470 'Innodb_buffer_pool_read_requests' => __(
471 'The number of logical read requests InnoDB has done.'
473 'Innodb_buffer_pool_reads' => __(
474 'The number of logical reads that InnoDB could not satisfy'
475 . ' from buffer pool and had to do a single-page read.'
477 'Innodb_buffer_pool_wait_free' => __(
478 'Normally, writes to the InnoDB buffer pool happen in the'
479 . ' background. However, if it\'s necessary to read or create a page'
480 . ' and no clean pages are available, it\'s necessary to wait for'
481 . ' pages to be flushed first. This counter counts instances of'
482 . ' these waits. If the buffer pool size was set properly, this'
483 . ' value should be small.'
485 'Innodb_buffer_pool_write_requests' => __(
486 'The number writes done to the InnoDB buffer pool.'
488 'Innodb_data_fsyncs' => __(
489 'The number of fsync() operations so far.'
491 'Innodb_data_pending_fsyncs' => __(
492 'The current number of pending fsync() operations.'
494 'Innodb_data_pending_reads' => __(
495 'The current number of pending reads.'
497 'Innodb_data_pending_writes' => __(
498 'The current number of pending writes.'
500 'Innodb_data_read' => __(
501 'The amount of data read so far, in bytes.'
503 'Innodb_data_reads' => __(
504 'The total number of data reads.'
506 'Innodb_data_writes' => __(
507 'The total number of data writes.'
509 'Innodb_data_written' => __(
510 'The amount of data written so far, in bytes.'
512 'Innodb_dblwr_pages_written' => __(
513 'The number of pages that have been written for'
514 . ' doublewrite operations.'
516 'Innodb_dblwr_writes' => __(
517 'The number of doublewrite operations that have been performed.'
519 'Innodb_log_waits' => __(
520 'The number of waits we had because log buffer was too small and'
521 . ' we had to wait for it to be flushed before continuing.'
523 'Innodb_log_write_requests' => __(
524 'The number of log write requests.'
526 'Innodb_log_writes' => __(
527 'The number of physical writes to the log file.'
529 'Innodb_os_log_fsyncs' => __(
530 'The number of fsync() writes done to the log file.'
532 'Innodb_os_log_pending_fsyncs' => __(
533 'The number of pending log file fsyncs.'
535 'Innodb_os_log_pending_writes' => __(
536 'Pending log file writes.'
538 'Innodb_os_log_written' => __(
539 'The number of bytes written to the log file.'
541 'Innodb_pages_created' => __(
542 'The number of pages created.'
544 'Innodb_page_size' => __(
545 'The compiled-in InnoDB page size (default 16KB). Many values are'
546 . ' counted in pages; the page size allows them to be easily'
547 . ' converted to bytes.'
549 'Innodb_pages_read' => __(
550 'The number of pages read.'
552 'Innodb_pages_written' => __(
553 'The number of pages written.'
555 'Innodb_row_lock_current_waits' => __(
556 'The number of row locks currently being waited for.'
558 'Innodb_row_lock_time_avg' => __(
559 'The average time to acquire a row lock, in milliseconds.'
561 'Innodb_row_lock_time' => __(
562 'The total time spent in acquiring row locks, in milliseconds.'
564 'Innodb_row_lock_time_max' => __(
565 'The maximum time to acquire a row lock, in milliseconds.'
567 'Innodb_row_lock_waits' => __(
568 'The number of times a row lock had to be waited for.'
570 'Innodb_rows_deleted' => __(
571 'The number of rows deleted from InnoDB tables.'
573 'Innodb_rows_inserted' => __(
574 'The number of rows inserted in InnoDB tables.'
576 'Innodb_rows_read' => __(
577 'The number of rows read from InnoDB tables.'
579 'Innodb_rows_updated' => __(
580 'The number of rows updated in InnoDB tables.'
582 'Key_blocks_not_flushed' => __(
583 'The number of key blocks in the key cache that have changed but'
584 . ' haven\'t yet been flushed to disk. It used to be known as'
585 . ' Not_flushed_key_blocks.'
587 'Key_blocks_unused' => __(
588 'The number of unused blocks in the key cache. You can use this'
589 . ' value to determine how much of the key cache is in use.'
591 'Key_blocks_used' => __(
592 'The number of used blocks in the key cache. This value is a'
593 . ' high-water mark that indicates the maximum number of blocks'
594 . ' that have ever been in use at one time.'
596 'Key_buffer_fraction_%' => __(
597 'Percentage of used key cache (calculated value)'
599 'Key_read_requests' => __(
600 'The number of requests to read a key block from the cache.'
603 'The number of physical reads of a key block from disk. If Key_reads'
604 . ' is big, then your key_buffer_size value is probably too small.'
605 . ' The cache miss rate can be calculated as'
606 . ' Key_reads/Key_read_requests.'
608 'Key_read_ratio_%' => __(
609 'Key cache miss calculated as rate of physical reads compared'
610 . ' to read requests (calculated value)'
612 'Key_write_requests' => __(
613 'The number of requests to write a key block to the cache.'
616 'The number of physical writes of a key block to disk.'
618 'Key_write_ratio_%' => __(
619 'Percentage of physical writes compared'
620 . ' to write requests (calculated value)'
622 'Last_query_cost' => __(
623 'The total cost of the last compiled query as computed by the query'
624 . ' optimizer. Useful for comparing the cost of different query'
625 . ' plans for the same query. The default value of 0 means that'
626 . ' no query has been compiled yet.'
628 'Max_used_connections' => __(
629 'The maximum number of connections that have been in use'
630 . ' simultaneously since the server started.'
632 'Not_flushed_delayed_rows' => __(
633 'The number of rows waiting to be written in INSERT DELAYED queues.'
635 'Opened_tables' => __(
636 'The number of tables that have been opened. If opened tables is'
637 . ' big, your table cache value is probably too small.'
640 'The number of files that are open.'
642 'Open_streams' => __(
643 'The number of streams that are open (used mainly for logging).'
646 'The number of tables that are open.'
648 'Qcache_free_blocks' => __(
649 'The number of free memory blocks in query cache. High numbers can'
650 . ' indicate fragmentation issues, which may be solved by issuing'
651 . ' a FLUSH QUERY CACHE statement.'
653 'Qcache_free_memory' => __(
654 'The amount of free memory for query cache.'
657 'The number of cache hits.'
659 'Qcache_inserts' => __(
660 'The number of queries added to the cache.'
662 'Qcache_lowmem_prunes' => __(
663 'The number of queries that have been removed from the cache to'
664 . ' free up memory for caching new queries. This information can'
665 . ' help you tune the query cache size. The query cache uses a'
666 . ' least recently used (LRU) strategy to decide which queries'
667 . ' to remove from the cache.'
669 'Qcache_not_cached' => __(
670 'The number of non-cached queries (not cachable, or not cached'
671 . ' due to the query_cache_type setting).'
673 'Qcache_queries_in_cache' => __(
674 'The number of queries registered in the cache.'
676 'Qcache_total_blocks' => __(
677 'The total number of blocks in the query cache.'
680 'The status of failsafe replication (not yet implemented).'
682 'Select_full_join' => __(
683 'The number of joins that do not use indexes. If this value is'
684 . ' not 0, you should carefully check the indexes of your tables.'
686 'Select_full_range_join' => __(
687 'The number of joins that used a range search on a reference table.'
689 'Select_range_check' => __(
690 'The number of joins without keys that check for key usage after'
691 . ' each row. (If this is not 0, you should carefully check the'
692 . ' indexes of your tables.)'
694 'Select_range' => __(
695 'The number of joins that used ranges on the first table. (It\'s'
696 . ' normally not critical even if this is big.)'
699 'The number of joins that did a full scan of the first table.'
701 'Slave_open_temp_tables' => __(
702 'The number of temporary tables currently'
703 . ' open by the slave SQL thread.'
705 'Slave_retried_transactions' => __(
706 'Total (since startup) number of times the replication slave SQL'
707 . ' thread has retried transactions.'
709 'Slave_running' => __(
710 'This is ON if this server is a slave that is connected to a master.'
712 'Slow_launch_threads' => __(
713 'The number of threads that have taken more than slow_launch_time'
714 . ' seconds to create.'
716 'Slow_queries' => __(
717 'The number of queries that have taken more than long_query_time'
720 'Sort_merge_passes' => __(
721 'The number of merge passes the sort algorithm has had to do.'
722 . ' If this value is large, you should consider increasing the'
723 . ' value of the sort_buffer_size system variable.'
726 'The number of sorts that were done with ranges.'
729 'The number of sorted rows.'
732 'The number of sorts that were done by scanning the table.'
734 'Table_locks_immediate' => __(
735 'The number of times that a table lock was acquired immediately.'
737 'Table_locks_waited' => __(
738 'The number of times that a table lock could not be acquired'
739 . ' immediately and a wait was needed. If this is high, and you have'
740 . ' performance problems, you should first optimize your queries,'
741 . ' and then either split your table or tables or use replication.'
743 'Threads_cached' => __(
744 'The number of threads in the thread cache. The cache hit rate can'
745 . ' be calculated as Threads_created/Connections. If this value is'
746 . ' red you should raise your thread_cache_size.'
748 'Threads_connected' => __(
749 'The number of currently open connections.'
751 'Threads_created' => __(
752 'The number of threads created to handle connections. If'
753 . ' Threads_created is big, you may want to increase the'
754 . ' thread_cache_size value. (Normally this doesn\'t give a notable'
755 . ' performance improvement if you have a good thread'
756 . ' implementation.)'
758 'Threads_cache_hitrate_%' => __(
759 'Thread cache hit rate (calculated value)'
761 'Threads_running' => __(
762 'The number of threads that are not sleeping.'