Add missing HTML escaping
[phpmyadmin.git] / server_status.php
blob9065fcea237370132dc101198001fdc1df7ddac1
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 * @package phpMyAdmin
8 */
10 /**
11 * no need for variables importing
12 * @ignore
14 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
15 define('PMA_NO_VARIABLES_IMPORT', true);
18 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true)
19 $GLOBALS['is_header_sent'] = true;
21 require_once './libraries/common.inc.php';
23 /**
24 * Function to output refresh rate selection.
26 function PMA_choose_refresh_rate() {
27 echo '<option value="5">' . __('Refresh rate') . '</option>';
28 foreach (array(1, 2, 5, 20, 40, 60, 120, 300, 600) as $rate) {
29 if ($rate % 60 == 0) {
30 $minrate = $rate / 60;
31 echo '<option value="' . $rate . '">' . sprintf(_ngettext('%d minute', '%d minutes', $minrate), $minrate) . '</option>';
32 } else {
33 echo '<option value="' . $rate . '">' . sprintf(_ngettext('%d second', '%d seconds', $rate), $rate) . '</option>';
38 /**
39 * Ajax request
42 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
43 // Send with correct charset
44 header('Content-Type: text/html; charset=UTF-8');
46 if (isset($_REQUEST['logging_vars'])) {
47 if (isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) {
48 $value = PMA_sqlAddslashes($_REQUEST['varValue']);
49 if (!is_numeric($value)) $value="'".$value."'";
51 if (!preg_match("/[^a-zA-Z0-9_]+/",$_REQUEST['varName']))
52 PMA_DBI_query('SET GLOBAL ' . $_REQUEST['varName'] . ' = '.$value);
56 $loggingVars = PMA_DBI_fetch_result(
57 "SHOW GLOBAL VARIABLES WHERE Variable_name IN (
58 'general_log', 'slow_query_log', 'long_query_time', 'log_output')", 0, 1);
59 exit(json_encode($loggingVars));
62 // real-time charting data
63 if (isset($_REQUEST['chart_data'])) {
64 switch($_REQUEST['type']) {
65 case 'proc':
66 $c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1);
67 $result = PMA_DBI_query('SHOW PROCESSLIST');
68 $num_procs = PMA_DBI_num_rows($result);
70 $ret = array(
71 'x' => microtime(true)*1000,
72 'y_proc' => $num_procs,
73 'y_conn' => $c['Connections']
76 exit(json_encode($ret));
78 case 'queries':
79 $queries = PMA_DBI_fetch_result(
80 "SHOW GLOBAL STATUS
81 WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions')
82 AND Value > 0'", 0, 1);
83 cleanDeprecated($queries);
84 // admin commands are not queries
85 unset($queries['Com_admin_commands']);
86 $questions = $queries['Questions'];
87 unset($queries['Questions']);
89 //$sum=array_sum($queries);
90 $ret = array(
91 'x' => microtime(true)*1000,
92 'y' => $questions,
93 'pointInfo' => $queries
96 exit(json_encode($ret));
98 case 'traffic':
99 $traffic = PMA_DBI_fetch_result(
100 "SHOW GLOBAL STATUS
101 WHERE Variable_name = 'Bytes_received'
102 OR Variable_name = 'Bytes_sent'", 0, 1);
104 $ret = array(
105 'x' => microtime(true)*1000,
106 'y_sent' => $traffic['Bytes_sent'],
107 'y_received' => $traffic['Bytes_received']
110 exit(json_encode($ret));
112 case 'chartgrid':
113 $ret = json_decode($_REQUEST['requiredData'], true);
114 $statusVars = array();
115 $sysinfo = $cpuload = $memory = 0;
117 foreach ($ret as $chart_id => $chartNodes) {
118 foreach ($chartNodes as $node_id => $node) {
119 switch ($node['dataType']) {
120 case 'statusvar':
121 // Some white list filtering
122 if (!preg_match('/[^a-zA-Z_]+/',$node['name']))
123 $statusVars[] = $node['name'];
124 break;
126 case 'proc':
127 $result = PMA_DBI_query('SHOW PROCESSLIST');
128 $ret[$chart_id][$node_id]['y'] = PMA_DBI_num_rows($result);
129 break;
131 case 'cpu':
132 if (!$sysinfo) {
133 require_once('libraries/sysinfo.lib.php');
134 $sysinfo = getSysInfo();
136 if (!$cpuload)
137 $cpuload = $sysinfo->loadavg();
139 if (PHP_OS == 'Linux') {
140 $ret[$chart_id][$node_id]['idle'] = $cpuload['idle'];
141 $ret[$chart_id][$node_id]['busy'] = $cpuload['busy'];
142 } else
143 $ret[$chart_id][$node_id]['y'] = $cpuload['loadavg'];
145 break;
147 case 'memory':
148 if (!$sysinfo) {
149 require_once('libraries/sysinfo.lib.php');
150 $sysinfo = getSysInfo();
152 if (!$memory)
153 $memory = $sysinfo->memory();
155 $ret[$chart_id][$node_id]['y'] = $memory[$node['name']];
156 break;
161 $vars = PMA_DBI_fetch_result(
162 "SHOW GLOBAL STATUS
163 WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1);
165 foreach ($ret as $chart_id => $chartNodes) {
166 foreach ($chartNodes as $node_id => $node) {
167 if ($node['dataType'] == 'statusvar')
168 $ret[$chart_id][$node_id]['y'] = $vars[$node['name']];
172 $ret['x'] = microtime(true)*1000;
174 exit(json_encode($ret));
178 if (isset($_REQUEST['log_data'])) {
179 $start = intval($_REQUEST['time_start']);
180 $end = intval($_REQUEST['time_end']);
182 if ($_REQUEST['type'] == 'slow') {
183 $q = 'SELECT SUM(query_time) AS TIME(query_time), SUM(lock_time) as lock_time, '.
184 'SUM(rows_sent) AS rows_sent, SUM(rows_examined) AS rows_examined, sql_text, COUNT(sql_text) AS \'#\' '.
185 'FROM `mysql`.`slow_log` WHERE event_time > FROM_UNIXTIME('.$start.') '.
186 'AND event_time < FROM_UNIXTIME('.$end.') GROUP BY sql_text';
188 $result = PMA_DBI_try_query($q);
190 $return = array('rows' => array(), 'sum' => array());
191 $type = '';
193 while ($row = PMA_DBI_fetch_assoc($result)) {
194 $type = substr($row['sql_text'],0,strpos($row['sql_text'],' '));
195 $return['sum'][$type]++;
196 $return['rows'][] = $row;
199 $return['sum']['TOTAL'] = array_sum($return['sum']);
201 PMA_DBI_free_result($result);
203 exit(json_encode($return));
206 if ($_REQUEST['type'] == 'general') {
207 $q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, server_id, argument, count(argument) as \'#\' FROM `mysql`.`general_log` WHERE command_type=\'Query\' '.
208 'AND event_time > FROM_UNIXTIME('.$start.') AND event_time < FROM_UNIXTIME('.$end.') '.
209 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' GROUP by argument'; // HAVING count > 1';
211 $result = PMA_DBI_try_query($q);
213 $return = array('rows' => array(), 'sum' => array());
214 $type = '';
215 $insertTables = array();
216 $insertTablesFirst = -1;
217 $i = 0;
219 while ($row = PMA_DBI_fetch_assoc($result)) {
220 preg_match('/^(\w+)\s/',$row['argument'],$match);
221 $type = strtolower($match[1]);
222 // Ignore undefined index warning, just increase counter by one
223 @$return['sum'][$type] += $row['#'];
225 if ($type=='insert' || $type=='update') {
226 // Group inserts if selected
227 if ($type=='insert' && isset($_REQUEST['groupInserts']) && $_REQUEST['groupInserts'] && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i',$row['argument'],$matches)) {
228 $insertTables[$matches[2]]++;
229 if ($insertTables[$matches[2]] > 1) {
230 $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
232 // Add a ... to the end of this query to indicate that there's been other queries
233 if ($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.')
234 $return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
236 // Group this value, thus do not add to the result list
237 continue;
238 } else {
239 $insertTablesFirst = $i;
240 $insertTables[$matches[2]] += $row['#'] - 1;
244 // Cut off big selects, but append byte count therefor
245 if (strlen($row['argument']) > 180) {
246 $row['argument'] = substr($row['argument'],0,160) . '... [' .
247 PMA_formatByteDown(strlen($row['argument']), 2).']';
250 $return['rows'][] = $row;
251 $i++;
254 $return['sum']['TOTAL'] = array_sum($return['sum']);
255 $return['numRows'] = count($return['rows']);
257 PMA_DBI_free_result($result);
259 exit(json_encode($return));
266 * Replication library
268 require './libraries/replication.inc.php';
269 require_once './libraries/replication_gui.lib.php';
272 * JS Includes
275 $GLOBALS['js_include'][] = 'server_status.js';
276 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
277 $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
278 $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
279 $GLOBALS['js_include'][] = 'jquery/jquery.json-2.2.js';
280 $GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
281 $GLOBALS['js_include'][] = 'jquery/jquery.sortableTable.js';
282 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
283 // Charting
284 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
285 /* Files required for chart exporting */
286 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
287 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
288 $GLOBALS['js_include'][] = 'canvg/canvg.js';
289 $GLOBALS['js_include'][] = 'canvg/rgbcolor.js';
292 * flush status variables if requested
294 if (isset($_REQUEST['flush'])) {
295 $_flush_commands = array(
296 'STATUS',
297 'TABLES',
298 'QUERY CACHE',
301 if (in_array($_REQUEST['flush'], $_flush_commands)) {
302 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
304 unset($_flush_commands);
308 * Kills a selected process
310 if (!empty($_REQUEST['kill'])) {
311 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
312 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
313 } else {
314 $message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
316 $message->addParam($_REQUEST['kill']);
317 //$message->display();
323 * get status from server
325 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
328 * for some calculations we require also some server settings
330 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
333 * cleanup of some deprecated values
335 cleanDeprecated($server_status);
338 * calculate some values
340 // Key_buffer_fraction
341 if (isset($server_status['Key_blocks_unused'])
342 && isset($server_variables['key_cache_block_size'])
343 && isset($server_variables['key_buffer_size'])) {
344 $server_status['Key_buffer_fraction_%'] =
346 - $server_status['Key_blocks_unused']
347 * $server_variables['key_cache_block_size']
348 / $server_variables['key_buffer_size']
349 * 100;
350 } elseif (isset($server_status['Key_blocks_used'])
351 && isset($server_variables['key_buffer_size'])) {
352 $server_status['Key_buffer_fraction_%'] =
353 $server_status['Key_blocks_used']
354 * 1024
355 / $server_variables['key_buffer_size'];
358 // Ratio for key read/write
359 if (isset($server_status['Key_writes'])
360 && isset($server_status['Key_write_requests'])
361 && $server_status['Key_write_requests'] > 0) {
362 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
365 if (isset($server_status['Key_reads'])
366 && isset($server_status['Key_read_requests'])
367 && $server_status['Key_read_requests'] > 0) {
368 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
371 // Threads_cache_hitrate
372 if (isset($server_status['Threads_created'])
373 && isset($server_status['Connections'])
374 && $server_status['Connections'] > 0) {
375 $server_status['Threads_cache_hitrate_%'] =
377 - $server_status['Threads_created']
378 / $server_status['Connections']
379 * 100;
382 // Format Uptime_since_flush_status : show as days, hours, minutes, seconds
383 if (isset($server_status['Uptime_since_flush_status'])) {
384 $server_status['Uptime_since_flush_status'] = PMA_timespanFormat($server_status['Uptime_since_flush_status']);
388 * split variables in sections
390 $allocations = array(
391 // variable name => section
392 // variable names match when they begin with the given string
394 'Com_' => 'com',
395 'Innodb_' => 'innodb',
396 'Ndb_' => 'ndb',
397 'Handler_' => 'handler',
398 'Qcache_' => 'qcache',
399 'Threads_' => 'threads',
400 'Slow_launch_threads' => 'threads',
402 'Binlog_cache_' => 'binlog_cache',
403 'Created_tmp_' => 'created_tmp',
404 'Key_' => 'key',
406 'Delayed_' => 'delayed',
407 'Not_flushed_delayed_rows' => 'delayed',
409 'Flush_commands' => 'query',
410 'Last_query_cost' => 'query',
411 'Slow_queries' => 'query',
412 'Queries' => 'query',
413 'Prepared_stmt_count' => 'query',
415 'Select_' => 'select',
416 'Sort_' => 'sort',
418 'Open_tables' => 'table',
419 'Opened_tables' => 'table',
420 'Open_table_definitions' => 'table',
421 'Opened_table_definitions' => 'table',
422 'Table_locks_' => 'table',
424 'Rpl_status' => 'repl',
425 'Slave_' => 'repl',
427 'Tc_' => 'tc',
429 'Ssl_' => 'ssl',
431 'Open_files' => 'files',
432 'Open_streams' => 'files',
433 'Opened_files' => 'files',
436 $sections = array(
437 // section => section name (description)
438 'com' => 'Com',
439 'query' => __('SQL query'),
440 'innodb' => 'InnoDB',
441 'ndb' => 'NDB',
442 'handler' => __('Handler'),
443 'qcache' => __('Query cache'),
444 'threads' => __('Threads'),
445 'binlog_cache' => __('Binary log'),
446 'created_tmp' => __('Temporary data'),
447 'delayed' => __('Delayed inserts'),
448 'key' => __('Key cache'),
449 'select' => __('Joins'),
450 'repl' => __('Replication'),
451 'sort' => __('Sorting'),
452 'table' => __('Tables'),
453 'tc' => __('Transaction coordinator'),
454 'files' => __('Files'),
455 'ssl' => 'SSL',
459 * define some needfull links/commands
461 // variable or section name => (name => url)
462 $links = array();
464 $links['table'][__('Flush (close) all tables')]
465 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
466 $links['table'][__('Show open tables')]
467 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
468 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
470 if ($server_master_status) {
471 $links['repl'][__('Show slave hosts')]
472 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
473 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
474 $links['repl'][__('Show master status')] = '#replication_master';
476 if ($server_slave_status) {
477 $links['repl'][__('Show slave status')] = '#replication_slave';
480 $links['repl']['doc'] = 'replication';
482 $links['qcache'][__('Flush query cache')]
483 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
484 PMA_generate_common_url();
485 $links['qcache']['doc'] = 'query_cache';
487 //$links['threads'][__('Show processes')]
488 // = 'server_processlist.php?' . PMA_generate_common_url();
489 $links['threads']['doc'] = 'mysql_threads';
491 $links['key']['doc'] = 'myisam_key_cache';
493 $links['binlog_cache']['doc'] = 'binary_log';
495 $links['Slow_queries']['doc'] = 'slow_query_log';
497 $links['innodb'][__('Variables')]
498 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
499 $links['innodb'][__('InnoDB Status')]
500 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
501 PMA_generate_common_url();
502 $links['innodb']['doc'] = 'innodb';
505 // Variable to contain all com_ variables
506 $used_queries = array();
508 // Variable to map variable names to their respective section name (used for js category filtering)
509 $allocationMap = array();
511 // sort vars into arrays
512 foreach ($server_status as $name => $value) {
513 foreach ($allocations as $filter => $section) {
514 if (strpos($name, $filter) !== false) {
515 $allocationMap[$name] = $section;
516 if ($section == 'com' && $value > 0) $used_queries[$name] = $value;
517 break; // Only exits inner loop
522 // admin commands are not queries (e.g. they include COM_PING, which is excluded from $server_status['Questions'])
523 unset($used_queries['Com_admin_commands']);
525 /* Ajax request refresh */
526 if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
527 switch($_REQUEST['show']) {
528 case 'query_statistics':
529 printQueryStatistics();
530 exit();
531 case 'server_traffic':
532 printServerTraffic();
533 exit();
534 case 'variables_table':
535 // Prints the variables table
536 printVariablesTable();
537 exit();
539 default:
540 break;
545 * start output
549 * Does the common work
551 require './libraries/server_common.inc.php';
555 * Displays the links
557 require './libraries/server_links.inc.php';
559 $server = 1;
560 if (isset($_REQUEST['server']) && intval($_REQUEST['server'])) $server = intval($_REQUEST['server']);
562 $server_db_isLocal = strtolower($cfg['Servers'][$server]['host']) == 'localhost'
563 || $cfg['Servers'][$server]['host'] == '127.0.0.1'
564 || $cfg['Servers'][$server]['host'] == '::1';
567 <script type="text/javascript">
568 pma_token = '<?php echo $_SESSION[' PMA_token ']; ?>';
569 url_query = '<?php echo str_replace('&amp;','&',$url_query);?>';
570 server_time_diff = new Date().getTime() - <?php echo microtime(true)*1000; ?>;
571 server_os = '<?php echo PHP_OS; ?>';
572 is_superuser = <?php echo PMA_isSuperuser()?'true':'false'; ?>;
573 server_db_isLocal = <?php echo ($server_db_isLocal)?'true':'false'; ?>;
574 </script>
575 <div id="serverstatus">
576 <h2><?php
578 * Displays the sub-page heading
580 if ($GLOBALS['cfg']['MainPageIconic']) {
581 echo '<img class="icon ic_s_status" src="themes/dot.gif" width="16" height="16" alt="" />';
584 echo __('Runtime Information');
586 ?></h2>
587 <div id="serverStatusTabs">
588 <ul>
589 <li><a href="#statustabs_traffic"><?php echo __('Server'); ?></a></li>
590 <li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
591 <li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
592 <li><a href="#statustabs_charting"><?php echo __('Monitor'); ?></a></li>
593 </ul>
595 <div id="statustabs_traffic">
596 <div class="buttonlinks">
597 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&amp;' . PMA_generate_common_url(); ?>" >
598 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
599 <?php echo __('Refresh'); ?>
600 </a>
601 <span class="refreshList" style="display:none;">
602 <label for="trafficChartRefresh"><?php echo __('Refresh rate: '); ?></label>
603 <?php refreshList('trafficChartRefresh'); ?>
604 </span>
606 <a class="tabChart livetrafficLink" href="#">
607 <?php echo __('Live traffic chart'); ?>
608 </a>
609 <a class="tabChart liveconnectionsLink" href="#">
610 <?php echo __('Live conn./process chart'); ?>
611 </a>
612 </div>
613 <div class="tabInnerContent">
614 <?php printServerTraffic(); ?>
615 </div>
616 </div>
617 <div id="statustabs_queries">
618 <div class="buttonlinks">
619 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
620 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
621 <?php echo __('Refresh'); ?>
622 </a>
623 <span class="refreshList" style="display:none;">
624 <label for="queryChartRefresh"><?php echo __('Refresh rate: '); ?></label>
625 <?php refreshList('queryChartRefresh'); ?>
626 </span>
627 <a class="tabChart livequeriesLink" href="#">
628 <?php echo __('Live query chart'); ?>
629 </a>
630 </div>
631 <div class="tabInnerContent">
632 <?php printQueryStatistics(); ?>
633 </div>
634 </div>
635 <div id="statustabs_allvars">
636 <fieldset id="tableFilter">
637 <div class="buttonlinks">
638 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
639 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
640 <?php echo __('Refresh'); ?>
641 </a>
642 </div>
643 <legend>Filters</legend>
644 <div class="formelement">
645 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
646 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
647 </div>
648 <div class="formelement">
649 <input type="checkbox" name="filterAlert" id="filterAlert">
650 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
651 </div>
652 <div class="formelement">
653 <select id="filterCategory" name="filterCategory">
654 <option value=''><?php echo __('Filter by category...'); ?></option>
655 <?php
656 foreach ($sections as $section_id => $section_name) {
658 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
659 <?php
663 </select>
664 </div>
665 </fieldset>
666 <div id="linkSuggestions" class="defaultLinks" style="display:none">
667 <p class="notice"><?php echo __('Related links:'); ?>
668 <?php
669 foreach ($links as $section_name => $section_links) {
670 echo '<span class="status_'.$section_name.'"> ';
671 $i=0;
672 foreach ($section_links as $link_name => $link_url) {
673 if ($i > 0) echo ', ';
674 if ('doc' == $link_name) {
675 echo PMA_showMySQLDocu($link_url, $link_url);
676 } else {
677 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
679 $i++;
681 echo '</span>';
683 unset($link_url, $link_name, $i);
685 </p>
686 </div>
687 <div class="tabInnerContent">
688 <?php printVariablesTable(); ?>
689 </div>
690 </div>
692 <div id="statustabs_charting">
693 <?php printMonitor(); ?>
694 </div>
695 </div>
696 </div>
698 <?php
700 function printQueryStatistics() {
701 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
703 $hour_factor = 3600 / $server_status['Uptime'];
705 $total_queries = array_sum($used_queries);
708 <h3 id="serverstatusqueries">
709 <?php
710 /* l10n: Questions is the name of a MySQL Status variable */
711 echo sprintf(__('Questions since startup: %s'),PMA_formatNumber($total_queries, 0)) . ' ';
712 echo PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_Questions');
714 <br>
715 <span>
716 <?php
717 echo '&oslash; '.__('per hour').': ';
718 echo PMA_formatNumber($total_queries * $hour_factor, 0);
719 echo '<br>';
721 echo '&oslash; '.__('per minute').': ';
722 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
723 echo '<br>';
725 if ($total_queries / $server_status['Uptime'] >= 1) {
726 echo '&oslash; '.__('per second').': ';
727 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
730 </span>
731 </h3>
732 <?php
734 // reverse sort by value to show most used statements first
735 arsort($used_queries);
737 $odd_row = true;
738 $count_displayed_rows = 0;
739 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
743 <table id="serverstatusqueriesdetails" class="data sortable">
744 <col class="namecol" />
745 <col class="valuecol" span="3" />
746 <thead>
747 <tr><th><?php echo __('Statements'); ?></th>
748 <th><?php
749 /* l10n: # = Amount of queries */
750 echo __('#');
752 <th>&oslash; <?php echo __('per hour'); ?></th>
753 <th>%</th>
754 </tr>
755 </thead>
756 <tbody>
758 <?php
759 $chart_json = array();
760 $query_sum = array_sum($used_queries);
761 $other_sum = 0;
762 foreach ($used_queries as $name => $value) {
763 $odd_row = !$odd_row;
765 // For the percentage column, use Questions - Connections, because
766 // the number of connections is not an item of the Query types
767 // but is included in Questions. Then the total of the percentages is 100.
768 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
770 // Group together values that make out less than 2% into "Other", but only if we have more than 6 fractions already
771 if ($value < $query_sum * 0.02 && count($chart_json)>6)
772 $other_sum += $value;
773 else $chart_json[$name] = $value;
775 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
776 <th class="name"><?php echo htmlspecialchars($name); ?></th>
777 <td class="value"><?php echo PMA_formatNumber($value, 5, 0, true); ?></td>
778 <td class="value"><?php echo
779 PMA_formatNumber($value * $hour_factor, 4, 1, true); ?></td>
780 <td class="value"><?php echo
781 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
782 </tr>
783 <?php
786 </tbody>
787 </table>
789 <div id="serverstatusquerieschart">
790 <span style="display:none;">
791 <?php
792 if ($other_sum > 0)
793 $chart_json[__('Other')] = $other_sum;
795 echo json_encode($chart_json);
797 </span>
798 </div>
799 <?php
802 function printServerTraffic() {
803 global $server_status,$PMA_PHP_SELF;
804 global $server_master_status, $server_slave_status, $replication_types;
806 $hour_factor = 3600 / $server_status['Uptime'];
809 * starttime calculation
811 $start_time = PMA_DBI_fetch_value(
812 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
815 <h3><?php
816 echo sprintf(
817 __('Network traffic since startup: %s'),
818 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
821 </h3>
824 <?php
825 echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'),
826 PMA_timespanFormat($server_status['Uptime']),
827 PMA_localisedDate($start_time)) . "\n";
829 </p>
831 <?php
832 if ($server_master_status || $server_slave_status) {
833 echo '<p class="notice">';
834 if ($server_master_status && $server_slave_status) {
835 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
836 } elseif ($server_master_status) {
837 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
838 } elseif ($server_slave_status) {
839 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
841 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
842 echo '</p>';
845 /* if the server works as master or slave in replication process, display useful information */
846 if ($server_master_status || $server_slave_status)
849 <hr class="clearfloat" />
851 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
852 <?php
854 foreach ($replication_types as $type)
856 if (${"server_{$type}_status"}) {
857 PMA_replication_print_status_table($type);
860 unset($types);
864 <table id="serverstatustraffic" class="data">
865 <thead>
866 <tr>
867 <th colspan="2"><?php echo __('Traffic') . '&nbsp;' . PMA_showHint(__('On a busy server, the byte counters may overrun, so those statistics as reported by the MySQL server may be incorrect.')); ?></th>
868 <th>&oslash; <?php echo __('per hour'); ?></th>
869 </tr>
870 </thead>
871 <tbody>
872 <tr class="noclick odd">
873 <th class="name"><?php echo __('Received'); ?></th>
874 <td class="value"><?php echo
875 implode(' ',
876 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
877 <td class="value"><?php echo
878 implode(' ',
879 PMA_formatByteDown(
880 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
881 </tr>
882 <tr class="noclick even">
883 <th class="name"><?php echo __('Sent'); ?></th>
884 <td class="value"><?php echo
885 implode(' ',
886 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
887 <td class="value"><?php echo
888 implode(' ',
889 PMA_formatByteDown(
890 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
891 </tr>
892 <tr class="noclick odd">
893 <th class="name"><?php echo __('Total'); ?></th>
894 <td class="value"><?php echo
895 implode(' ',
896 PMA_formatByteDown(
897 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
898 ); ?></td>
899 <td class="value"><?php echo
900 implode(' ',
901 PMA_formatByteDown(
902 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
903 * $hour_factor, 3, 1)
904 ); ?></td>
905 </tr>
906 </tbody>
907 </table>
909 <table id="serverstatusconnections" class="data">
910 <thead>
911 <tr>
912 <th colspan="2"><?php echo __('Connections'); ?></th>
913 <th>&oslash; <?php echo __('per hour'); ?></th>
914 <th>%</th>
915 </tr>
916 </thead>
917 <tbody>
918 <tr class="noclick odd">
919 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
920 <td class="value"><?php echo
921 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
922 <td class="value">--- </td>
923 <td class="value">--- </td>
924 </tr>
925 <tr class="noclick even">
926 <th class="name"><?php echo __('Failed attempts'); ?></th>
927 <td class="value"><?php echo
928 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
929 <td class="value"><?php echo
930 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
931 4, 2, true); ?></td>
932 <td class="value"><?php echo
933 $server_status['Connections'] > 0
934 ? PMA_formatNumber(
935 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
936 0, 2, true) . '%'
937 : '--- '; ?></td>
938 </tr>
939 <tr class="noclick odd">
940 <th class="name"><?php echo __('Aborted'); ?></th>
941 <td class="value"><?php echo
942 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
943 <td class="value"><?php echo
944 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
945 4, 2, true); ?></td>
946 <td class="value"><?php echo
947 $server_status['Connections'] > 0
948 ? PMA_formatNumber(
949 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
950 0, 2, true) . '%'
951 : '--- '; ?></td>
952 </tr>
953 <tr class="noclick even">
954 <th class="name"><?php echo __('Total'); ?></th>
955 <td class="value"><?php echo
956 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
957 <td class="value"><?php echo
958 PMA_formatNumber($server_status['Connections'] * $hour_factor,
959 4, 2); ?></td>
960 <td class="value"><?php echo
961 PMA_formatNumber(100, 0, 2); ?>%</td>
962 </tr>
963 </tbody>
964 </table>
965 <?php
967 $url_params = array();
969 if (! empty($_REQUEST['full'])) {
970 $sql_query = 'SHOW FULL PROCESSLIST';
971 $url_params['full'] = 1;
972 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
973 } else {
974 $sql_query = 'SHOW PROCESSLIST';
975 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
977 $result = PMA_DBI_query($sql_query);
980 * Displays the page
983 <table id="tableprocesslist" class="data clearfloat">
984 <thead>
985 <tr>
986 <th><?php echo __('Processes'); ?></th>
987 <th><?php echo __('ID'); ?></th>
988 <th><?php echo __('User'); ?></th>
989 <th><?php echo __('Host'); ?></th>
990 <th><?php echo __('Database'); ?></th>
991 <th><?php echo __('Command'); ?></th>
992 <th><?php echo __('Time'); ?></th>
993 <th><?php echo __('Status'); ?></th>
994 <th><?php
995 echo __('SQL query');
996 if (! PMA_DRIZZLE) { ?>
997 <a href="<?php echo $full_text_link; ?>"
998 title="<?php echo empty($full) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>">
999 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (empty($_REQUEST['full']) ? 'full' : 'partial'); ?>text.png"
1000 alt="<?php echo empty($_REQUEST['full']) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>" />
1001 </a>
1002 <?php } ?>
1003 </th>
1004 </tr>
1005 </thead>
1006 <tbody>
1007 <?php
1008 $odd_row = true;
1009 while ($process = PMA_DBI_fetch_assoc($result)) {
1010 if (PMA_DRIZZLE) {
1011 // Drizzle uses uppercase keys
1012 foreach ($process as $k => $v) {
1013 $k = $k !== 'DB'
1014 ? ucfirst(strtolower($k))
1015 : 'db';
1016 $process[$k] = $v;
1019 $url_params['kill'] = $process['Id'];
1020 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
1022 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
1023 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
1024 <td class="value"><?php echo $process['Id']; ?></td>
1025 <td><?php echo $process['User']; ?></td>
1026 <td><?php echo $process['Host']; ?></td>
1027 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
1028 <td><?php echo $process['Command']; ?></td>
1029 <td class="value"><?php echo $process['Time']; ?></td>
1030 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
1031 <td><?php echo (empty($process['Info']) ? '---' : PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']))); ?></td>
1032 </tr>
1033 <?php
1034 $odd_row = ! $odd_row;
1037 </tbody>
1038 </table>
1039 <?php
1042 function printVariablesTable() {
1043 global $server_status, $server_variables, $allocationMap, $links;
1045 * Messages are built using the message name
1047 $strShowStatus = array(
1048 'Aborted_clients' => __('The number of connections that were aborted because the client died without closing the connection properly.'),
1049 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
1050 'Binlog_cache_disk_use' => __('The number of transactions that used the temporary binary log cache but that exceeded the value of binlog_cache_size and used a temporary file to store statements from the transaction.'),
1051 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
1052 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
1053 'Created_tmp_disk_tables' => __('The number of temporary tables on disk created automatically by the server while executing statements. If Created_tmp_disk_tables is big, you may want to increase the tmp_table_size value to cause temporary tables to be memory-based instead of disk-based.'),
1054 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
1055 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
1056 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
1057 'Delayed_insert_threads' => __('The number of INSERT DELAYED handler threads in use. Every different table on which one uses INSERT DELAYED gets its own thread.'),
1058 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
1059 'Flush_commands' => __('The number of executed FLUSH statements.'),
1060 'Handler_commit' => __('The number of internal COMMIT statements.'),
1061 'Handler_delete' => __('The number of times a row was deleted from a table.'),
1062 'Handler_discover' => __('The MySQL server can ask the NDB Cluster storage engine if it knows about a table with a given name. This is called discovery. Handler_discover indicates the number of time tables have been discovered.'),
1063 'Handler_read_first' => __('The number of times the first entry was read from an index. If this is high, it suggests that the server is doing a lot of full index scans; for example, SELECT col1 FROM foo, assuming that col1 is indexed.'),
1064 'Handler_read_key' => __('The number of requests to read a row based on a key. If this is high, it is a good indication that your queries and tables are properly indexed.'),
1065 'Handler_read_next' => __('The number of requests to read the next row in key order. This is incremented if you are querying an index column with a range constraint or if you are doing an index scan.'),
1066 'Handler_read_prev' => __('The number of requests to read the previous row in key order. This read method is mainly used to optimize ORDER BY ... DESC.'),
1067 'Handler_read_rnd' => __('The number of requests to read a row based on a fixed position. This is high if you are doing a lot of queries that require sorting of the result. You probably have a lot of queries that require MySQL to scan whole tables or you have joins that don\'t use keys properly.'),
1068 'Handler_read_rnd_next' => __('The number of requests to read the next row in the data file. This is high if you are doing a lot of table scans. Generally this suggests that your tables are not properly indexed or that your queries are not written to take advantage of the indexes you have.'),
1069 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
1070 'Handler_update' => __('The number of requests to update a row in a table.'),
1071 'Handler_write' => __('The number of requests to insert a row in a table.'),
1072 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
1073 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
1074 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
1075 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
1076 'Innodb_buffer_pool_pages_latched' => __('The number of latched pages in InnoDB buffer pool. These are pages currently being read or written or that can\'t be flushed or removed for some other reason.'),
1077 'Innodb_buffer_pool_pages_misc' => __('The number of pages busy because they have been allocated for administrative overhead such as row locks or the adaptive hash index. This value can also be calculated as Innodb_buffer_pool_pages_total - Innodb_buffer_pool_pages_free - Innodb_buffer_pool_pages_data.'),
1078 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
1079 'Innodb_buffer_pool_read_ahead_rnd' => __('The number of "random" read-aheads InnoDB initiated. This happens when a query is to scan a large portion of a table but in random order.'),
1080 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
1081 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
1082 'Innodb_buffer_pool_reads' => __('The number of logical reads that InnoDB could not satisfy from buffer pool and had to do a single-page read.'),
1083 'Innodb_buffer_pool_wait_free' => __('Normally, writes to the InnoDB buffer pool happen in the background. However, if it\'s necessary to read or create a page and no clean pages are available, it\'s necessary to wait for pages to be flushed first. This counter counts instances of these waits. If the buffer pool size was set properly, this value should be small.'),
1084 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
1085 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
1086 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
1087 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
1088 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
1089 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
1090 'Innodb_data_reads' => __('The total number of data reads.'),
1091 'Innodb_data_writes' => __('The total number of data writes.'),
1092 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
1093 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
1094 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
1095 'Innodb_log_waits' => __('The number of waits we had because log buffer was too small and we had to wait for it to be flushed before continuing.'),
1096 'Innodb_log_write_requests' => __('The number of log write requests.'),
1097 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
1098 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
1099 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
1100 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
1101 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
1102 'Innodb_pages_created' => __('The number of pages created.'),
1103 'Innodb_page_size' => __('The compiled-in InnoDB page size (default 16KB). Many values are counted in pages; the page size allows them to be easily converted to bytes.'),
1104 'Innodb_pages_read' => __('The number of pages read.'),
1105 'Innodb_pages_written' => __('The number of pages written.'),
1106 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
1107 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
1108 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
1109 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
1110 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
1111 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
1112 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
1113 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
1114 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
1115 'Key_blocks_not_flushed' => __('The number of key blocks in the key cache that have changed but haven\'t yet been flushed to disk. It used to be known as Not_flushed_key_blocks.'),
1116 'Key_blocks_unused' => __('The number of unused blocks in the key cache. You can use this value to determine how much of the key cache is in use.'),
1117 'Key_blocks_used' => __('The number of used blocks in the key cache. This value is a high-water mark that indicates the maximum number of blocks that have ever been in use at one time.'),
1118 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
1119 'Key_reads' => __('The number of physical reads of a key block from disk. If Key_reads is big, then your key_buffer_size value is probably too small. The cache miss rate can be calculated as Key_reads/Key_read_requests.'),
1120 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
1121 'Key_writes' => __('The number of physical writes of a key block to disk.'),
1122 'Last_query_cost' => __('The total cost of the last compiled query as computed by the query optimizer. Useful for comparing the cost of different query plans for the same query. The default value of 0 means that no query has been compiled yet.'),
1123 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
1124 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
1125 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
1126 'Open_files' => __('The number of files that are open.'),
1127 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
1128 'Open_tables' => __('The number of tables that are open.'),
1129 'Qcache_free_blocks' => __('The number of free memory blocks in query cache. High numbers can indicate fragmentation issues, which may be solved by issuing a FLUSH QUERY CACHE statement.'),
1130 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
1131 'Qcache_hits' => __('The number of cache hits.'),
1132 'Qcache_inserts' => __('The number of queries added to the cache.'),
1133 'Qcache_lowmem_prunes' => __('The number of queries that have been removed from the cache to free up memory for caching new queries. This information can help you tune the query cache size. The query cache uses a least recently used (LRU) strategy to decide which queries to remove from the cache.'),
1134 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
1135 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
1136 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
1137 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
1138 'Select_full_join' => __('The number of joins that do not use indexes. If this value is not 0, you should carefully check the indexes of your tables.'),
1139 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
1140 'Select_range_check' => __('The number of joins without keys that check for key usage after each row. (If this is not 0, you should carefully check the indexes of your tables.)'),
1141 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
1142 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
1143 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
1144 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
1145 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
1146 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
1147 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
1148 'Sort_merge_passes' => __('The number of merge passes the sort algorithm has had to do. If this value is large, you should consider increasing the value of the sort_buffer_size system variable.'),
1149 'Sort_range' => __('The number of sorts that were done with ranges.'),
1150 'Sort_rows' => __('The number of sorted rows.'),
1151 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
1152 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
1153 'Table_locks_waited' => __('The number of times that a table lock could not be acquired immediately and a wait was needed. If this is high, and you have performance problems, you should first optimize your queries, and then either split your table or tables or use replication.'),
1154 'Threads_cached' => __('The number of threads in the thread cache. The cache hit rate can be calculated as Threads_created/Connections. If this value is red you should raise your thread_cache_size.'),
1155 'Threads_connected' => __('The number of currently open connections.'),
1156 'Threads_created' => __('The number of threads created to handle connections. If Threads_created is big, you may want to increase the thread_cache_size value. (Normally this doesn\'t give a notable performance improvement if you have a good thread implementation.)'),
1157 'Threads_running' => __('The number of threads that are not sleeping.')
1161 * define some alerts
1163 // name => max value before alert
1164 $alerts = array(
1165 // lower is better
1166 // variable => max value
1167 'Aborted_clients' => 0,
1168 'Aborted_connects' => 0,
1170 'Binlog_cache_disk_use' => 0,
1172 'Created_tmp_disk_tables' => 0,
1174 'Handler_read_rnd' => 0,
1175 'Handler_read_rnd_next' => 0,
1177 'Innodb_buffer_pool_pages_dirty' => 0,
1178 'Innodb_buffer_pool_reads' => 0,
1179 'Innodb_buffer_pool_wait_free' => 0,
1180 'Innodb_log_waits' => 0,
1181 'Innodb_row_lock_time_avg' => 10, // ms
1182 'Innodb_row_lock_time_max' => 50, // ms
1183 'Innodb_row_lock_waits' => 0,
1185 'Slow_queries' => 0,
1186 'Delayed_errors' => 0,
1187 'Select_full_join' => 0,
1188 'Select_range_check' => 0,
1189 'Sort_merge_passes' => 0,
1190 'Opened_tables' => 0,
1191 'Table_locks_waited' => 0,
1192 'Qcache_lowmem_prunes' => 0,
1194 'Qcache_free_blocks' => $server_status['Qcache_total_blocks'] / 5,
1195 'Slow_launch_threads' => 0,
1197 // depends on Key_read_requests
1198 // normaly lower then 1:0.01
1199 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
1200 // depends on Key_write_requests
1201 // normaly nearly 1:1
1202 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
1204 'Key_buffer_fraction' => 0.5,
1206 // alert if more than 95% of thread cache is in use
1207 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
1209 // higher is better
1210 // variable => min value
1211 //'Handler read key' => '> ',
1215 <table class="data sortable" id="serverstatusvariables">
1216 <col class="namecol" />
1217 <col class="valuecol" />
1218 <col class="descrcol" />
1219 <thead>
1220 <tr>
1221 <th><?php echo __('Variable'); ?></th>
1222 <th><?php echo __('Value'); ?></th>
1223 <th><?php echo __('Description'); ?></th>
1224 </tr>
1225 </thead>
1226 <tbody>
1227 <?php
1229 $odd_row = false;
1230 foreach ($server_status as $name => $value) {
1231 $odd_row = !$odd_row;
1233 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_'.$allocationMap[$name]:''; ?>">
1234 <th class="name"><?php echo htmlspecialchars(str_replace('_',' ',$name)) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1235 </th>
1236 <td class="value"><?php
1237 if (isset($alerts[$name])) {
1238 if ($value > $alerts[$name]) {
1239 echo '<span class="attention">';
1240 } else {
1241 echo '<span class="allfine">';
1244 if ('%' === substr($name, -1, 1)) {
1245 echo PMA_formatNumber($value, 0, 2) . ' %';
1246 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1247 echo PMA_formatNumber($value, 3, 1);
1248 } elseif (is_numeric($value) && $value == (int) $value) {
1249 echo PMA_formatNumber($value, 3, 0);
1250 } elseif (is_numeric($value)) {
1251 echo PMA_formatNumber($value, 3, 1);
1252 } else {
1253 echo htmlspecialchars($value);
1255 if (isset($alerts[$name])) {
1256 echo '</span>';
1258 ?></td>
1259 <td class="descr">
1260 <?php
1261 if (isset($strShowStatus[$name ])) {
1262 echo $strShowStatus[$name];
1265 if (isset($links[$name])) {
1266 foreach ($links[$name] as $link_name => $link_url) {
1267 if ('doc' == $link_name) {
1268 echo PMA_showMySQLDocu($link_url, $link_url);
1269 } else {
1270 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1271 "\n";
1274 unset($link_url, $link_name);
1277 </td>
1278 </tr>
1279 <?php
1282 </tbody>
1283 </table>
1284 <?php
1287 function printMonitor() {
1288 global $server_status, $server_db_isLocal;
1290 <div class="monitorLinks">
1291 <a href="#pauseCharts">
1292 <img src="themes/dot.gif" class="icon ic_play" alt="" />
1293 <?php echo __('Start Monitor'); ?>
1294 </a>
1295 <a href="#settingsPopup" rel="popupLink" style="display:none;">
1296 <img src="themes/dot.gif" class="icon ic_s_cog" alt="" />
1297 <?php echo __('Settings'); ?>
1298 </a>
1299 <a href="#monitorInstructionsDialog">
1300 <img src="themes/dot.gif" class="icon ic_b_help" alt="" />
1301 <?php echo __('Instructions/Setup'); ?>
1302 </a>
1303 <a href="#endChartEditMode" style="display:none;">
1304 <img src="themes/dot.gif" class="icon ic_s_okay" alt="" />
1305 <?php echo __('Done rearranging/editing charts'); ?>
1306 </a>
1307 </div>
1309 <div class="popupContent settingsPopup">
1310 <a href="#addNewChart">
1311 <img src="themes/dot.gif" class="icon ic_b_chart" alt="" />
1312 <?php echo __('Add chart'); ?>
1313 </a> |
1314 <a href="#rearrangeCharts"> <?php echo __('Rearrange/edit charts'); ?></a><br>
1316 <?php echo __('Refresh rate:'); refreshList('gridChartRefresh'); ?><br>
1317 </p>
1319 <?php echo __('Chart columns:'); ?>
1320 <select name="chartColumns">
1321 <option>1</option>
1322 <option>2</option>
1323 <option>3</option>
1324 <option>4</option>
1325 <option>5</option>
1326 <option>6</option>
1327 <option>7</option>
1328 <option>8</option>
1329 <option>9</option>
1330 <option>10</option>
1331 </select>
1332 </p>
1333 <a href="#clearMonitorConfig"><?php echo __('Clear monitor config'); ?></a>
1334 </div>
1336 <div id="monitorInstructionsDialog" title="<?php echo __('Monitor Instructions'); ?>" style="display:none;">
1337 <?php echo __('The phpMyAdmin Monitor can assist you in optimizing the server configuration and track down time intensive
1338 queries. For the latter you will need to set log_output to \'TABLE\' and have either the slow_query_log or general_log enabled. Note however, that the
1339 general_log produces a lot of data and increases server load by up to 15%'); ?>
1340 <p></p>
1341 <img class="ajaxIcon" src="<?php echo $GLOBALS['pmaThemeImage']; ?>ajax_clock_small.gif" alt="Loading">
1342 <div class="ajaxContent">
1343 </div>
1344 <div class="monitorUse" style="display:none;">
1345 <p></p>
1346 <?php echo __('<b>Using the monitor:</b><br/>
1347 Ok, you are good to go! Once you click \'Start monitor\' your browser will refresh all displayed charts
1348 in a regular interval. You may add charts and change the refresh rate under \'Settings\', or remove any chart
1349 using the cog icon on each respective chart.
1350 <p>When you get to see a sudden spike in activity, select the relevant time span on any chart by holding down the
1351 left mouse button and panning over the chart. This will load statistics from the logs helping you find what caused the
1352 activity spike.</p>');
1355 <img class="icon ic_s_attention" src="themes/dot.gif" alt="">
1356 <?php echo __('<b>Please note:</b>
1357 Enabling the general_log may increase the server load by 5-15%. Also be aware that generating statistics from the logs is a
1358 load intensive task, so it is advisable to select only a small time span and to disable the general_log and empty its table once monitoring is not required any more.
1359 '); ?>
1360 </p>
1361 </div>
1362 </div>
1364 <div id="addChartDialog" title="Add chart" style="display:none;">
1365 <div id="tabGridVariables">
1366 <p><input type="text" name="chartTitle" value="<?php echo __('Chart Title'); ?>" /></p>
1367 <?php if ($server_db_isLocal) { ?>
1368 <input type="radio" name="chartType" value="cpu" id="chartCPU">
1369 <label for="chartCPU"><?php echo __('CPU Usage'); ?></label><br/>
1371 <input type="radio" name="chartType" value="memory" id="chartMemory">
1372 <label for="chartMemory"><?php echo __('Memory Usage'); ?></label><br/>
1374 <input type="radio" name="chartType" value="swap" id="chartSwap">
1375 <label for="chartSwap"><?php echo __('Swap Usage'); ?></label><br/>
1376 <?php } ?>
1377 <input type="radio" name="chartType" value="variable" id="chartStatusVar" checked="checked">
1378 <label for="chartStatusVar"><?php echo __('Status variable(s)'); ?></label><br/>
1379 <div id="chartVariableSettings">
1380 <label for="chartSeries"><?php echo __('Select series:'); ?></label><br>
1381 <select id="chartSeries" name="varChartList" size="1">
1382 <option><?php echo __('Commonly monitored'); ?></option>
1383 <option>Processes</option>
1384 <option>Questions</option>
1385 <option>Connections</option>
1386 <option>Bytes_sent</option>
1387 <option>Bytes_received</option>
1388 <option>Threads_connected</option>
1389 <option>Created_tmp_disk_tables</option>
1390 <option>Handler_read_first</option>
1391 <option>Innodb_buffer_pool_wait_free</option>
1392 <option>Key_reads</option>
1393 <option>Open_tables</option>
1394 <option>Select_full_join</option>
1395 <option>Slow_queries</option>
1396 </select><br>
1397 <label for="variableInput"><?php echo __('or type variable name:'); ?> </label>
1398 <input type="text" name="variableInput" id="variableInput" />
1399 <p></p>
1400 <input type="checkbox" name="differentialValue" id="differentialValue" value="differential" checked="checked" />
1401 <label for="differentialValue"><?php echo __('Display as differential value'); ?></label><br>
1402 <input type="checkbox" id="useDivisor" name="useDivisor" value="1" />
1403 <label for="useDivisor"><?php echo __('Apply a divisor'); ?></label>
1404 <span class="divisorInput" style="display:none;">
1405 <input type="text" name="valueDivisor" size="4" value="1">
1406 (<a href="#kibDivisor"><?php echo __('KiB'); ?></a>, <a href="#mibDivisor"><?php echo __('MiB'); ?></a>)
1407 </span><br>
1409 <input type="checkbox" id="useUnit" name="useUnit" value="1" />
1410 <label for="useUnit"><?php echo __('Append unit to data values'); ?></label>
1412 <span class="unitInput" style="display:none;">
1413 <input type="text" name="valueUnit" size="4" value="">
1414 </span>
1416 <a href="#submitAddSeries"><b><?php echo __('Add this series'); ?></b></a>
1417 <span id="clearSeriesLink" style="display:none;">
1418 | <a href="#submitClearSeries"><?php echo __('Clear series'); ?></a>
1419 </span>
1420 </p>
1421 <?php echo __('Series in Chart:'); ?><br/>
1422 <span id="seriesPreview">
1423 <i><?php echo __('None'); ?></i>
1424 </span>
1425 </div>
1426 </div>
1427 </div>
1429 <div id="loadingLogsDialog" title="<?php echo __('Loading logs'); ?>" style="display:none;">
1430 </div>
1432 <div id="logAnalyseDialog" title="<?php echo __('Log statistics'); ?>">
1434 </div>
1436 <table border="0" class="clearfloat" id="chartGrid">
1438 </table>
1439 <div id="logTable">
1440 <br/>
1441 </div>
1443 <script type="text/javascript">
1444 variableNames = [ <?php
1445 $i=0;
1446 foreach ($server_status as $name=>$value) {
1447 if (is_numeric($value)) {
1448 if ($i++ > 0) echo ", ";
1449 echo "'".$name."'";
1452 ?> ];
1453 </script>
1454 <?php
1457 /* Builds a <select> list for refresh rates */
1458 function refreshList($name,$defaultRate=5, $refreshRates=Array(1, 2, 5, 10, 20, 40, 60, 120, 300, 600)) {
1460 <select name="<?php echo $name; ?>">
1461 <?php
1462 foreach ($refreshRates as $rate) {
1463 $selected = ($rate == $defaultRate)?' selected="selected"':'';
1465 if ($rate<60)
1466 echo '<option value="'.$rate.'"'.$selected.'>'.sprintf(_ngettext('%d second', '%d seconds', $rate), $rate).'</option>';
1467 else
1468 echo '<option value="'.$rate.'"'.$selected.'>'.sprintf(_ngettext('%d minute', '%d minutes', $rate/60), $rate/60).'</option>';
1471 </select>
1472 <?php
1476 * cleanup of some deprecated values
1478 * @param array &$server_status
1480 function cleanDeprecated(&$server_status) {
1481 $deprecated = array(
1482 'Com_prepare_sql' => 'Com_stmt_prepare',
1483 'Com_execute_sql' => 'Com_stmt_execute',
1484 'Com_dealloc_sql' => 'Com_stmt_close',
1487 foreach ($deprecated as $old => $new) {
1488 if (isset($server_status[$old]) && isset($server_status[$new])) {
1489 unset($server_status[$old]);
1495 * Sends the footer
1497 require './libraries/footer.inc.php';