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(PMA_getFilterHtml($ServerStatusData));
48 $response->addHTML(PMA_getLinkSuggestionsHtml($ServerStatusData));
49 $response->addHTML(PMA_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 PMA_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 PMA_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 PMA_getVariablesTableHtml($ServerStatusData)
167 $strShowStatus = PMA_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 > 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))
280 } elseif (is_numeric($value)) {
281 $retval .= htmlspecialchars(PMA_Util
::formatNumber($value, 3, 1));
283 $retval .= htmlspecialchars($value);
285 if (isset($alerts[$name])) {
286 $retval .= '</span>';
288 $retval .= '</span>';
289 $retval .= '<span style="display:none;" class="original">';
291 $retval .= '</span>';
293 $retval .= '<td class="descr">';
295 if (isset($strShowStatus[$name])) {
296 $retval .= $strShowStatus[$name];
299 if (isset($ServerStatusData->links
[$name])) {
300 foreach ($ServerStatusData->links
[$name] as $link_name => $link_url) {
301 if ('doc' == $link_name) {
302 $retval .= PMA_Util
::showMySQLDocu($link_url, $link_url);
304 $retval .= ' <a href="' . $link_url . '">' . $link_name . '</a>';
307 unset($link_url, $link_name);
312 $retval .= '</tbody>';
313 $retval .= '</table>';
319 * Returns a list of variable descriptions
323 function PMA_getStatusVariablesDescriptions()
326 * Messages are built using the message name
329 'Aborted_clients' => __(
330 'The number of connections that were aborted because the client died'
331 . ' without closing the connection properly.'
333 'Aborted_connects' => __(
334 'The number of failed attempts to connect to the MySQL server.'
336 'Binlog_cache_disk_use' => __(
337 'The number of transactions that used the temporary binary log cache'
338 . ' but that exceeded the value of binlog_cache_size and used a'
339 . ' temporary file to store statements from the transaction.'
341 'Binlog_cache_use' => __(
342 'The number of transactions that used the temporary binary log cache.'
345 'The number of connection attempts (successful or not)'
346 . ' to the MySQL server.'
348 'Created_tmp_disk_tables' => __(
349 'The number of temporary tables on disk created automatically by'
350 . ' the server while executing statements. If'
351 . ' Created_tmp_disk_tables is big, you may want to increase the'
352 . ' tmp_table_size value to cause temporary tables to be'
353 . ' memory-based instead of disk-based.'
355 'Created_tmp_files' => __(
356 'How many temporary files mysqld has created.'
358 'Created_tmp_tables' => __(
359 'The number of in-memory temporary tables created automatically'
360 . ' by the server while executing statements.'
362 'Delayed_errors' => __(
363 'The number of rows written with INSERT DELAYED for which some'
364 . ' error occurred (probably duplicate key).'
366 'Delayed_insert_threads' => __(
367 'The number of INSERT DELAYED handler threads in use. Every'
368 . ' different table on which one uses INSERT DELAYED gets'
371 'Delayed_writes' => __(
372 'The number of INSERT DELAYED rows written.'
374 'Flush_commands' => __(
375 'The number of executed FLUSH statements.'
377 'Handler_commit' => __(
378 'The number of internal COMMIT statements.'
380 'Handler_delete' => __(
381 'The number of times a row was deleted from a table.'
383 'Handler_discover' => __(
384 'The MySQL server can ask the NDB Cluster storage engine if it'
385 . ' knows about a table with a given name. This is called discovery.'
386 . ' Handler_discover indicates the number of time tables have been'
389 'Handler_read_first' => __(
390 'The number of times the first entry was read from an index. If this'
391 . ' is high, it suggests that the server is doing a lot of full'
392 . ' index scans; for example, SELECT col1 FROM foo, assuming that'
393 . ' col1 is indexed.'
395 'Handler_read_key' => __(
396 'The number of requests to read a row based on a key. If this is'
397 . ' high, it is a good indication that your queries and tables'
398 . ' are properly indexed.'
400 'Handler_read_next' => __(
401 'The number of requests to read the next row in key order. This is'
402 . ' incremented if you are querying an index column with a range'
403 . ' constraint or if you are doing an index scan.'
405 'Handler_read_prev' => __(
406 'The number of requests to read the previous row in key order.'
407 . ' This read method is mainly used to optimize ORDER BY … DESC.'
409 'Handler_read_rnd' => __(
410 'The number of requests to read a row based on a fixed position.'
411 . ' This is high if you are doing a lot of queries that require'
412 . ' sorting of the result. You probably have a lot of queries that'
413 . ' require MySQL to scan whole tables or you have joins that'
414 . ' don\'t use keys properly.'
416 'Handler_read_rnd_next' => __(
417 'The number of requests to read the next row in the data file.'
418 . ' This is high if you are doing a lot of table scans. Generally'
419 . ' this suggests that your tables are not properly indexed or that'
420 . ' your queries are not written to take advantage of the indexes'
423 'Handler_rollback' => __(
424 'The number of internal ROLLBACK statements.'
426 'Handler_update' => __(
427 'The number of requests to update a row in a table.'
429 'Handler_write' => __(
430 'The number of requests to insert a row in a table.'
432 'Innodb_buffer_pool_pages_data' => __(
433 'The number of pages containing data (dirty or clean).'
435 'Innodb_buffer_pool_pages_dirty' => __(
436 'The number of pages currently dirty.'
438 'Innodb_buffer_pool_pages_flushed' => __(
439 'The number of buffer pool pages that have been requested'
442 'Innodb_buffer_pool_pages_free' => __(
443 'The number of free pages.'
445 'Innodb_buffer_pool_pages_latched' => __(
446 'The number of latched pages in InnoDB buffer pool. These are pages'
447 . ' currently being read or written or that can\'t be flushed or'
448 . ' removed for some other reason.'
450 'Innodb_buffer_pool_pages_misc' => __(
451 'The number of pages busy because they have been allocated for'
452 . ' administrative overhead such as row locks or the adaptive'
453 . ' hash index. This value can also be calculated as'
454 . ' Innodb_buffer_pool_pages_total - Innodb_buffer_pool_pages_free'
455 . ' - Innodb_buffer_pool_pages_data.'
457 'Innodb_buffer_pool_pages_total' => __(
458 'Total size of buffer pool, in pages.'
460 'Innodb_buffer_pool_read_ahead_rnd' => __(
461 'The number of "random" read-aheads InnoDB initiated. This happens'
462 . ' when a query is to scan a large portion of a table but in'
465 'Innodb_buffer_pool_read_ahead_seq' => __(
466 'The number of sequential read-aheads InnoDB initiated. This'
467 . ' happens when InnoDB does a sequential full table scan.'
469 'Innodb_buffer_pool_read_requests' => __(
470 'The number of logical read requests InnoDB has done.'
472 'Innodb_buffer_pool_reads' => __(
473 'The number of logical reads that InnoDB could not satisfy'
474 . ' from buffer pool and had to do a single-page read.'
476 'Innodb_buffer_pool_wait_free' => __(
477 'Normally, writes to the InnoDB buffer pool happen in the'
478 . ' background. However, if it\'s necessary to read or create a page'
479 . ' and no clean pages are available, it\'s necessary to wait for'
480 . ' pages to be flushed first. This counter counts instances of'
481 . ' these waits. If the buffer pool size was set properly, this'
482 . ' value should be small.'
484 'Innodb_buffer_pool_write_requests' => __(
485 'The number writes done to the InnoDB buffer pool.'
487 'Innodb_data_fsyncs' => __(
488 'The number of fsync() operations so far.'
490 'Innodb_data_pending_fsyncs' => __(
491 'The current number of pending fsync() operations.'
493 'Innodb_data_pending_reads' => __(
494 'The current number of pending reads.'
496 'Innodb_data_pending_writes' => __(
497 'The current number of pending writes.'
499 'Innodb_data_read' => __(
500 'The amount of data read so far, in bytes.'
502 'Innodb_data_reads' => __(
503 'The total number of data reads.'
505 'Innodb_data_writes' => __(
506 'The total number of data writes.'
508 'Innodb_data_written' => __(
509 'The amount of data written so far, in bytes.'
511 'Innodb_dblwr_pages_written' => __(
512 'The number of pages that have been written for'
513 . ' doublewrite operations.'
515 'Innodb_dblwr_writes' => __(
516 'The number of doublewrite operations that have been performed.'
518 'Innodb_log_waits' => __(
519 'The number of waits we had because log buffer was too small and'
520 . ' we had to wait for it to be flushed before continuing.'
522 'Innodb_log_write_requests' => __(
523 'The number of log write requests.'
525 'Innodb_log_writes' => __(
526 'The number of physical writes to the log file.'
528 'Innodb_os_log_fsyncs' => __(
529 'The number of fsync() writes done to the log file.'
531 'Innodb_os_log_pending_fsyncs' => __(
532 'The number of pending log file fsyncs.'
534 'Innodb_os_log_pending_writes' => __(
535 'Pending log file writes.'
537 'Innodb_os_log_written' => __(
538 'The number of bytes written to the log file.'
540 'Innodb_pages_created' => __(
541 'The number of pages created.'
543 'Innodb_page_size' => __(
544 'The compiled-in InnoDB page size (default 16KB). Many values are'
545 . ' counted in pages; the page size allows them to be easily'
546 . ' converted to bytes.'
548 'Innodb_pages_read' => __(
549 'The number of pages read.'
551 'Innodb_pages_written' => __(
552 'The number of pages written.'
554 'Innodb_row_lock_current_waits' => __(
555 'The number of row locks currently being waited for.'
557 'Innodb_row_lock_time_avg' => __(
558 'The average time to acquire a row lock, in milliseconds.'
560 'Innodb_row_lock_time' => __(
561 'The total time spent in acquiring row locks, in milliseconds.'
563 'Innodb_row_lock_time_max' => __(
564 'The maximum time to acquire a row lock, in milliseconds.'
566 'Innodb_row_lock_waits' => __(
567 'The number of times a row lock had to be waited for.'
569 'Innodb_rows_deleted' => __(
570 'The number of rows deleted from InnoDB tables.'
572 'Innodb_rows_inserted' => __(
573 'The number of rows inserted in InnoDB tables.'
575 'Innodb_rows_read' => __(
576 'The number of rows read from InnoDB tables.'
578 'Innodb_rows_updated' => __(
579 'The number of rows updated in InnoDB tables.'
581 'Key_blocks_not_flushed' => __(
582 'The number of key blocks in the key cache that have changed but'
583 . ' haven\'t yet been flushed to disk. It used to be known as'
584 . ' Not_flushed_key_blocks.'
586 'Key_blocks_unused' => __(
587 'The number of unused blocks in the key cache. You can use this'
588 . ' value to determine how much of the key cache is in use.'
590 'Key_blocks_used' => __(
591 'The number of used blocks in the key cache. This value is a'
592 . ' high-water mark that indicates the maximum number of blocks'
593 . ' that have ever been in use at one time.'
595 'Key_buffer_fraction_%' => __(
596 'Percentage of used key cache (calculated value)'
598 'Key_read_requests' => __(
599 'The number of requests to read a key block from the cache.'
602 'The number of physical reads of a key block from disk. If Key_reads'
603 . ' is big, then your key_buffer_size value is probably too small.'
604 . ' The cache miss rate can be calculated as'
605 . ' Key_reads/Key_read_requests.'
607 'Key_read_ratio_%' => __(
608 'Key cache miss calculated as rate of physical reads compared'
609 . ' to read requests (calculated value)'
611 'Key_write_requests' => __(
612 'The number of requests to write a key block to the cache.'
615 'The number of physical writes of a key block to disk.'
617 'Key_write_ratio_%' => __(
618 'Percentage of physical writes compared'
619 . ' to write requests (calculated value)'
621 'Last_query_cost' => __(
622 'The total cost of the last compiled query as computed by the query'
623 . ' optimizer. Useful for comparing the cost of different query'
624 . ' plans for the same query. The default value of 0 means that'
625 . ' no query has been compiled yet.'
627 'Max_used_connections' => __(
628 'The maximum number of connections that have been in use'
629 . ' simultaneously since the server started.'
631 'Not_flushed_delayed_rows' => __(
632 'The number of rows waiting to be written in INSERT DELAYED queues.'
634 'Opened_tables' => __(
635 'The number of tables that have been opened. If opened tables is'
636 . ' big, your table cache value is probably too small.'
639 'The number of files that are open.'
641 'Open_streams' => __(
642 'The number of streams that are open (used mainly for logging).'
645 'The number of tables that are open.'
647 'Qcache_free_blocks' => __(
648 'The number of free memory blocks in query cache. High numbers can'
649 . ' indicate fragmentation issues, which may be solved by issuing'
650 . ' a FLUSH QUERY CACHE statement.'
652 'Qcache_free_memory' => __(
653 'The amount of free memory for query cache.'
656 'The number of cache hits.'
658 'Qcache_inserts' => __(
659 'The number of queries added to the cache.'
661 'Qcache_lowmem_prunes' => __(
662 'The number of queries that have been removed from the cache to'
663 . ' free up memory for caching new queries. This information can'
664 . ' help you tune the query cache size. The query cache uses a'
665 . ' least recently used (LRU) strategy to decide which queries'
666 . ' to remove from the cache.'
668 'Qcache_not_cached' => __(
669 'The number of non-cached queries (not cachable, or not cached'
670 . ' due to the query_cache_type setting).'
672 'Qcache_queries_in_cache' => __(
673 'The number of queries registered in the cache.'
675 'Qcache_total_blocks' => __(
676 'The total number of blocks in the query cache.'
679 'The status of failsafe replication (not yet implemented).'
681 'Select_full_join' => __(
682 'The number of joins that do not use indexes. If this value is'
683 . ' not 0, you should carefully check the indexes of your tables.'
685 'Select_full_range_join' => __(
686 'The number of joins that used a range search on a reference table.'
688 'Select_range_check' => __(
689 'The number of joins without keys that check for key usage after'
690 . ' each row. (If this is not 0, you should carefully check the'
691 . ' indexes of your tables.)'
693 'Select_range' => __(
694 'The number of joins that used ranges on the first table. (It\'s'
695 . ' normally not critical even if this is big.)'
698 'The number of joins that did a full scan of the first table.'
700 'Slave_open_temp_tables' => __(
701 'The number of temporary tables currently'
702 . ' open by the slave SQL thread.'
704 'Slave_retried_transactions' => __(
705 'Total (since startup) number of times the replication slave SQL'
706 . ' thread has retried transactions.'
708 'Slave_running' => __(
709 'This is ON if this server is a slave that is connected to a master.'
711 'Slow_launch_threads' => __(
712 'The number of threads that have taken more than slow_launch_time'
713 . ' seconds to create.'
715 'Slow_queries' => __(
716 'The number of queries that have taken more than long_query_time'
719 'Sort_merge_passes' => __(
720 'The number of merge passes the sort algorithm has had to do.'
721 . ' If this value is large, you should consider increasing the'
722 . ' value of the sort_buffer_size system variable.'
725 'The number of sorts that were done with ranges.'
728 'The number of sorted rows.'
731 'The number of sorts that were done by scanning the table.'
733 'Table_locks_immediate' => __(
734 'The number of times that a table lock was acquired immediately.'
736 'Table_locks_waited' => __(
737 'The number of times that a table lock could not be acquired'
738 . ' immediately and a wait was needed. If this is high, and you have'
739 . ' performance problems, you should first optimize your queries,'
740 . ' and then either split your table or tables or use replication.'
742 'Threads_cached' => __(
743 'The number of threads in the thread cache. The cache hit rate can'
744 . ' be calculated as Threads_created/Connections. If this value is'
745 . ' red you should raise your thread_cache_size.'
747 'Threads_connected' => __(
748 'The number of currently open connections.'
750 'Threads_created' => __(
751 'The number of threads created to handle connections. If'
752 . ' Threads_created is big, you may want to increase the'
753 . ' thread_cache_size value. (Normally this doesn\'t give a notable'
754 . ' performance improvement if you have a good thread'
755 . ' implementation.)'
757 'Threads_cache_hitrate_%' => __(
758 'Thread cache hit rate (calculated value)'
760 'Threads_running' => __(
761 'The number of threads that are not sleeping.'