$server_db_isLocal - account for IPv6 loopback address
[phpmyadmin.git] / server_status.php
blob2bdae6496a005a894de522cb3e1f173f3e79d42d
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]++;
224 if($type=='insert' || $type=='update') {
225 // Group inserts if selected
226 if($type=='insert' && isset($_REQUEST['groupInserts']) && $_REQUEST['groupInserts'] && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i',$row['argument'],$matches)) {
227 $insertTables[$matches[2]]++;
228 if ($insertTables[$matches[2]] > 1) {
229 $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
231 // Add a ... to the end of this query to indicate that there's been other queries
232 $return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.';
233 $return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
235 // Group this value, thus do not add to the result list
236 continue;
237 } else {
238 $insertTablesFirst = $i;
239 $insertTables[$matches[2]] += $row['#'] - 1;
243 // Cut off big selects, but append byte count therefor
244 if (strlen($row['argument']) > 180) {
245 $row['argument'] = substr($row['argument'],0,160) . '... [' .
246 PMA_formatByteDown(strlen($row['argument']), 2).']';
249 $return['rows'][] = $row;
250 $i++;
253 $return['sum']['TOTAL'] = array_sum($return['sum']);
255 PMA_DBI_free_result($result);
257 exit(json_encode($return));
264 * Replication library
266 require './libraries/replication.inc.php';
267 require_once './libraries/replication_gui.lib.php';
270 * JS Includes
273 $GLOBALS['js_include'][] = 'server_status.js';
274 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
275 $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
276 $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
277 $GLOBALS['js_include'][] = 'jquery/jquery.json-2.2.js';
278 $GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
279 $GLOBALS['js_include'][] = 'jquery/jquery.sortableTable.js';
280 // Charting
281 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
282 /* Files required for chart exporting */
283 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
284 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
285 $GLOBALS['js_include'][] = 'canvg/canvg.js';
286 $GLOBALS['js_include'][] = 'canvg/rgbcolor.js';
289 * flush status variables if requested
291 if (isset($_REQUEST['flush'])) {
292 $_flush_commands = array(
293 'STATUS',
294 'TABLES',
295 'QUERY CACHE',
298 if (in_array($_REQUEST['flush'], $_flush_commands)) {
299 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
301 unset($_flush_commands);
305 * Kills a selected process
307 if (!empty($_REQUEST['kill'])) {
308 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
309 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
310 } else {
311 $message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
313 $message->addParam($_REQUEST['kill']);
314 //$message->display();
320 * get status from server
322 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
325 * for some calculations we require also some server settings
327 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
330 * cleanup of some deprecated values
332 cleanDeprecated($server_status);
335 * calculate some values
337 // Key_buffer_fraction
338 if (isset($server_status['Key_blocks_unused'])
339 && isset($server_variables['key_cache_block_size'])
340 && isset($server_variables['key_buffer_size'])) {
341 $server_status['Key_buffer_fraction_%'] =
343 - $server_status['Key_blocks_unused']
344 * $server_variables['key_cache_block_size']
345 / $server_variables['key_buffer_size']
346 * 100;
347 } elseif (isset($server_status['Key_blocks_used'])
348 && isset($server_variables['key_buffer_size'])) {
349 $server_status['Key_buffer_fraction_%'] =
350 $server_status['Key_blocks_used']
351 * 1024
352 / $server_variables['key_buffer_size'];
355 // Ratio for key read/write
356 if (isset($server_status['Key_writes'])
357 && isset($server_status['Key_write_requests'])
358 && $server_status['Key_write_requests'] > 0) {
359 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
362 if (isset($server_status['Key_reads'])
363 && isset($server_status['Key_read_requests'])
364 && $server_status['Key_read_requests'] > 0) {
365 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
368 // Threads_cache_hitrate
369 if (isset($server_status['Threads_created'])
370 && isset($server_status['Connections'])
371 && $server_status['Connections'] > 0) {
372 $server_status['Threads_cache_hitrate_%'] =
374 - $server_status['Threads_created']
375 / $server_status['Connections']
376 * 100;
379 // Format Uptime_since_flush_status : show as days, hours, minutes, seconds
380 if (isset($server_status['Uptime_since_flush_status'])) {
381 $server_status['Uptime_since_flush_status'] = PMA_timespanFormat($server_status['Uptime_since_flush_status']);
385 * split variables in sections
387 $allocations = array(
388 // variable name => section
389 // variable names match when they begin with the given string
391 'Com_' => 'com',
392 'Innodb_' => 'innodb',
393 'Ndb_' => 'ndb',
394 'Handler_' => 'handler',
395 'Qcache_' => 'qcache',
396 'Threads_' => 'threads',
397 'Slow_launch_threads' => 'threads',
399 'Binlog_cache_' => 'binlog_cache',
400 'Created_tmp_' => 'created_tmp',
401 'Key_' => 'key',
403 'Delayed_' => 'delayed',
404 'Not_flushed_delayed_rows' => 'delayed',
406 'Flush_commands' => 'query',
407 'Last_query_cost' => 'query',
408 'Slow_queries' => 'query',
409 'Queries' => 'query',
410 'Prepared_stmt_count' => 'query',
412 'Select_' => 'select',
413 'Sort_' => 'sort',
415 'Open_tables' => 'table',
416 'Opened_tables' => 'table',
417 'Open_table_definitions' => 'table',
418 'Opened_table_definitions' => 'table',
419 'Table_locks_' => 'table',
421 'Rpl_status' => 'repl',
422 'Slave_' => 'repl',
424 'Tc_' => 'tc',
426 'Ssl_' => 'ssl',
428 'Open_files' => 'files',
429 'Open_streams' => 'files',
430 'Opened_files' => 'files',
433 $sections = array(
434 // section => section name (description)
435 'com' => 'Com',
436 'query' => __('SQL query'),
437 'innodb' => 'InnoDB',
438 'ndb' => 'NDB',
439 'handler' => __('Handler'),
440 'qcache' => __('Query cache'),
441 'threads' => __('Threads'),
442 'binlog_cache' => __('Binary log'),
443 'created_tmp' => __('Temporary data'),
444 'delayed' => __('Delayed inserts'),
445 'key' => __('Key cache'),
446 'select' => __('Joins'),
447 'repl' => __('Replication'),
448 'sort' => __('Sorting'),
449 'table' => __('Tables'),
450 'tc' => __('Transaction coordinator'),
451 'files' => __('Files'),
452 'ssl' => 'SSL',
456 * define some needfull links/commands
458 // variable or section name => (name => url)
459 $links = array();
461 $links['table'][__('Flush (close) all tables')]
462 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
463 $links['table'][__('Show open tables')]
464 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
465 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
467 if ($server_master_status) {
468 $links['repl'][__('Show slave hosts')]
469 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
470 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
471 $links['repl'][__('Show master status')] = '#replication_master';
473 if ($server_slave_status) {
474 $links['repl'][__('Show slave status')] = '#replication_slave';
477 $links['repl']['doc'] = 'replication';
479 $links['qcache'][__('Flush query cache')]
480 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
481 PMA_generate_common_url();
482 $links['qcache']['doc'] = 'query_cache';
484 //$links['threads'][__('Show processes')]
485 // = 'server_processlist.php?' . PMA_generate_common_url();
486 $links['threads']['doc'] = 'mysql_threads';
488 $links['key']['doc'] = 'myisam_key_cache';
490 $links['binlog_cache']['doc'] = 'binary_log';
492 $links['Slow_queries']['doc'] = 'slow_query_log';
494 $links['innodb'][__('Variables')]
495 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
496 $links['innodb'][__('InnoDB Status')]
497 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
498 PMA_generate_common_url();
499 $links['innodb']['doc'] = 'innodb';
502 // Variable to contain all com_ variables
503 $used_queries = array();
505 // Variable to map variable names to their respective section name (used for js category filtering)
506 $allocationMap = array();
508 // sort vars into arrays
509 foreach ($server_status as $name => $value) {
510 foreach ($allocations as $filter => $section) {
511 if (strpos($name, $filter) !== false) {
512 $allocationMap[$name] = $section;
513 if ($section == 'com' && $value > 0) $used_queries[$name] = $value;
514 break; // Only exits inner loop
519 // admin commands are not queries (e.g. they include COM_PING, which is excluded from $server_status['Questions'])
520 unset($used_queries['Com_admin_commands']);
522 /* Ajax request refresh */
523 if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
524 switch($_REQUEST['show']) {
525 case 'query_statistics':
526 printQueryStatistics();
527 exit();
528 case 'server_traffic':
529 printServerTraffic();
530 exit();
531 case 'variables_table':
532 // Prints the variables table
533 printVariablesTable();
534 exit();
536 default:
537 break;
542 * start output
546 * Does the common work
548 require './libraries/server_common.inc.php';
552 * Displays the links
554 require './libraries/server_links.inc.php';
556 $server = 1;
557 if(isset($_REQUEST['server']) && intval($_REQUEST['server'])) $server = intval($_REQUEST['server']);
559 $server_db_isLocal = strtolower($cfg['Servers'][$server]['host']) == 'localhost'
560 || $cfg['Servers'][$server]['host'] == '127.0.0.1'
561 || $cfg['Servers'][$server]['host'] == '::1';
564 <script type="text/javascript">
565 pma_token = '<?php echo $_SESSION[' PMA_token ']; ?>';
566 url_query = '<?php echo str_replace('&amp;','&',$url_query);?>';
567 server_time_diff = new Date().getTime() - <?php echo microtime(true)*1000; ?>;
568 server_os = '<?php echo PHP_OS; ?>';
569 is_superuser = <?php echo PMA_isSuperuser()?'true':'false'; ?>;
570 server_db_isLocal = <?php echo ($server_db_isLocal)?'true':'false'; ?>;
571 </script>
572 <div id="serverstatus">
573 <h2><?php
575 * Displays the sub-page heading
577 if ($GLOBALS['cfg']['MainPageIconic']) {
578 echo '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_status.png" width="16" height="16" alt="" />';
581 echo __('Runtime Information');
583 ?></h2>
584 <div id="serverStatusTabs">
585 <ul>
586 <li><a href="#statustabs_traffic"><?php echo __('Server traffic'); ?></a></li>
587 <li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
588 <li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
589 <li><a href="#statustabs_charting"><?php echo __('Monitor'); ?></a></li>
590 </ul>
592 <div id="statustabs_traffic">
593 <div class="buttonlinks">
594 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&amp;' . PMA_generate_common_url(); ?>" >
595 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
596 <?php echo __('Refresh'); ?>
597 </a>
598 <span class="refreshList" style="display:none;">
599 <label for="trafficChartRefresh"><?php echo __('Refresh rate: '); ?></label>
600 <?php refreshList('trafficChartRefresh'); ?>
601 </span>
603 <a class="tabChart livetrafficLink" href="#">
604 <?php echo __('Live traffic chart'); ?>
605 </a>
606 <a class="tabChart liveconnectionsLink" href="#">
607 <?php echo __('Live conn./process chart'); ?>
608 </a>
609 </div>
610 <div class="tabInnerContent">
611 <?php printServerTraffic(); ?>
612 </div>
613 </div>
614 <div id="statustabs_queries">
615 <div class="buttonlinks">
616 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
617 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
618 <?php echo __('Refresh'); ?>
619 </a>
620 <span class="refreshList" style="display:none;">
621 <label for="queryChartRefresh"><?php echo __('Refresh rate: '); ?></label>
622 <?php refreshList('queryChartRefresh'); ?>
623 </span>
624 <a class="tabChart livequeriesLink" href="#">
625 <?php echo __('Live query chart'); ?>
626 </a>
627 </div>
628 <div class="tabInnerContent">
629 <?php printQueryStatistics(); ?>
630 </div>
631 </div>
632 <div id="statustabs_allvars">
633 <fieldset id="tableFilter">
634 <div class="buttonlinks">
635 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
636 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
637 <?php echo __('Refresh'); ?>
638 </a>
639 </div>
640 <legend>Filters</legend>
641 <div class="formelement">
642 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
643 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
644 </div>
645 <div class="formelement">
646 <input type="checkbox" name="filterAlert" id="filterAlert">
647 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
648 </div>
649 <div class="formelement">
650 <select id="filterCategory" name="filterCategory">
651 <option value=''><?php echo __('Filter by category...'); ?></option>
652 <?php
653 foreach($sections as $section_id => $section_name) {
655 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
656 <?php
660 </select>
661 </div>
662 </fieldset>
663 <div id="linkSuggestions" class="defaultLinks" style="display:none">
664 <p class="notice"><?php echo __('Related links:'); ?>
665 <?php
666 foreach ($links as $section_name => $section_links) {
667 echo '<span class="status_'.$section_name.'"> ';
668 $i=0;
669 foreach ($section_links as $link_name => $link_url) {
670 if ($i > 0) echo ', ';
671 if ('doc' == $link_name) {
672 echo PMA_showMySQLDocu($link_url, $link_url);
673 } else {
674 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
676 $i++;
678 echo '</span>';
680 unset($link_url, $link_name, $i);
682 </p>
683 </div>
684 <div class="tabInnerContent">
685 <?php printVariablesTable(); ?>
686 </div>
687 </div>
689 <div id="statustabs_charting">
690 <?php printMonitor(); ?>
691 </div>
692 </div>
693 </div>
695 <?php
697 function printQueryStatistics() {
698 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
700 $hour_factor = 3600 / $server_status['Uptime'];
702 $total_queries = array_sum($used_queries);
705 <h3 id="serverstatusqueries">
706 <?php
707 /* l10n: Questions is the name of a MySQL Status variable */
708 echo sprintf(__('Questions since startup: %s'),PMA_formatNumber($total_queries, 0)) . ' ';
709 echo PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_Questions');
711 <br>
712 <span>
713 <?php
714 echo '&oslash; '.__('per hour').': ';
715 echo PMA_formatNumber($total_queries * $hour_factor, 0);
716 echo '<br>';
718 echo '&oslash; '.__('per minute').': ';
719 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
720 echo '<br>';
722 if($total_queries / $server_status['Uptime'] >= 1) {
723 echo '&oslash; '.__('per second').': ';
724 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
727 </span>
728 </h3>
729 <?php
731 // reverse sort by value to show most used statements first
732 arsort($used_queries);
734 $odd_row = true;
735 $count_displayed_rows = 0;
736 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
740 <table id="serverstatusqueriesdetails" class="data sortable">
741 <col class="namecol" />
742 <col class="valuecol" span="3" />
743 <thead>
744 <tr><th><?php echo __('Statements'); ?></th>
745 <th><?php
746 /* l10n: # = Amount of queries */
747 echo __('#');
749 <th>&oslash; <?php echo __('per hour'); ?></th>
750 <th>%</th>
751 </tr>
752 </thead>
753 <tbody>
755 <?php
756 $chart_json = array();
757 $query_sum = array_sum($used_queries);
758 $other_sum = 0;
759 foreach ($used_queries as $name => $value) {
760 $odd_row = !$odd_row;
762 // For the percentage column, use Questions - Connections, because
763 // the number of connections is not an item of the Query types
764 // but is included in Questions. Then the total of the percentages is 100.
765 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
767 // Group together values that make out less than 2% into "Other", but only if we have more than 6 fractions already
768 if($value < $query_sum * 0.02 && count($chart_json)>6)
769 $other_sum += $value;
770 else $chart_json[$name] = $value;
772 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
773 <th class="name"><?php echo htmlspecialchars($name); ?></th>
774 <td class="value"><?php echo PMA_formatNumber($value, 5, 0, true); ?></td>
775 <td class="value"><?php echo
776 PMA_formatNumber($value * $hour_factor, 4, 1, true); ?></td>
777 <td class="value"><?php echo
778 PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
779 </tr>
780 <?php
783 </tbody>
784 </table>
786 <div id="serverstatusquerieschart">
787 <span style="display:none;">
788 <?php
789 if ($other_sum > 0)
790 $chart_json[__('Other')] = $other_sum;
792 echo json_encode($chart_json);
794 </span>
795 </div>
796 <?php
799 function printServerTraffic() {
800 global $server_status,$PMA_PHP_SELF;
801 global $server_master_status, $server_slave_status, $replication_types;
803 $hour_factor = 3600 / $server_status['Uptime'];
806 * starttime calculation
808 $start_time = PMA_DBI_fetch_value(
809 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
812 <h3><?php
813 echo sprintf(
814 __('Network traffic since startup: %s'),
815 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
818 </h3>
820 <p class="notice">
821 <?php
822 echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'),
823 PMA_timespanFormat($server_status['Uptime']),
824 PMA_localisedDate($start_time)) . "\n";
826 </p>
828 <?php
829 if ($server_master_status || $server_slave_status) {
830 echo '<p class="notice">';
831 if ($server_master_status && $server_slave_status) {
832 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
833 } elseif ($server_master_status) {
834 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
835 } elseif ($server_slave_status) {
836 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
838 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
839 echo '</p>';
842 /* if the server works as master or slave in replication process, display useful information */
843 if ($server_master_status || $server_slave_status)
846 <hr class="clearfloat" />
848 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
849 <?php
851 foreach ($replication_types as $type)
853 if (${"server_{$type}_status"}) {
854 PMA_replication_print_status_table($type);
857 unset($types);
861 <table id="serverstatustraffic" class="data">
862 <thead>
863 <tr>
864 <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>
865 <th>&oslash; <?php echo __('per hour'); ?></th>
866 </tr>
867 </thead>
868 <tbody>
869 <tr class="noclick odd">
870 <th class="name"><?php echo __('Received'); ?></th>
871 <td class="value"><?php echo
872 implode(' ',
873 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
874 <td class="value"><?php echo
875 implode(' ',
876 PMA_formatByteDown(
877 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
878 </tr>
879 <tr class="noclick even">
880 <th class="name"><?php echo __('Sent'); ?></th>
881 <td class="value"><?php echo
882 implode(' ',
883 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
884 <td class="value"><?php echo
885 implode(' ',
886 PMA_formatByteDown(
887 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
888 </tr>
889 <tr class="noclick odd">
890 <th class="name"><?php echo __('Total'); ?></th>
891 <td class="value"><?php echo
892 implode(' ',
893 PMA_formatByteDown(
894 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
895 ); ?></td>
896 <td class="value"><?php echo
897 implode(' ',
898 PMA_formatByteDown(
899 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
900 * $hour_factor, 3, 1)
901 ); ?></td>
902 </tr>
903 </tbody>
904 </table>
906 <table id="serverstatusconnections" class="data">
907 <thead>
908 <tr>
909 <th colspan="2"><?php echo __('Connections'); ?></th>
910 <th>&oslash; <?php echo __('per hour'); ?></th>
911 <th>%</th>
912 </tr>
913 </thead>
914 <tbody>
915 <tr class="noclick odd">
916 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
917 <td class="value"><?php echo
918 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
919 <td class="value">--- </td>
920 <td class="value">--- </td>
921 </tr>
922 <tr class="noclick even">
923 <th class="name"><?php echo __('Failed attempts'); ?></th>
924 <td class="value"><?php echo
925 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
926 <td class="value"><?php echo
927 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
928 4, 2, true); ?></td>
929 <td class="value"><?php echo
930 $server_status['Connections'] > 0
931 ? PMA_formatNumber(
932 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
933 0, 2, true) . '%'
934 : '--- '; ?></td>
935 </tr>
936 <tr class="noclick odd">
937 <th class="name"><?php echo __('Aborted'); ?></th>
938 <td class="value"><?php echo
939 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
940 <td class="value"><?php echo
941 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
942 4, 2, true); ?></td>
943 <td class="value"><?php echo
944 $server_status['Connections'] > 0
945 ? PMA_formatNumber(
946 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
947 0, 2, true) . '%'
948 : '--- '; ?></td>
949 </tr>
950 <tr class="noclick even">
951 <th class="name"><?php echo __('Total'); ?></th>
952 <td class="value"><?php echo
953 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
954 <td class="value"><?php echo
955 PMA_formatNumber($server_status['Connections'] * $hour_factor,
956 4, 2); ?></td>
957 <td class="value"><?php echo
958 PMA_formatNumber(100, 0, 2); ?>%</td>
959 </tr>
960 </tbody>
961 </table>
962 <?php
964 $url_params = array();
966 if (! empty($_REQUEST['full'])) {
967 $sql_query = 'SHOW FULL PROCESSLIST';
968 $url_params['full'] = 1;
969 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
970 } else {
971 $sql_query = 'SHOW PROCESSLIST';
972 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
974 $result = PMA_DBI_query($sql_query);
977 * Displays the page
980 <table id="tableprocesslist" class="data clearfloat">
981 <thead>
982 <tr>
983 <th><?php echo __('Processes'); ?></th>
984 <th><?php echo __('ID'); ?></th>
985 <th><?php echo __('User'); ?></th>
986 <th><?php echo __('Host'); ?></th>
987 <th><?php echo __('Database'); ?></th>
988 <th><?php echo __('Command'); ?></th>
989 <th><?php echo __('Time'); ?></th>
990 <th><?php echo __('Status'); ?></th>
991 <th><?php
992 echo __('SQL query');
993 if (! PMA_DRIZZLE) { ?>
994 <a href="<?php echo $full_text_link; ?>"
995 title="<?php echo empty($full) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>">
996 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (empty($_REQUEST['full']) ? 'full' : 'partial'); ?>text.png"
997 alt="<?php echo empty($_REQUEST['full']) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>" />
998 </a>
999 <?php } ?>
1000 </th>
1001 </tr>
1002 </thead>
1003 <tbody>
1004 <?php
1005 $odd_row = true;
1006 while ($process = PMA_DBI_fetch_assoc($result)) {
1007 if (PMA_DRIZZLE) {
1008 // Drizzle uses uppercase keys
1009 foreach ($process as $k => $v) {
1010 $k = $k !== 'DB'
1011 ? ucfirst(strtolower($k))
1012 : 'db';
1013 $process[$k] = $v;
1016 $url_params['kill'] = $process['Id'];
1017 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
1019 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
1020 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
1021 <td class="value"><?php echo $process['Id']; ?></td>
1022 <td><?php echo $process['User']; ?></td>
1023 <td><?php echo $process['Host']; ?></td>
1024 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
1025 <td><?php echo $process['Command']; ?></td>
1026 <td class="value"><?php echo $process['Time']; ?></td>
1027 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
1028 <td><?php echo (empty($process['Info']) ? '---' : PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']))); ?></td>
1029 </tr>
1030 <?php
1031 $odd_row = ! $odd_row;
1034 </tbody>
1035 </table>
1036 <?php
1039 function printVariablesTable() {
1040 global $server_status, $server_variables, $allocationMap, $links;
1042 * Messages are built using the message name
1044 $strShowStatus = array(
1045 'Aborted_clients' => __('The number of connections that were aborted because the client died without closing the connection properly.'),
1046 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
1047 '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.'),
1048 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
1049 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
1050 '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.'),
1051 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
1052 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
1053 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
1054 '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.'),
1055 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
1056 'Flush_commands' => __('The number of executed FLUSH statements.'),
1057 'Handler_commit' => __('The number of internal COMMIT statements.'),
1058 'Handler_delete' => __('The number of times a row was deleted from a table.'),
1059 '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.'),
1060 '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.'),
1061 '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.'),
1062 '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.'),
1063 '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.'),
1064 '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.'),
1065 '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.'),
1066 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
1067 'Handler_update' => __('The number of requests to update a row in a table.'),
1068 'Handler_write' => __('The number of requests to insert a row in a table.'),
1069 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
1070 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
1071 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
1072 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
1073 '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.'),
1074 '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.'),
1075 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
1076 '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.'),
1077 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
1078 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
1079 '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.'),
1080 '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.'),
1081 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
1082 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
1083 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
1084 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
1085 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
1086 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
1087 'Innodb_data_reads' => __('The total number of data reads.'),
1088 'Innodb_data_writes' => __('The total number of data writes.'),
1089 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
1090 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
1091 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
1092 '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.'),
1093 'Innodb_log_write_requests' => __('The number of log write requests.'),
1094 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
1095 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
1096 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
1097 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
1098 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
1099 'Innodb_pages_created' => __('The number of pages created.'),
1100 '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.'),
1101 'Innodb_pages_read' => __('The number of pages read.'),
1102 'Innodb_pages_written' => __('The number of pages written.'),
1103 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
1104 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
1105 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
1106 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
1107 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
1108 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
1109 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
1110 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
1111 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
1112 '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.'),
1113 '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.'),
1114 '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.'),
1115 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
1116 '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.'),
1117 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
1118 'Key_writes' => __('The number of physical writes of a key block to disk.'),
1119 '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.'),
1120 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
1121 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
1122 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
1123 'Open_files' => __('The number of files that are open.'),
1124 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
1125 'Open_tables' => __('The number of tables that are open.'),
1126 '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.'),
1127 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
1128 'Qcache_hits' => __('The number of cache hits.'),
1129 'Qcache_inserts' => __('The number of queries added to the cache.'),
1130 '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.'),
1131 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
1132 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
1133 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
1134 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
1135 '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.'),
1136 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
1137 '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.)'),
1138 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
1139 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
1140 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
1141 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
1142 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
1143 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
1144 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
1145 '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.'),
1146 'Sort_range' => __('The number of sorts that were done with ranges.'),
1147 'Sort_rows' => __('The number of sorted rows.'),
1148 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
1149 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
1150 '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.'),
1151 '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.'),
1152 'Threads_connected' => __('The number of currently open connections.'),
1153 '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.)'),
1154 'Threads_running' => __('The number of threads that are not sleeping.')
1158 * define some alerts
1160 // name => max value before alert
1161 $alerts = array(
1162 // lower is better
1163 // variable => max value
1164 'Aborted_clients' => 0,
1165 'Aborted_connects' => 0,
1167 'Binlog_cache_disk_use' => 0,
1169 'Created_tmp_disk_tables' => 0,
1171 'Handler_read_rnd' => 0,
1172 'Handler_read_rnd_next' => 0,
1174 'Innodb_buffer_pool_pages_dirty' => 0,
1175 'Innodb_buffer_pool_reads' => 0,
1176 'Innodb_buffer_pool_wait_free' => 0,
1177 'Innodb_log_waits' => 0,
1178 'Innodb_row_lock_time_avg' => 10, // ms
1179 'Innodb_row_lock_time_max' => 50, // ms
1180 'Innodb_row_lock_waits' => 0,
1182 'Slow_queries' => 0,
1183 'Delayed_errors' => 0,
1184 'Select_full_join' => 0,
1185 'Select_range_check' => 0,
1186 'Sort_merge_passes' => 0,
1187 'Opened_tables' => 0,
1188 'Table_locks_waited' => 0,
1189 'Qcache_lowmem_prunes' => 0,
1191 'Qcache_free_blocks' => $server_status['Qcache_total_blocks'] / 5,
1192 'Slow_launch_threads' => 0,
1194 // depends on Key_read_requests
1195 // normaly lower then 1:0.01
1196 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
1197 // depends on Key_write_requests
1198 // normaly nearly 1:1
1199 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
1201 'Key_buffer_fraction' => 0.5,
1203 // alert if more than 95% of thread cache is in use
1204 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
1206 // higher is better
1207 // variable => min value
1208 //'Handler read key' => '> ',
1212 <table class="data sortable" id="serverstatusvariables">
1213 <col class="namecol" />
1214 <col class="valuecol" />
1215 <col class="descrcol" />
1216 <thead>
1217 <tr>
1218 <th><?php echo __('Variable'); ?></th>
1219 <th><?php echo __('Value'); ?></th>
1220 <th><?php echo __('Description'); ?></th>
1221 </tr>
1222 </thead>
1223 <tbody>
1224 <?php
1226 $odd_row = false;
1227 foreach ($server_status as $name => $value) {
1228 $odd_row = !$odd_row;
1230 <tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_'.$allocationMap[$name]:''; ?>">
1231 <th class="name"><?php echo htmlspecialchars(str_replace('_',' ',$name)) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1232 </th>
1233 <td class="value"><?php
1234 if (isset($alerts[$name])) {
1235 if ($value > $alerts[$name]) {
1236 echo '<span class="attention">';
1237 } else {
1238 echo '<span class="allfine">';
1241 if ('%' === substr($name, -1, 1)) {
1242 echo PMA_formatNumber($value, 0, 2) . ' %';
1243 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1244 echo PMA_formatNumber($value, 3, 1);
1245 } elseif (is_numeric($value) && $value == (int) $value) {
1246 echo PMA_formatNumber($value, 3, 0);
1247 } elseif (is_numeric($value)) {
1248 echo PMA_formatNumber($value, 3, 1);
1249 } else {
1250 echo htmlspecialchars($value);
1252 if (isset($alerts[$name])) {
1253 echo '</span>';
1255 ?></td>
1256 <td class="descr">
1257 <?php
1258 if (isset($strShowStatus[$name ])) {
1259 echo $strShowStatus[$name];
1262 if (isset($links[$name])) {
1263 foreach ($links[$name] as $link_name => $link_url) {
1264 if ('doc' == $link_name) {
1265 echo PMA_showMySQLDocu($link_url, $link_url);
1266 } else {
1267 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1268 "\n";
1271 unset($link_url, $link_name);
1274 </td>
1275 </tr>
1276 <?php
1279 </tbody>
1280 </table>
1281 <?php
1284 function printMonitor() {
1285 global $server_status, $server_db_isLocal;
1287 <div class="monitorLinks">
1288 <a href="#pauseCharts">
1289 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>play.png" alt="" />
1290 <?php echo __('Start Monitor'); ?>
1291 </a>
1292 <a href="#settingsPopup" rel="popupLink" style="display:none;">
1293 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>s_cog.png" alt="" />
1294 <?php echo __('Settings'); ?>
1295 </a>
1296 <a href="#monitorInstructionsDialog">
1297 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>b_help.png" alt="" />
1298 <?php echo __('Instructions/Setup'); ?>
1299 </a>
1300 <a href="#endChartEditMode" style="display:none;">
1301 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>s_okay.png" alt="" />
1302 <?php echo __('Done rearranging/editing charts'); ?>
1303 </a>
1304 </div>
1306 <div class="popupContent settingsPopup">
1307 <a href="#addNewChart">
1308 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>b_chart.png" alt="" />
1309 <?php echo __('Add chart'); ?>
1310 </a> |
1311 <a href="#rearrangeCharts"> <?php echo __('Rearrange/edit charts'); ?></a><br>
1313 <?php echo __('Refresh rate:'); refreshList('gridChartRefresh'); ?><br>
1314 </p>
1315 <p>
1316 <?php echo __('Chart columns:'); ?>
1317 <select name="chartColumns">
1318 <option>1</option>
1319 <option>2</option>
1320 <option>3</option>
1321 <option>4</option>
1322 <option>5</option>
1323 <option>6</option>
1324 <option>7</option>
1325 <option>8</option>
1326 <option>9</option>
1327 <option>10</option>
1328 </select>
1329 </p>
1330 <a href="#clearMonitorConfig"><?php echo __('Clear monitor config'); ?></a>
1331 </div>
1333 <div id="monitorInstructionsDialog" title="<?php echo __('Monitor Instructions'); ?>" style="display:none;">
1334 <?php echo __('The phpMyAdmin Monitor can assist you in optimizing the server configuration and track down time intensive
1335 queries. For the latter you will need to log_output set to \'TABLE\' and have either the slow_query_log or general_log enabled.'); ?>
1336 <p></p>
1337 <img class="ajaxIcon" src="<?php echo $GLOBALS['pmaThemeImage']; ?>ajax_clock_small.gif" alt="Loading">
1338 <div class="ajaxContent">
1339 </div>
1340 <div class="monitorUse" style="display:none;">
1341 <p></p>
1342 <?php echo __('<b>Using the monitor:</b><br/>
1343 Ok, you are good to go! Once you click \'Start monitor\' your browser will refresh all displayed charts
1344 in a regular interval. You may add charts and change the refresh rate under \'Settings\', or remove any chart
1345 using the cog icon on each respective chart.
1346 <p>When you get to see a sudden spike in activity, select the relevant time span on any chart by holding down the
1347 left mouse button and panning over the chart. This will load statistics from the logs helping you find what caused the
1348 activity spike.</p>
1349 <p><b>Please note:</b>
1350 Enabling the general_log may increase the server load by up to 5-15%. Also be aware that generating statistics out of the logs is a
1351 very load intensive task, thus it is advisable to select only a small time span.
1352 </p>'); ?>
1353 </div>
1354 </div>
1356 <div id="addChartDialog" title="Add chart" style="display:none;">
1357 <div id="tabGridVariables">
1358 <p><input type="text" name="chartTitle" value="<?php echo __('Chart Title'); ?>" /></p>
1359 <?php if($server_db_isLocal) { ?>
1360 <input type="radio" name="chartType" value="cpu" id="chartCPU">
1361 <label for="chartCPU"><?php echo __('CPU Usage'); ?></label><br/>
1363 <input type="radio" name="chartType" value="memory" id="chartMemory">
1364 <label for="chartMemory"><?php echo __('Memory Usage'); ?></label><br/>
1366 <input type="radio" name="chartType" value="swap" id="chartSwap">
1367 <label for="chartSwap"><?php echo __('Swap Usage'); ?></label><br/>
1368 <?php } ?>
1369 <input type="radio" name="chartType" value="variable" id="chartStatusVar" checked="checked">
1370 <label for="chartStatusVar"><?php echo __('Status variable(s)'); ?></label><br/>
1371 <div id="chartVariableSettings">
1372 <label for="chartSeries"><?php echo __('Select series:'); ?></label><br>
1373 <select id="chartSeries" name="varChartList" size="1">
1374 <option><?php echo __('Commonly monitored'); ?></option>
1375 <option>Processes</option>
1376 <option>Questions</option>
1377 <option>Connections</option>
1378 <option>Bytes_sent</option>
1379 <option>Bytes_received</option>
1380 <option>Threads_connected</option>
1381 <option>Created_tmp_disk_tables</option>
1382 <option>Handler_read_first</option>
1383 <option>Innodb_buffer_pool_wait_free</option>
1384 <option>Key_reads</option>
1385 <option>Open_tables</option>
1386 <option>Select_full_join</option>
1387 <option>Slow_queries</option>
1388 </select><br>
1389 <label for="variableInput"><?php echo __('or type variable name:'); ?> </label>
1390 <input type="text" name="variableInput" id="variableInput" />
1391 <p></p>
1392 <input type="checkbox" name="differentialValue" id="differentialValue" value="differential" checked="checked" />
1393 <label for="differentialValue"><?php echo __('Display as differential value'); ?></label><br>
1394 <input type="checkbox" id="useDivisor" name="useDivisor" value="1" />
1395 <label for="useDivisor"><?php echo __('Apply a divisor'); ?></label>
1396 <span class="divisorInput" style="display:none;">
1397 <input type="text" name="valueDivisor" size="4" value="1">
1398 (<a href="#kibDivisor"><?php echo __('KiB'); ?></a>, <a href="#mibDivisor"><?php echo __('MiB'); ?></a>)
1399 </span><br>
1401 <input type="checkbox" id="useUnit" name="useUnit" value="1" />
1402 <label for="useUnit"><?php echo __('Append unit to data values'); ?></label>
1404 <span class="unitInput" style="display:none;">
1405 <input type="text" name="valueUnit" size="4" value="">
1406 </span>
1408 <a href="#submitAddSeries"><b><?php echo __('Add this series'); ?></b></a>
1409 <span id="clearSeriesLink" style="display:none;">
1410 | <a href="#submitClearSeries"><?php echo __('Clear series'); ?></a>
1411 </span>
1412 </p>
1413 <?php echo __('Series in Chart:'); ?><br/>
1414 <span id="seriesPreview">
1415 <i><?php echo __('None'); ?></i>
1416 </span>
1417 </div>
1418 </div>
1419 </div>
1421 <div id="loadingLogsDialog" title="<?php echo __('Loading logs'); ?>" style="display:none;">
1422 </div>
1424 <div id="logAnalyseDialog" title="<?php echo __('Log statistics'); ?>">
1426 </div>
1428 <table border="0" class="clearfloat" id="chartGrid">
1430 </table>
1431 <div id="logTable">
1432 <br/>
1433 </div>
1435 <script type="text/javascript">
1436 variableNames = [ <?php
1437 $i=0;
1438 foreach($server_status as $name=>$value) {
1439 if(is_numeric($value)) {
1440 if($i++ > 0) echo ", ";
1441 echo "'".$name."'";
1444 ?> ];
1445 </script>
1446 <?php
1449 /* Builds a <select> list for refresh rates */
1450 function refreshList($name,$defaultRate=5, $refreshRates=Array(1, 2, 5, 10, 20, 40, 60, 120, 300, 600)) {
1452 <select name="<?php echo $name; ?>">
1453 <?php
1454 foreach($refreshRates as $rate) {
1455 $selected = ($rate == $defaultRate)?' selected="selected"':'';
1457 if($rate<60)
1458 echo '<option value="'.$rate.'"'.$selected.'>'.sprintf(_ngettext('%d second', '%d seconds', $rate), $rate).'</option>';
1459 else
1460 echo '<option value="'.$rate.'"'.$selected.'>'.sprintf(_ngettext('%d minute', '%d minutes', $rate/60), $rate/60).'</option>';
1463 </select>
1464 <?php
1468 * cleanup of some deprecated values
1470 * @param array &$server_status
1472 function cleanDeprecated(&$server_status) {
1473 $deprecated = array(
1474 'Com_prepare_sql' => 'Com_stmt_prepare',
1475 'Com_execute_sql' => 'Com_stmt_execute',
1476 'Com_dealloc_sql' => 'Com_stmt_close',
1479 foreach ($deprecated as $old => $new) {
1480 if (isset($server_status[$old]) && isset($server_status[$new])) {
1481 unset($server_status[$old]);
1487 * Sends the footer
1489 require './libraries/footer.inc.php';