Bug: Live query chart always zero
[phpmyadmin/tyronm.git] / server_status.php
blobf6036ca894667d1590f26d1febf51e2c2a48af2c
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;
22 require_once './libraries/common.inc.php';
24 /**
25 * Ajax request
28 if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
29 // Send with correct charset
30 header('Content-Type: text/html; charset=UTF-8');
32 // real-time charting data
33 if (isset($_REQUEST['chart_data'])) {
34 switch($_REQUEST['type']) {
35 // Process and Connections realtime chart
36 case 'proc':
37 $c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1);
38 $result = PMA_DBI_query('SHOW PROCESSLIST');
39 $num_procs = PMA_DBI_num_rows($result);
41 $ret = array(
42 'x' => microtime(true) * 1000,
43 'y_proc' => $num_procs,
44 'y_conn' => $c['Connections']
47 exit(json_encode($ret));
49 // Query realtime chart
50 case 'queries':
51 $queries = PMA_DBI_fetch_result(
52 "SHOW GLOBAL STATUS
53 WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions')
54 AND Value > 0", 0, 1);
55 cleanDeprecated($queries);
56 // admin commands are not queries
57 unset($queries['Com_admin_commands']);
58 $questions = $queries['Questions'];
59 unset($queries['Questions']);
61 //$sum=array_sum($queries);
62 $ret = array(
63 'x' => microtime(true) * 1000,
64 'y' => $questions,
65 'pointInfo' => $queries
68 exit(json_encode($ret));
70 // Traffic realtime chart
71 case 'traffic':
72 $traffic = PMA_DBI_fetch_result(
73 "SHOW GLOBAL STATUS
74 WHERE Variable_name = 'Bytes_received'
75 OR Variable_name = 'Bytes_sent'", 0, 1);
77 $ret = array(
78 'x' => microtime(true) * 1000,
79 'y_sent' => $traffic['Bytes_sent'],
80 'y_received' => $traffic['Bytes_received']
83 exit(json_encode($ret));
85 // Data for the monitor
86 case 'chartgrid':
87 $ret = json_decode($_REQUEST['requiredData'], true);
88 $statusVars = array();
89 $serverVars = array();
90 $sysinfo = $cpuload = $memory = 0;
91 $pName = '';
93 /* Accumulate all required variables and data */
94 // For each chart
95 foreach ($ret as $chart_id => $chartNodes) {
96 // For each data series
97 foreach ($chartNodes as $node_id => $nodeDataPoints) {
98 // For each data point in the series (usually just 1)
99 foreach ($nodeDataPoints as $point_id => $dataPoint) {
100 $pName = $dataPoint['name'];
102 switch ($dataPoint['type']) {
103 /* We only collect the status and server variables here to
104 * read them all in one query, and only afterwards assign them.
105 * Also do some white list filtering on the names
107 case 'servervar':
108 if (!preg_match('/[^a-zA-Z_]+/', $pName)) {
109 $serverVars[] = $pName;
111 break;
113 case 'statusvar':
114 if (!preg_match('/[^a-zA-Z_]+/', $pName)) {
115 $statusVars[] = $pName;
117 break;
119 case 'proc':
120 $result = PMA_DBI_query('SHOW PROCESSLIST');
121 $ret[$chart_id][$node_id][$point_id]['value'] = PMA_DBI_num_rows($result);
122 break;
124 case 'cpu':
125 if (!$sysinfo) {
126 require_once 'libraries/sysinfo.lib.php';
127 $sysinfo = getSysInfo();
129 if (!$cpuload) {
130 $cpuload = $sysinfo->loadavg();
133 if (PHP_OS == 'Linux') {
134 $ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle'];
135 $ret[$chart_id][$node_id][$point_id]['busy'] = $cpuload['busy'];
136 } else
137 $ret[$chart_id][$node_id][$point_id]['value'] = $cpuload['loadavg'];
139 break;
141 case 'memory':
142 if (!$sysinfo) {
143 require_once 'libraries/sysinfo.lib.php';
144 $sysinfo = getSysInfo();
146 if (!$memory) {
147 $memory = $sysinfo->memory();
150 $ret[$chart_id][$node_id][$point_id]['value'] = $memory[$pName];
151 break;
152 } /* switch */
153 } /* foreach */
154 } /* foreach */
155 } /* foreach */
157 // Retrieve all required status variables
158 if (count($statusVars)) {
159 $statusVarValues = PMA_DBI_fetch_result(
160 "SHOW GLOBAL STATUS
161 WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1);
162 } else {
163 $statusVarValues = array();
166 // Retrieve all required server variables
167 if (count($serverVars)) {
168 $serverVarValues = PMA_DBI_fetch_result(
169 "SHOW GLOBAL VARIABLES
170 WHERE Variable_name='" . implode("' OR Variable_name='", $serverVars) . "'", 0, 1);
171 } else {
172 $serverVarValues = array();
175 // ...and now assign them
176 foreach ($ret as $chart_id => $chartNodes) {
177 foreach ($chartNodes as $node_id => $nodeDataPoints) {
178 foreach ($nodeDataPoints as $point_id => $dataPoint) {
179 switch($dataPoint['type']) {
180 case 'statusvar':
181 $ret[$chart_id][$node_id][$point_id]['value'] = $statusVarValues[$dataPoint['name']];
182 break;
183 case 'servervar':
184 $ret[$chart_id][$node_id][$point_id]['value'] = $serverVarValues[$dataPoint['name']];
185 break;
191 $ret['x'] = microtime(true) * 1000;
193 exit(json_encode($ret));
197 if (isset($_REQUEST['log_data'])) {
198 if (PMA_MYSQL_INT_VERSION < 50106) {
199 /* FIXME: why this? */
200 exit('""');
203 $start = intval($_REQUEST['time_start']);
204 $end = intval($_REQUEST['time_end']);
206 if ($_REQUEST['type'] == 'slow') {
207 $q = 'SELECT start_time, user_host, Sec_to_Time(Sum(Time_to_Sec(query_time))) as query_time, Sec_to_Time(Sum(Time_to_Sec(lock_time))) as lock_time, '.
208 'SUM(rows_sent) AS rows_sent, SUM(rows_examined) AS rows_examined, db, sql_text, COUNT(sql_text) AS \'#\' '.
209 'FROM `mysql`.`slow_log` WHERE start_time > FROM_UNIXTIME(' . $start . ') '.
210 'AND start_time < FROM_UNIXTIME(' . $end . ') GROUP BY sql_text';
212 $result = PMA_DBI_try_query($q);
214 $return = array('rows' => array(), 'sum' => array());
215 $type = '';
217 while ($row = PMA_DBI_fetch_assoc($result)) {
218 $type = strtolower(substr($row['sql_text'], 0, strpos($row['sql_text'], ' ')));
220 switch($type) {
221 case 'insert':
222 case 'update':
223 // Cut off big inserts and updates, but append byte count therefor
224 if (strlen($row['sql_text']) > 220) {
225 $row['sql_text'] = substr($row['sql_text'], 0, 200)
226 . '... ['
227 . implode(' ', PMA_formatByteDown(strlen($row['sql_text']), 2, 2))
228 . ']';
230 break;
231 default:
232 break;
235 if (!isset($return['sum'][$type])) {
236 $return['sum'][$type] = 0;
238 $return['sum'][$type] += $row['#'];
239 $return['rows'][] = $row;
242 $return['sum']['TOTAL'] = array_sum($return['sum']);
243 $return['numRows'] = count($return['rows']);
245 PMA_DBI_free_result($result);
247 exit(json_encode($return));
250 if ($_REQUEST['type'] == 'general') {
251 $limitTypes = (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes'])
252 ? 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ' : '';
254 $q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, server_id, argument, count(argument) as \'#\' '.
255 'FROM `mysql`.`general_log` WHERE command_type=\'Query\' '.
256 'AND event_time > FROM_UNIXTIME(' . $start . ') AND event_time < FROM_UNIXTIME(' . $end . ') '.
257 $limitTypes . 'GROUP by argument'; // HAVING count > 1';
259 $result = PMA_DBI_try_query($q);
261 $return = array('rows' => array(), 'sum' => array());
262 $type = '';
263 $insertTables = array();
264 $insertTablesFirst = -1;
265 $i = 0;
266 $removeVars = isset($_REQUEST['removeVariables']) && $_REQUEST['removeVariables'];
268 while ($row = PMA_DBI_fetch_assoc($result)) {
269 preg_match('/^(\w+)\s/', $row['argument'], $match);
270 $type = strtolower($match[1]);
272 if (!isset($return['sum'][$type])) {
273 $return['sum'][$type] = 0;
275 $return['sum'][$type] += $row['#'];
277 switch($type) {
278 case 'insert':
279 // Group inserts if selected
280 if ($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i', $row['argument'], $matches)) {
281 $insertTables[$matches[2]]++;
282 if ($insertTables[$matches[2]] > 1) {
283 $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
285 // Add a ... to the end of this query to indicate that there's been other queries
286 if ($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.') {
287 $return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
290 // Group this value, thus do not add to the result list
291 continue 2;
292 } else {
293 $insertTablesFirst = $i;
294 $insertTables[$matches[2]] += $row['#'] - 1;
297 // No break here
299 case 'update':
300 // Cut off big inserts and updates, but append byte count therefor
301 if (strlen($row['argument']) > 220) {
302 $row['argument'] = substr($row['argument'], 0, 200)
303 . '... ['
304 . implode(' ', PMA_formatByteDown(strlen($row['argument'])), 2, 2)
305 . ']';
307 break;
309 default: break;
312 $return['rows'][] = $row;
313 $i++;
316 $return['sum']['TOTAL'] = array_sum($return['sum']);
317 $return['numRows'] = count($return['rows']);
319 PMA_DBI_free_result($result);
321 exit(json_encode($return));
325 if (isset($_REQUEST['logging_vars'])) {
326 if (isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) {
327 $value = PMA_sqlAddslashes($_REQUEST['varValue']);
328 if (!is_numeric($value)) {
329 $value="'" . $value . "'";
332 if (! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName'])) {
333 PMA_DBI_query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value);
338 $loggingVars = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES WHERE Variable_name IN ("general_log","slow_query_log","long_query_time","log_output")', 0, 1);
339 exit(json_encode($loggingVars));
342 if (isset($_REQUEST['query_analyzer'])) {
343 $return = array();
345 if (strlen($_REQUEST['database'])) {
346 PMA_DBI_select_db($_REQUEST['database']);
349 if ($profiling = PMA_profilingSupported()) {
350 PMA_DBI_query('SET PROFILING=1;');
353 // Do not cache query
354 $query = preg_replace('/^(\s*SELECT)/i', '\\1 SQL_NO_CACHE', $_REQUEST['query']);
356 $result = PMA_DBI_try_query($query);
357 $return['affectedRows'] = $GLOBALS['cached_affected_rows'];
359 $result = PMA_DBI_try_query('EXPLAIN ' . $query);
360 while ($row = PMA_DBI_fetch_assoc($result)) {
361 $return['explain'][] = $row;
364 // In case an error happened
365 $return['error'] = PMA_DBI_getError();
367 PMA_DBI_free_result($result);
369 if ($profiling) {
370 $return['profiling'] = array();
371 $result = PMA_DBI_try_query('SELECT seq,state,duration FROM INFORMATION_SCHEMA.PROFILING WHERE QUERY_ID=1 ORDER BY seq');
372 while ($row = PMA_DBI_fetch_assoc($result)) {
373 $return['profiling'][]= $row;
375 PMA_DBI_free_result($result);
378 exit(json_encode($return));
381 if (isset($_REQUEST['advisor'])) {
382 include 'libraries/Advisor.class.php';
383 $advisor = new Advisor();
384 exit(json_encode($advisor->run()));
390 * Replication library
392 require './libraries/replication.inc.php';
393 require_once './libraries/replication_gui.lib.php';
396 * JS Includes
399 $GLOBALS['js_include'][] = 'server_status.js';
400 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
401 $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
402 $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
403 // Charting
404 $GLOBALS['js_include'][] = 'highcharts/highcharts.js';
405 /* Files required for chart exporting */
406 $GLOBALS['js_include'][] = 'highcharts/exporting.js';
407 /* < IE 9 doesn't support canvas natively */
408 if(PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
409 $GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
411 $GLOBALS['js_include'][] = 'canvg/canvg.js';
414 * flush status variables if requested
416 if (isset($_REQUEST['flush'])) {
417 $_flush_commands = array(
418 'STATUS',
419 'TABLES',
420 'QUERY CACHE',
423 if (in_array($_REQUEST['flush'], $_flush_commands)) {
424 PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
426 unset($_flush_commands);
430 * Kills a selected process
432 if (!empty($_REQUEST['kill'])) {
433 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
434 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
435 } else {
436 $message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
438 $message->addParam($_REQUEST['kill']);
439 //$message->display();
445 * get status from server
447 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
450 * for some calculations we require also some server settings
452 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
455 * cleanup of some deprecated values
457 cleanDeprecated($server_status);
460 * calculate some values
462 // Key_buffer_fraction
463 if (isset($server_status['Key_blocks_unused'])
464 && isset($server_variables['key_cache_block_size'])
465 && isset($server_variables['key_buffer_size'])) {
466 $server_status['Key_buffer_fraction_%'] =
468 - $server_status['Key_blocks_unused']
469 * $server_variables['key_cache_block_size']
470 / $server_variables['key_buffer_size']
471 * 100;
472 } elseif (isset($server_status['Key_blocks_used'])
473 && isset($server_variables['key_buffer_size'])) {
474 $server_status['Key_buffer_fraction_%'] =
475 $server_status['Key_blocks_used']
476 * 1024
477 / $server_variables['key_buffer_size'];
480 // Ratio for key read/write
481 if (isset($server_status['Key_writes'])
482 && isset($server_status['Key_write_requests'])
483 && $server_status['Key_write_requests'] > 0) {
484 $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
487 if (isset($server_status['Key_reads'])
488 && isset($server_status['Key_read_requests'])
489 && $server_status['Key_read_requests'] > 0) {
490 $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
493 // Threads_cache_hitrate
494 if (isset($server_status['Threads_created'])
495 && isset($server_status['Connections'])
496 && $server_status['Connections'] > 0) {
498 $server_status['Threads_cache_hitrate_%'] =
499 100 - $server_status['Threads_created'] / $server_status['Connections'] * 100;
503 * split variables in sections
505 $allocations = array(
506 // variable name => section
507 // variable names match when they begin with the given string
509 'Com_' => 'com',
510 'Innodb_' => 'innodb',
511 'Ndb_' => 'ndb',
512 'Handler_' => 'handler',
513 'Qcache_' => 'qcache',
514 'Threads_' => 'threads',
515 'Slow_launch_threads' => 'threads',
517 'Binlog_cache_' => 'binlog_cache',
518 'Created_tmp_' => 'created_tmp',
519 'Key_' => 'key',
521 'Delayed_' => 'delayed',
522 'Not_flushed_delayed_rows' => 'delayed',
524 'Flush_commands' => 'query',
525 'Last_query_cost' => 'query',
526 'Slow_queries' => 'query',
527 'Queries' => 'query',
528 'Prepared_stmt_count' => 'query',
530 'Select_' => 'select',
531 'Sort_' => 'sort',
533 'Open_tables' => 'table',
534 'Opened_tables' => 'table',
535 'Open_table_definitions' => 'table',
536 'Opened_table_definitions' => 'table',
537 'Table_locks_' => 'table',
539 'Rpl_status' => 'repl',
540 'Slave_' => 'repl',
542 'Tc_' => 'tc',
544 'Ssl_' => 'ssl',
546 'Open_files' => 'files',
547 'Open_streams' => 'files',
548 'Opened_files' => 'files',
551 $sections = array(
552 // section => section name (description)
553 'com' => 'Com',
554 'query' => __('SQL query'),
555 'innodb' => 'InnoDB',
556 'ndb' => 'NDB',
557 'handler' => __('Handler'),
558 'qcache' => __('Query cache'),
559 'threads' => __('Threads'),
560 'binlog_cache' => __('Binary log'),
561 'created_tmp' => __('Temporary data'),
562 'delayed' => __('Delayed inserts'),
563 'key' => __('Key cache'),
564 'select' => __('Joins'),
565 'repl' => __('Replication'),
566 'sort' => __('Sorting'),
567 'table' => __('Tables'),
568 'tc' => __('Transaction coordinator'),
569 'files' => __('Files'),
570 'ssl' => 'SSL',
574 * define some needfull links/commands
576 // variable or section name => (name => url)
577 $links = array();
579 $links['table'][__('Flush (close) all tables')]
580 = $PMA_PHP_SELF . '?flush=TABLES&amp;' . PMA_generate_common_url();
581 $links['table'][__('Show open tables')]
582 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
583 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
585 if ($server_master_status) {
586 $links['repl'][__('Show slave hosts')]
587 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
588 '&amp;goto=server_status.php&amp;' . PMA_generate_common_url();
589 $links['repl'][__('Show master status')] = '#replication_master';
591 if ($server_slave_status) {
592 $links['repl'][__('Show slave status')] = '#replication_slave';
595 $links['repl']['doc'] = 'replication';
597 $links['qcache'][__('Flush query cache')]
598 = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
599 PMA_generate_common_url();
600 $links['qcache']['doc'] = 'query_cache';
602 //$links['threads'][__('Show processes')]
603 // = 'server_processlist.php?' . PMA_generate_common_url();
604 $links['threads']['doc'] = 'mysql_threads';
606 $links['key']['doc'] = 'myisam_key_cache';
608 $links['binlog_cache']['doc'] = 'binary_log';
610 $links['Slow_queries']['doc'] = 'slow_query_log';
612 $links['innodb'][__('Variables')]
613 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
614 $links['innodb'][__('InnoDB Status')]
615 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
616 PMA_generate_common_url();
617 $links['innodb']['doc'] = 'innodb';
620 // Variable to contain all com_ variables
621 $used_queries = array();
623 // Variable to map variable names to their respective section name
624 // (used for js category filtering)
625 $allocationMap = array();
627 // sort vars into arrays
628 foreach ($server_status as $name => $value) {
629 foreach ($allocations as $filter => $section) {
630 if (strpos($name, $filter) !== false) {
631 $allocationMap[$name] = $section;
632 if ($section == 'com' && $value > 0) {
633 $used_queries[$name] = $value;
635 break; // Only exits inner loop
640 if(PMA_DRIZZLE) {
641 $used_queries = PMA_DBI_fetch_result(
642 'SELECT * FROM data_dictionary.global_statements',
646 unset($used_queries['admin_commands']);
647 } else {
648 // admin commands are not queries (e.g. they include COM_PING,
649 // which is excluded from $server_status['Questions'])
650 unset($used_queries['Com_admin_commands']);
653 /* Ajax request refresh */
654 if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
655 switch($_REQUEST['show']) {
656 case 'query_statistics':
657 printQueryStatistics();
658 exit();
659 case 'server_traffic':
660 printServerTraffic();
661 exit();
662 case 'variables_table':
663 // Prints the variables table
664 printVariablesTable();
665 exit();
667 default:
668 break;
672 $server_db_isLocal = strtolower($cfg['Server']['host']) == 'localhost'
673 || $cfg['Server']['host'] == '127.0.0.1'
674 || $cfg['Server']['host'] == '::1';
676 PMA_AddJSVar(
677 'pma_token',
678 $_SESSION[' PMA_token ']
680 PMA_AddJSVar(
681 'url_query',
682 str_replace('&amp;', '&', PMA_generate_common_url($db))
684 PMA_AddJSVar(
685 'server_time_diff',
686 'new Date().getTime() - ' . (microtime(true) * 1000),
687 false
689 PMA_AddJSVar(
690 'server_os',
691 PHP_OS
693 PMA_AddJSVar(
694 'is_superuser',
695 PMA_isSuperuser()
697 PMA_AddJSVar(
698 'server_db_isLocal',
699 $server_db_isLocal
701 PMA_AddJSVar(
702 'profiling_docu',
703 PMA_showMySQLDocu('general-thread-states', 'general-thread-states')
705 PMA_AddJSVar(
706 'explain_docu',
707 PMA_showMySQLDocu('explain-output', 'explain-output')
711 * start output
715 * Does the common work
717 require './libraries/server_common.inc.php';
722 * Displays the links
724 require './libraries/server_links.inc.php';
727 <div id="serverstatus">
728 <h2><?php
730 * Displays the sub-page heading
732 if ($GLOBALS['cfg']['MainPageIconic']) {
733 echo '<img class="icon ic_s_status" src="themes/dot.gif" width="16" height="16" alt="" />';
736 echo __('Runtime Information');
738 ?></h2>
739 <div id="serverStatusTabs">
740 <ul>
741 <li><a href="#statustabs_traffic"><?php echo __('Server'); ?></a></li>
742 <li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
743 <li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
744 <li class="jsfeature"><a href="#statustabs_charting"><?php echo __('Monitor'); ?></a></li>
745 <li class="jsfeature"><a href="#statustabs_advisor"><?php echo __('Advisor'); ?></a></li>
746 </ul>
748 <div id="statustabs_traffic" class="clearfloat">
749 <div class="buttonlinks jsfeature">
750 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&amp;' . PMA_generate_common_url(); ?>" >
751 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
752 <?php echo __('Refresh'); ?>
753 </a>
754 <span class="refreshList" style="display:none;">
755 <label for="id_trafficChartRefresh"><?php echo __('Refresh rate: '); ?></label>
756 <?php refreshList('trafficChartRefresh'); ?>
757 </span>
759 <a class="tabChart livetrafficLink" href="#">
760 <?php echo __('Live traffic chart'); ?>
761 </a>
762 <a class="tabChart liveconnectionsLink" href="#">
763 <?php echo __('Live conn./process chart'); ?>
764 </a>
765 </div>
766 <div class="tabInnerContent">
767 <?php printServerTraffic(); ?>
768 </div>
769 </div>
770 <div id="statustabs_queries" class="clearfloat">
771 <div class="buttonlinks jsfeature">
772 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&amp;' . PMA_generate_common_url(); ?>" >
773 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
774 <?php echo __('Refresh'); ?>
775 </a>
776 <span class="refreshList" style="display:none;">
777 <label for="id_queryChartRefresh"><?php echo __('Refresh rate: '); ?></label>
778 <?php refreshList('queryChartRefresh'); ?>
779 </span>
780 <a class="tabChart livequeriesLink" href="#">
781 <?php echo __('Live query chart'); ?>
782 </a>
783 </div>
784 <div class="tabInnerContent">
785 <?php printQueryStatistics(); ?>
786 </div>
787 </div>
788 <div id="statustabs_allvars" class="clearfloat">
789 <fieldset id="tableFilter" class="jsfeature">
790 <div class="buttonlinks">
791 <a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&amp;' . PMA_generate_common_url(); ?>" >
792 <img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
793 <?php echo __('Refresh'); ?>
794 </a>
795 </div>
796 <legend>Filters</legend>
797 <div class="formelement">
798 <label for="filterText"><?php echo __('Containing the word:'); ?></label>
799 <input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
800 </div>
801 <div class="formelement">
802 <input type="checkbox" name="filterAlert" id="filterAlert" />
803 <label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
804 </div>
805 <div class="formelement">
806 <select id="filterCategory" name="filterCategory">
807 <option value=''><?php echo __('Filter by category...'); ?></option>
808 <?php
809 foreach ($sections as $section_id => $section_name) {
811 <option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
812 <?php
816 </select>
817 </div>
818 <div class="formelement">
819 <input type="checkbox" name="dontFormat" id="dontFormat" />
820 <label for="dontFormat"><?php echo __('Show unformatted values'); ?></label>
821 </div>
822 </fieldset>
823 <div id="linkSuggestions" class="defaultLinks" style="display:none">
824 <p class="notice"><?php echo __('Related links:'); ?>
825 <?php
826 foreach ($links as $section_name => $section_links) {
827 echo '<span class="status_' . $section_name . '"> ';
828 $i=0;
829 foreach ($section_links as $link_name => $link_url) {
830 if ($i > 0) {
831 echo ', ';
833 if ('doc' == $link_name) {
834 echo PMA_showMySQLDocu($link_url, $link_url);
835 } else {
836 echo '<a href="' . $link_url . '">' . $link_name . '</a>';
838 $i++;
840 echo '</span>';
842 unset($link_url, $link_name, $i);
844 </p>
845 </div>
846 <div class="tabInnerContent">
847 <?php printVariablesTable(); ?>
848 </div>
849 </div>
851 <div id="statustabs_charting" class="jsfeature">
852 <?php printMonitor(); ?>
853 </div>
855 <div id="statustabs_advisor" class="jsfeature">
856 <div class="tabLinks">
857 <img src="themes/dot.gif" class="icon ic_play" alt="" /> <a href="#startAnalyzer"><?php echo __('Run analyzer'); ?></a>
858 <img src="themes/dot.gif" class="icon ic_b_help" alt="" /> <a href="#openAdvisorInstructions"><?php echo __('Instructions'); ?></a>
859 </div>
860 <div class="tabInnerContent clearfloat">
861 </div>
862 <div id="advisorInstructionsDialog" style="display:none;">
863 <?php
864 echo '<p>';
865 echo __('The Advisor system can provide recommendations on server variables by analyzing the server status variables.');
866 echo '</p> <p>';
867 echo __('Do note however that this system provides recommendations based on simple calculations and by rule of thumb which may not necessarily apply to your system.');
868 echo '</p> <p>';
869 echo __('Prior to changing any of the configuration, be sure to know what you are changing (by reading the documentation) and how to undo the change. Wrong tuning can have a very negative effect on performance.');
870 echo '</p> <p>';
871 echo __('The best way to tune your system would be to change only one setting at a time, observe or benchmark your database, and undo the change if there was no clearly measurable improvement.');
872 echo '</p>';
874 </div>
875 </div>
876 </div>
877 </div>
879 <?php
881 function printQueryStatistics()
883 global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
885 $hour_factor = 3600 / $server_status['Uptime'];
887 $total_queries = array_sum($used_queries);
890 <h3 id="serverstatusqueries">
891 <?php
892 /* l10n: Questions is the name of a MySQL Status variable */
893 echo sprintf(__('Questions since startup: %s'), PMA_formatNumber($total_queries, 0)) . ' ';
894 echo PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_Questions');
896 <br />
897 <span>
898 <?php
899 echo '&oslash; ' . __('per hour') . ': ';
900 echo PMA_formatNumber($total_queries * $hour_factor, 0);
901 echo '<br />';
903 echo '&oslash; ' . __('per minute') . ': ';
904 echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
905 echo '<br />';
907 if ($total_queries / $server_status['Uptime'] >= 1) {
908 echo '&oslash; ' . __('per second') . ': ';
909 echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
912 </span>
913 </h3>
914 <?php
916 // reverse sort by value to show most used statements first
917 arsort($used_queries);
919 $odd_row = true;
920 $count_displayed_rows = 0;
921 $perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
925 <table id="serverstatusqueriesdetails" class="data sortable noclick">
926 <col class="namecol" />
927 <col class="valuecol" span="3" />
928 <thead>
929 <tr><th><?php echo __('Statements'); ?></th>
930 <th><?php
931 /* l10n: # = Amount of queries */
932 echo __('#');
934 </th>
935 <th>&oslash; <?php echo __('per hour'); ?></th>
936 <th>%</th>
937 </tr>
938 </thead>
939 <tbody>
941 <?php
942 $chart_json = array();
943 $query_sum = array_sum($used_queries);
944 $other_sum = 0;
945 foreach ($used_queries as $name => $value) {
946 $odd_row = !$odd_row;
948 // For the percentage column, use Questions - Connections, because
949 // the number of connections is not an item of the Query types
950 // but is included in Questions. Then the total of the percentages is 100.
951 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
953 // Group together values that make out less than 2% into "Other", but only if we have more than 6 fractions already
954 if ($value < $query_sum * 0.02 && count($chart_json)>6) {
955 $other_sum += $value;
956 } else {
957 $chart_json[$name] = $value;
960 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
961 <th class="name"><?php echo htmlspecialchars($name); ?></th>
962 <td class="value"><?php echo htmlspecialchars(PMA_formatNumber($value, 5, 0, true)); ?></td>
963 <td class="value"><?php echo
964 htmlspecialchars(PMA_formatNumber($value * $hour_factor, 4, 1, true)); ?></td>
965 <td class="value"><?php echo
966 htmlspecialchars(PMA_formatNumber($value * $perc_factor, 0, 2)); ?>%</td>
967 </tr>
968 <?php
971 </tbody>
972 </table>
974 <div id="serverstatusquerieschart">
975 <span style="display:none;">
976 <?php
977 if ($other_sum > 0) {
978 $chart_json[__('Other')] = $other_sum;
981 echo json_encode($chart_json);
983 </span>
984 </div>
985 <?php
988 function printServerTraffic()
990 global $server_status, $PMA_PHP_SELF;
991 global $server_master_status, $server_slave_status, $replication_types;
993 $hour_factor = 3600 / $server_status['Uptime'];
996 * starttime calculation
998 $start_time = PMA_DBI_fetch_value(
999 'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
1002 <h3><?php
1003 echo sprintf(
1004 __('Network traffic since startup: %s'),
1005 implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
1008 </h3>
1011 <?php
1012 echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'),
1013 PMA_timespanFormat($server_status['Uptime']),
1014 PMA_localisedDate($start_time)) . "\n";
1016 </p>
1018 <?php
1019 if ($server_master_status || $server_slave_status) {
1020 echo '<p class="notice">';
1021 if ($server_master_status && $server_slave_status) {
1022 echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
1023 } elseif ($server_master_status) {
1024 echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
1025 } elseif ($server_slave_status) {
1026 echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
1028 echo ' ';
1029 echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
1030 echo '</p>';
1033 /* if the server works as master or slave in replication process, display useful information */
1034 if ($server_master_status || $server_slave_status) {
1036 <hr class="clearfloat" />
1038 <h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
1039 <?php
1041 foreach ($replication_types as $type)
1043 if (${"server_{$type}_status"}) {
1044 PMA_replication_print_status_table($type);
1047 unset($types);
1051 <table id="serverstatustraffic" class="data noclick">
1052 <thead>
1053 <tr>
1054 <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>
1055 <th>&oslash; <?php echo __('per hour'); ?></th>
1056 </tr>
1057 </thead>
1058 <tbody>
1059 <tr class="odd">
1060 <th class="name"><?php echo __('Received'); ?></th>
1061 <td class="value"><?php echo
1062 implode(' ',
1063 PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
1064 <td class="value"><?php echo
1065 implode(' ',
1066 PMA_formatByteDown(
1067 $server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
1068 </tr>
1069 <tr class="even">
1070 <th class="name"><?php echo __('Sent'); ?></th>
1071 <td class="value"><?php echo
1072 implode(' ',
1073 PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
1074 <td class="value"><?php echo
1075 implode(' ',
1076 PMA_formatByteDown(
1077 $server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
1078 </tr>
1079 <tr class="odd">
1080 <th class="name"><?php echo __('Total'); ?></th>
1081 <td class="value"><?php echo
1082 implode(' ',
1083 PMA_formatByteDown(
1084 $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
1085 ); ?></td>
1086 <td class="value"><?php echo
1087 implode(' ',
1088 PMA_formatByteDown(
1089 ($server_status['Bytes_received'] + $server_status['Bytes_sent'])
1090 * $hour_factor, 3, 1)
1091 ); ?></td>
1092 </tr>
1093 </tbody>
1094 </table>
1096 <table id="serverstatusconnections" class="data noclick">
1097 <thead>
1098 <tr>
1099 <th colspan="2"><?php echo __('Connections'); ?></th>
1100 <th>&oslash; <?php echo __('per hour'); ?></th>
1101 <th>%</th>
1102 </tr>
1103 </thead>
1104 <tbody>
1105 <tr class="odd">
1106 <th class="name"><?php echo __('max. concurrent connections'); ?></th>
1107 <td class="value"><?php echo
1108 PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
1109 <td class="value">--- </td>
1110 <td class="value">--- </td>
1111 </tr>
1112 <tr class="even">
1113 <th class="name"><?php echo __('Failed attempts'); ?></th>
1114 <td class="value"><?php echo
1115 PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
1116 <td class="value"><?php echo
1117 PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
1118 4, 2, true); ?></td>
1119 <td class="value"><?php echo
1120 $server_status['Connections'] > 0
1121 ? PMA_formatNumber(
1122 $server_status['Aborted_connects'] * 100 / $server_status['Connections'],
1123 0, 2, true) . '%'
1124 : '--- '; ?></td>
1125 </tr>
1126 <tr class="odd">
1127 <th class="name"><?php echo __('Aborted'); ?></th>
1128 <td class="value"><?php echo
1129 PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
1130 <td class="value"><?php echo
1131 PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
1132 4, 2, true); ?></td>
1133 <td class="value"><?php echo
1134 $server_status['Connections'] > 0
1135 ? PMA_formatNumber(
1136 $server_status['Aborted_clients'] * 100 / $server_status['Connections'],
1137 0, 2, true) . '%'
1138 : '--- '; ?></td>
1139 </tr>
1140 <tr class="even">
1141 <th class="name"><?php echo __('Total'); ?></th>
1142 <td class="value"><?php echo
1143 PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
1144 <td class="value"><?php echo
1145 PMA_formatNumber($server_status['Connections'] * $hour_factor,
1146 4, 2); ?></td>
1147 <td class="value"><?php echo
1148 PMA_formatNumber(100, 0, 2); ?>%</td>
1149 </tr>
1150 </tbody>
1151 </table>
1152 <?php
1154 $url_params = array();
1156 if (! empty($_REQUEST['full'])) {
1157 $sql_query = 'SHOW FULL PROCESSLIST';
1158 $url_params['full'] = 1;
1159 $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
1160 } else {
1161 $sql_query = 'SHOW PROCESSLIST';
1162 $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
1164 $result = PMA_DBI_query($sql_query);
1167 * Displays the page
1170 <table id="tableprocesslist" class="data clearfloat noclick">
1171 <thead>
1172 <tr>
1173 <th><?php echo __('Processes'); ?></th>
1174 <th><?php echo __('ID'); ?></th>
1175 <th><?php echo __('User'); ?></th>
1176 <th><?php echo __('Host'); ?></th>
1177 <th><?php echo __('Database'); ?></th>
1178 <th><?php echo __('Command'); ?></th>
1179 <th><?php echo __('Time'); ?></th>
1180 <th><?php echo __('Status'); ?></th>
1181 <th><?php
1182 echo __('SQL query');
1183 if (! PMA_DRIZZLE) {
1185 <a href="<?php echo $full_text_link; ?>"
1186 title="<?php echo empty($full) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>">
1187 <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (empty($_REQUEST['full']) ? 'full' : 'partial'); ?>text.png"
1188 alt="<?php echo empty($_REQUEST['full']) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>" />
1189 </a>
1190 <?php } ?>
1191 </th>
1192 </tr>
1193 </thead>
1194 <tbody>
1195 <?php
1196 $odd_row = true;
1197 while ($process = PMA_DBI_fetch_assoc($result)) {
1198 if (PMA_DRIZZLE) {
1199 // Drizzle uses uppercase keys
1200 foreach ($process as $k => $v) {
1201 $k = $k !== 'DB'
1202 ? ucfirst(strtolower($k))
1203 : 'db';
1204 $process[$k] = $v;
1207 $url_params['kill'] = $process['Id'];
1208 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
1210 <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
1211 <td><a href="<?php echo $kill_process ; ?>"><?php echo __('Kill'); ?></a></td>
1212 <td class="value"><?php echo $process['Id']; ?></td>
1213 <td><?php echo $process['User']; ?></td>
1214 <td><?php echo $process['Host']; ?></td>
1215 <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : $process['db']); ?></td>
1216 <td><?php echo $process['Command']; ?></td>
1217 <td class="value"><?php echo $process['Time']; ?></td>
1218 <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
1219 <td>
1220 <?php
1221 if (empty($process['Info'])) {
1222 echo '---';
1223 } else {
1224 if (empty($_REQUEST['full']) && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
1225 echo htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
1226 } else {
1227 echo PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
1231 </td>
1232 </tr>
1233 <?php
1234 $odd_row = ! $odd_row;
1237 </tbody>
1238 </table>
1239 <?php
1242 function printVariablesTable()
1244 global $server_status, $server_variables, $allocationMap, $links;
1246 * Messages are built using the message name
1248 $strShowStatus = array(
1249 'Aborted_clients' => __('The number of connections that were aborted because the client died without closing the connection properly.'),
1250 'Aborted_connects' => __('The number of failed attempts to connect to the MySQL server.'),
1251 '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.'),
1252 'Binlog_cache_use' => __('The number of transactions that used the temporary binary log cache.'),
1253 'Connections' => __('The number of connection attempts (successful or not) to the MySQL server.'),
1254 '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.'),
1255 'Created_tmp_files' => __('How many temporary files mysqld has created.'),
1256 'Created_tmp_tables' => __('The number of in-memory temporary tables created automatically by the server while executing statements.'),
1257 'Delayed_errors' => __('The number of rows written with INSERT DELAYED for which some error occurred (probably duplicate key).'),
1258 '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.'),
1259 'Delayed_writes' => __('The number of INSERT DELAYED rows written.'),
1260 'Flush_commands' => __('The number of executed FLUSH statements.'),
1261 'Handler_commit' => __('The number of internal COMMIT statements.'),
1262 'Handler_delete' => __('The number of times a row was deleted from a table.'),
1263 '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.'),
1264 '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.'),
1265 '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.'),
1266 '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.'),
1267 '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.'),
1268 '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.'),
1269 '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.'),
1270 'Handler_rollback' => __('The number of internal ROLLBACK statements.'),
1271 'Handler_update' => __('The number of requests to update a row in a table.'),
1272 'Handler_write' => __('The number of requests to insert a row in a table.'),
1273 'Innodb_buffer_pool_pages_data' => __('The number of pages containing data (dirty or clean).'),
1274 'Innodb_buffer_pool_pages_dirty' => __('The number of pages currently dirty.'),
1275 'Innodb_buffer_pool_pages_flushed' => __('The number of buffer pool pages that have been requested to be flushed.'),
1276 'Innodb_buffer_pool_pages_free' => __('The number of free pages.'),
1277 '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.'),
1278 '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.'),
1279 'Innodb_buffer_pool_pages_total' => __('Total size of buffer pool, in pages.'),
1280 '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.'),
1281 'Innodb_buffer_pool_read_ahead_seq' => __('The number of sequential read-aheads InnoDB initiated. This happens when InnoDB does a sequential full table scan.'),
1282 'Innodb_buffer_pool_read_requests' => __('The number of logical read requests InnoDB has done.'),
1283 '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.'),
1284 '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.'),
1285 'Innodb_buffer_pool_write_requests' => __('The number writes done to the InnoDB buffer pool.'),
1286 'Innodb_data_fsyncs' => __('The number of fsync() operations so far.'),
1287 'Innodb_data_pending_fsyncs' => __('The current number of pending fsync() operations.'),
1288 'Innodb_data_pending_reads' => __('The current number of pending reads.'),
1289 'Innodb_data_pending_writes' => __('The current number of pending writes.'),
1290 'Innodb_data_read' => __('The amount of data read so far, in bytes.'),
1291 'Innodb_data_reads' => __('The total number of data reads.'),
1292 'Innodb_data_writes' => __('The total number of data writes.'),
1293 'Innodb_data_written' => __('The amount of data written so far, in bytes.'),
1294 'Innodb_dblwr_pages_written' => __('The number of pages that have been written for doublewrite operations.'),
1295 'Innodb_dblwr_writes' => __('The number of doublewrite operations that have been performed.'),
1296 '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.'),
1297 'Innodb_log_write_requests' => __('The number of log write requests.'),
1298 'Innodb_log_writes' => __('The number of physical writes to the log file.'),
1299 'Innodb_os_log_fsyncs' => __('The number of fsync() writes done to the log file.'),
1300 'Innodb_os_log_pending_fsyncs' => __('The number of pending log file fsyncs.'),
1301 'Innodb_os_log_pending_writes' => __('Pending log file writes.'),
1302 'Innodb_os_log_written' => __('The number of bytes written to the log file.'),
1303 'Innodb_pages_created' => __('The number of pages created.'),
1304 '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.'),
1305 'Innodb_pages_read' => __('The number of pages read.'),
1306 'Innodb_pages_written' => __('The number of pages written.'),
1307 'Innodb_row_lock_current_waits' => __('The number of row locks currently being waited for.'),
1308 'Innodb_row_lock_time_avg' => __('The average time to acquire a row lock, in milliseconds.'),
1309 'Innodb_row_lock_time' => __('The total time spent in acquiring row locks, in milliseconds.'),
1310 'Innodb_row_lock_time_max' => __('The maximum time to acquire a row lock, in milliseconds.'),
1311 'Innodb_row_lock_waits' => __('The number of times a row lock had to be waited for.'),
1312 'Innodb_rows_deleted' => __('The number of rows deleted from InnoDB tables.'),
1313 'Innodb_rows_inserted' => __('The number of rows inserted in InnoDB tables.'),
1314 'Innodb_rows_read' => __('The number of rows read from InnoDB tables.'),
1315 'Innodb_rows_updated' => __('The number of rows updated in InnoDB tables.'),
1316 '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.'),
1317 '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.'),
1318 '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.'),
1319 'Key_read_requests' => __('The number of requests to read a key block from the cache.'),
1320 '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.'),
1321 'Key_write_requests' => __('The number of requests to write a key block to the cache.'),
1322 'Key_writes' => __('The number of physical writes of a key block to disk.'),
1323 '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.'),
1324 'Max_used_connections' => __('The maximum number of connections that have been in use simultaneously since the server started.'),
1325 'Not_flushed_delayed_rows' => __('The number of rows waiting to be written in INSERT DELAYED queues.'),
1326 'Opened_tables' => __('The number of tables that have been opened. If opened tables is big, your table cache value is probably too small.'),
1327 'Open_files' => __('The number of files that are open.'),
1328 'Open_streams' => __('The number of streams that are open (used mainly for logging).'),
1329 'Open_tables' => __('The number of tables that are open.'),
1330 '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.'),
1331 'Qcache_free_memory' => __('The amount of free memory for query cache.'),
1332 'Qcache_hits' => __('The number of cache hits.'),
1333 'Qcache_inserts' => __('The number of queries added to the cache.'),
1334 '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.'),
1335 'Qcache_not_cached' => __('The number of non-cached queries (not cachable, or not cached due to the query_cache_type setting).'),
1336 'Qcache_queries_in_cache' => __('The number of queries registered in the cache.'),
1337 'Qcache_total_blocks' => __('The total number of blocks in the query cache.'),
1338 'Rpl_status' => __('The status of failsafe replication (not yet implemented).'),
1339 '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.'),
1340 'Select_full_range_join' => __('The number of joins that used a range search on a reference table.'),
1341 '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.)'),
1342 'Select_range' => __('The number of joins that used ranges on the first table. (It\'s normally not critical even if this is big.)'),
1343 'Select_scan' => __('The number of joins that did a full scan of the first table.'),
1344 'Slave_open_temp_tables' => __('The number of temporary tables currently open by the slave SQL thread.'),
1345 'Slave_retried_transactions' => __('Total (since startup) number of times the replication slave SQL thread has retried transactions.'),
1346 'Slave_running' => __('This is ON if this server is a slave that is connected to a master.'),
1347 'Slow_launch_threads' => __('The number of threads that have taken more than slow_launch_time seconds to create.'),
1348 'Slow_queries' => __('The number of queries that have taken more than long_query_time seconds.'),
1349 '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.'),
1350 'Sort_range' => __('The number of sorts that were done with ranges.'),
1351 'Sort_rows' => __('The number of sorted rows.'),
1352 'Sort_scan' => __('The number of sorts that were done by scanning the table.'),
1353 'Table_locks_immediate' => __('The number of times that a table lock was acquired immediately.'),
1354 '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.'),
1355 '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.'),
1356 'Threads_connected' => __('The number of currently open connections.'),
1357 '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.)'),
1358 'Threads_running' => __('The number of threads that are not sleeping.')
1362 * define some alerts
1364 // name => max value before alert
1365 $alerts = array(
1366 // lower is better
1367 // variable => max value
1368 'Aborted_clients' => 0,
1369 'Aborted_connects' => 0,
1371 'Binlog_cache_disk_use' => 0,
1373 'Created_tmp_disk_tables' => 0,
1375 'Handler_read_rnd' => 0,
1376 'Handler_read_rnd_next' => 0,
1378 'Innodb_buffer_pool_pages_dirty' => 0,
1379 'Innodb_buffer_pool_reads' => 0,
1380 'Innodb_buffer_pool_wait_free' => 0,
1381 'Innodb_log_waits' => 0,
1382 'Innodb_row_lock_time_avg' => 10, // ms
1383 'Innodb_row_lock_time_max' => 50, // ms
1384 'Innodb_row_lock_waits' => 0,
1386 'Slow_queries' => 0,
1387 'Delayed_errors' => 0,
1388 'Select_full_join' => 0,
1389 'Select_range_check' => 0,
1390 'Sort_merge_passes' => 0,
1391 'Opened_tables' => 0,
1392 'Table_locks_waited' => 0,
1393 'Qcache_lowmem_prunes' => 0,
1395 'Qcache_free_blocks' => $server_status['Qcache_total_blocks'] / 5,
1396 'Slow_launch_threads' => 0,
1398 // depends on Key_read_requests
1399 // normaly lower then 1:0.01
1400 'Key_reads' => (0.01 * $server_status['Key_read_requests']),
1401 // depends on Key_write_requests
1402 // normaly nearly 1:1
1403 'Key_writes' => (0.9 * $server_status['Key_write_requests']),
1405 'Key_buffer_fraction' => 0.5,
1407 // alert if more than 95% of thread cache is in use
1408 'Threads_cached' => 0.95 * $server_variables['thread_cache_size']
1410 // higher is better
1411 // variable => min value
1412 //'Handler read key' => '> ',
1416 <table class="data sortable noclick" id="serverstatusvariables">
1417 <col class="namecol" />
1418 <col class="valuecol" />
1419 <col class="descrcol" />
1420 <thead>
1421 <tr>
1422 <th><?php echo __('Variable'); ?></th>
1423 <th><?php echo __('Value'); ?></th>
1424 <th><?php echo __('Description'); ?></th>
1425 </tr>
1426 </thead>
1427 <tbody>
1428 <?php
1430 $odd_row = false;
1431 foreach ($server_status as $name => $value) {
1432 $odd_row = !$odd_row;
1434 <tr class="<?php echo $odd_row ? 'odd' : 'even'; echo isset($allocationMap[$name])?' s_' . $allocationMap[$name]:''; ?>">
1435 <th class="name"><?php echo htmlspecialchars(str_replace('_', ' ', $name)) . PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_' . $name); ?>
1436 </th>
1437 <td class="value"><span class="formatted"><?php
1438 if (isset($alerts[$name])) {
1439 if ($value > $alerts[$name]) {
1440 echo '<span class="attention">';
1441 } else {
1442 echo '<span class="allfine">';
1445 if ('%' === substr($name, -1, 1)) {
1446 echo htmlspecialchars(PMA_formatNumber($value, 0, 2)) . ' %';
1447 } elseif (strpos($name, 'Uptime')!==FALSE) {
1448 echo htmlspecialchars(PMA_timespanFormat($value));
1449 } elseif (is_numeric($value) && $value == (int) $value && $value > 1000) {
1450 echo htmlspecialchars(PMA_formatNumber($value, 3, 1));
1451 } elseif (is_numeric($value) && $value == (int) $value) {
1452 echo htmlspecialchars(PMA_formatNumber($value, 3, 0));
1453 } elseif (is_numeric($value)) {
1454 echo htmlspecialchars(PMA_formatNumber($value, 3, 1));
1455 } else {
1456 echo htmlspecialchars($value);
1458 if (isset($alerts[$name])) {
1459 echo '</span>';
1461 ?></span><span style="display:none;" class="original"><?php echo $value; ?></span>
1462 </td>
1463 <td class="descr">
1464 <?php
1465 if (isset($strShowStatus[$name ])) {
1466 echo $strShowStatus[$name];
1469 if (isset($links[$name])) {
1470 foreach ($links[$name] as $link_name => $link_url) {
1471 if ('doc' == $link_name) {
1472 echo PMA_showMySQLDocu($link_url, $link_url);
1473 } else {
1474 echo ' <a href="' . $link_url . '">' . $link_name . '</a>' .
1475 "\n";
1478 unset($link_url, $link_name);
1481 </td>
1482 </tr>
1483 <?php
1486 </tbody>
1487 </table>
1488 <?php
1491 function printMonitor()
1493 global $server_status, $server_db_isLocal;
1495 <div class="tabLinks" style="display:none;">
1496 <a href="#pauseCharts">
1497 <img src="themes/dot.gif" class="icon ic_play" alt="" />
1498 <?php echo __('Start Monitor'); ?>
1499 </a>
1500 <a href="#settingsPopup" rel="popupLink" style="display:none;">
1501 <img src="themes/dot.gif" class="icon ic_s_cog" alt="" />
1502 <?php echo __('Settings'); ?>
1503 </a>
1504 <a href="#monitorInstructionsDialog">
1505 <img src="themes/dot.gif" class="icon ic_b_help" alt="" />
1506 <?php echo __('Instructions/Setup'); ?>
1507 </a>
1508 <a href="#endChartEditMode" style="display:none;">
1509 <img src="themes/dot.gif" class="icon ic_s_okay" alt="" />
1510 <?php echo __('Done rearranging/editing charts'); ?>
1511 </a>
1512 </div>
1514 <div class="popupContent settingsPopup">
1515 <a href="#addNewChart">
1516 <img src="themes/dot.gif" class="icon ic_b_chart" alt="" />
1517 <?php echo __('Add chart'); ?>
1518 </a>
1519 <a href="#rearrangeCharts"><img class="icon ic_b_tblops" src="themes/dot.gif" width="16" height="16" alt="" /><?php echo __('Rearrange/edit charts'); ?></a>
1520 <div class="clearfloat paddingtop"></div>
1521 <div class="floatleft">
1522 <?php
1523 echo __('Refresh rate') . '<br />';
1524 refreshList('gridChartRefresh', 5, Array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200));
1525 ?><br />
1526 </div>
1527 <div class="floatleft">
1528 <?php echo __('Chart columns'); ?> <br />
1529 <select name="chartColumns">
1530 <option>1</option>
1531 <option>2</option>
1532 <option>3</option>
1533 <option>4</option>
1534 <option>5</option>
1535 <option>6</option>
1536 <option>7</option>
1537 <option>8</option>
1538 <option>9</option>
1539 <option>10</option>
1540 </select>
1541 </div>
1543 <div class="clearfloat paddingtop">
1544 <b><?php echo __('Chart arrangement'); ?></b> <?php echo PMA_showHint(__('The arrangement of the charts is stored to the browsers local storage. You may want to export it if you have a complicated set up.')); ?><br/>
1545 <a href="#importMonitorConfig"><?php echo __('Import'); ?></a>&nbsp;&nbsp;<a href="#exportMonitorConfig"><?php echo __('Export'); ?></a>&nbsp;&nbsp;<a href="#clearMonitorConfig"><?php echo __('Reset to default'); ?></a>
1546 </div>
1547 </div>
1549 <div id="monitorInstructionsDialog" title="<?php echo __('Monitor Instructions'); ?>" style="display:none;">
1550 <?php echo __('The phpMyAdmin Monitor can assist you in optimizing the server configuration and track down time intensive 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 general_log produces a lot of data and increases server load by up to 15%'); ?>
1551 <?php if (PMA_MYSQL_INT_VERSION < 50106) { ?>
1553 <img class="icon ic_s_attention" src="themes/dot.gif" alt="" />
1554 <?php
1555 echo __('Unfortunately your Database server does not support logging to table, which is a requirement for analyzing the database logs with phpMyAdmin. Logging to table is supported by MySQL 5.1.6 and onwards. You may still use the server charting features however.');
1557 </p>
1558 <?php
1559 } else {
1561 <p></p>
1562 <img class="ajaxIcon" src="<?php echo $GLOBALS['pmaThemeImage']; ?>ajax_clock_small.gif" alt="Loading" />
1563 <div class="ajaxContent"></div>
1564 <div class="monitorUse" style="display:none;">
1565 <p></p>
1566 <?php
1567 echo '<strong>';
1568 echo __('Using the monitor:');
1569 echo '</strong><p>';
1570 echo __('Ok, you are good to go! Once you click \'Start monitor\' your browser will refresh all displayed charts in a regular interval. You may add charts and change the refresh rate under \'Settings\', or remove any chart using the cog icon on each respective chart.');
1571 echo '</p><p>';
1572 echo __('To display queries from the logs, select the relevant time span on any chart by holding down the left mouse button and panning over the chart. Once confirmed, this will load a table of grouped queries, there you may click on any occuring SELECT statements to further analyze them.');
1573 echo '</p>';
1576 <img class="icon ic_s_attention" src="themes/dot.gif" alt="" />
1577 <?php
1578 echo '<strong>';
1579 echo __('Please note:');
1580 echo '</strong><br />';
1581 echo __('Enabling the general_log may increase the server load by 5-15%. Also be aware that generating statistics from the logs is a 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.');
1583 </p>
1584 </div>
1585 <?php } ?>
1586 </div>
1588 <div id="addChartDialog" title="Add chart" style="display:none;">
1589 <div id="tabGridVariables">
1590 <p><input type="text" name="chartTitle" value="<?php echo __('Chart Title'); ?>" /></p>
1592 <input type="radio" name="chartType" value="preset" id="chartPreset" />
1593 <label for="chartPreset"><?php echo __('Preset chart'); ?></label>
1594 <select name="presetCharts"></select><br/>
1596 <input type="radio" name="chartType" value="variable" id="chartStatusVar" checked="checked" />
1597 <label for="chartStatusVar"><?php echo __('Status variable(s)'); ?></label><br/>
1598 <div id="chartVariableSettings">
1599 <label for="chartSeries"><?php echo __('Select series:'); ?></label><br />
1600 <select id="chartSeries" name="varChartList" size="1">
1601 <option><?php echo __('Commonly monitored'); ?></option>
1602 <option>Processes</option>
1603 <option>Questions</option>
1604 <option>Connections</option>
1605 <option>Bytes_sent</option>
1606 <option>Bytes_received</option>
1607 <option>Threads_connected</option>
1608 <option>Created_tmp_disk_tables</option>
1609 <option>Handler_read_first</option>
1610 <option>Innodb_buffer_pool_wait_free</option>
1611 <option>Key_reads</option>
1612 <option>Open_tables</option>
1613 <option>Select_full_join</option>
1614 <option>Slow_queries</option>
1615 </select><br />
1616 <label for="variableInput"><?php echo __('or type variable name:'); ?> </label>
1617 <input type="text" name="variableInput" id="variableInput" />
1618 <p></p>
1619 <input type="checkbox" name="differentialValue" id="differentialValue" value="differential" checked="checked" />
1620 <label for="differentialValue"><?php echo __('Display as differential value'); ?></label><br />
1621 <input type="checkbox" id="useDivisor" name="useDivisor" value="1" />
1622 <label for="useDivisor"><?php echo __('Apply a divisor'); ?></label>
1623 <span class="divisorInput" style="display:none;">
1624 <input type="text" name="valueDivisor" size="4" value="1" />
1625 (<a href="#kibDivisor"><?php echo __('KiB'); ?></a>, <a href="#mibDivisor"><?php echo __('MiB'); ?></a>)
1626 </span><br />
1628 <input type="checkbox" id="useUnit" name="useUnit" value="1" />
1629 <label for="useUnit"><?php echo __('Append unit to data values'); ?></label>
1631 <span class="unitInput" style="display:none;">
1632 <input type="text" name="valueUnit" size="4" value="" />
1633 </span>
1635 <a href="#submitAddSeries"><b><?php echo __('Add this series'); ?></b></a>
1636 <span id="clearSeriesLink" style="display:none;">
1637 | <a href="#submitClearSeries"><?php echo __('Clear series'); ?></a>
1638 </span>
1639 </p>
1640 <?php echo __('Series in Chart:'); ?><br/>
1641 <span id="seriesPreview">
1642 <i><?php echo __('None'); ?></i>
1643 </span>
1644 </div>
1645 </div>
1646 </div>
1648 <!-- For generic use -->
1649 <div id="emptyDialog" title="Dialog" style="display:none;">
1650 </div>
1652 <div id="logAnalyseDialog" title="<?php echo __('Log statistics'); ?>" style="display:none;">
1653 <p> <?php echo __('Selected time range:'); ?>
1654 <input type="text" name="dateStart" class="datetimefield" value="" /> -
1655 <input type="text" name="dateEnd" class="datetimefield" value="" /></p>
1656 <input type="checkbox" id="limitTypes" value="1" checked="checked" />
1657 <label for="limitTypes">
1658 <?php echo __('Only retrieve SELECT,INSERT,UPDATE and DELETE Statements'); ?>
1659 </label>
1660 <br/>
1661 <input type="checkbox" id="removeVariables" value="1" checked="checked" />
1662 <label for="removeVariables">
1663 <?php echo __('Remove variable data in INSERT statements for better grouping'); ?>
1664 </label>
1666 <?php
1667 echo '<p>';
1668 echo __('Choose from which log you want the statistics to be generated from.');
1669 echo '</p><p>';
1670 echo __('Results are grouped by query text.');
1671 echo '</p>';
1673 </div>
1675 <div id="queryAnalyzerDialog" title="<?php echo __('Query analyzer'); ?>" style="display:none;">
1676 <textarea id="sqlquery"> </textarea>
1677 <p></p>
1678 <div class="placeHolder"></div>
1679 </div>
1681 <table border="0" class="clearfloat" id="chartGrid">
1683 </table>
1684 <div id="logTable">
1685 <br/>
1686 </div>
1688 <script type="text/javascript">
1689 variableNames = [ <?php
1690 $i=0;
1691 foreach ($server_status as $name=>$value) {
1692 if (is_numeric($value)) {
1693 if ($i++ > 0) {
1694 echo ", ";
1696 echo "'" . $name . "'";
1699 ?> ];
1700 </script>
1701 <?php
1704 /* Builds a <select> list for refresh rates */
1705 function refreshList($name, $defaultRate=5, $refreshRates=Array(1, 2, 5, 10, 20, 40, 60, 120, 300, 600))
1708 <select name="<?php echo $name; ?>" id="id_<?php echo $name; ?>">
1709 <?php
1710 foreach ($refreshRates as $rate) {
1711 $selected = ($rate == $defaultRate)?' selected="selected"':'';
1713 if ($rate<60) {
1714 echo '<option value="' . $rate . '"' . $selected . '>' . sprintf(_ngettext('%d second', '%d seconds', $rate), $rate) . '</option>';
1715 } else {
1716 echo '<option value="' . $rate . '"' . $selected . '>' . sprintf(_ngettext('%d minute', '%d minutes', $rate/60), $rate/60) . '</option>';
1720 </select>
1721 <?php
1725 * cleanup of some deprecated values
1727 * @param array &$server_status
1729 function cleanDeprecated(&$server_status)
1731 $deprecated = array(
1732 'Com_prepare_sql' => 'Com_stmt_prepare',
1733 'Com_execute_sql' => 'Com_stmt_execute',
1734 'Com_dealloc_sql' => 'Com_stmt_close',
1737 foreach ($deprecated as $old => $new) {
1738 if (isset($server_status[$old]) && isset($server_status[$new])) {
1739 unset($server_status[$old]);
1745 * Sends the footer
1747 require './libraries/footer.inc.php';