The branch, master has been updated via 23c5e3282fb1ce89ec6cdb5004c6f36aedcda2bc (commit) from 4ee15be98627dcc5e7de721a9fe69d3aabeefd41 (commit)
- Log ----------------------------------------------------------------- commit 23c5e3282fb1ce89ec6cdb5004c6f36aedcda2bc Author: Piotr Przybylski piotrprz@gmail.com Date: Wed Jul 20 18:38:37 2011 +0200
Code formatting
-----------------------------------------------------------------------
Summary of changes: server_status.php | 135 +++++++++++++++++++++++++++++------------------------ 1 files changed, 74 insertions(+), 61 deletions(-)
diff --git a/server_status.php b/server_status.php index 004a536..28d6858 100644 --- a/server_status.php +++ b/server_status.php @@ -44,16 +44,18 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { header('Content-Type: text/html; charset=UTF-8');
if (isset($_REQUEST['logging_vars'])) { - if(isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) { + if (isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) { $value = PMA_sqlAddslashes($_REQUEST['varValue']); - if(!is_numeric($value)) $value="'".$value."'"; + if (!is_numeric($value)) $value="'".$value."'";
- if(! preg_match("/[^a-zA-Z0-9_]+/",$_REQUEST['varName'])) - PMA_DBI_query('SET GLOBAL '.$_REQUEST['varName'].' = '.$value); + if (!preg_match("/[^a-zA-Z0-9_]+/",$_REQUEST['varName'])) + PMA_DBI_query('SET GLOBAL ' . $_REQUEST['varName'] . ' = '.$value);
}
- $loggingVars = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES WHERE Variable_name IN ("general_log","slow_query_log","long_query_time","log_output")', 0, 1); + $loggingVars = PMA_DBI_fetch_result( + "SHOW GLOBAL VARIABLES WHERE Variable_name IN ( + 'general_log', 'slow_query_log', 'long_query_time', 'log_output')", 0, 1); exit(json_encode($loggingVars)); }
@@ -61,7 +63,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { if (isset($_REQUEST['chart_data'])) { switch($_REQUEST['type']) { case 'proc': - $c = PMA_DBI_fetch_result('SHOW GLOBAL STATUS WHERE Variable_name="Connections"', 0, 1); + $c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1); $result = PMA_DBI_query('SHOW PROCESSLIST'); $num_procs = PMA_DBI_num_rows($result);
@@ -74,7 +76,10 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { exit(json_encode($ret));
case 'queries': - $queries = PMA_DBI_fetch_result('SHOW GLOBAL STATUS WHERE Variable_name LIKE "Com_%" OR Variable_name="Questions" AND Value>0', 0, 1); + $queries = PMA_DBI_fetch_result( + "SHOW GLOBAL STATUS + WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions') + AND Value > 0'", 0, 1); cleanDeprecated($queries); // admin commands are not queries unset($queries['Com_admin_commands']); @@ -91,7 +96,10 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { exit(json_encode($ret));
case 'traffic': - $traffic = PMA_DBI_fetch_result('SHOW GLOBAL STATUS WHERE Variable_name="Bytes_received" OR Variable_name="Bytes_sent"', 0, 1); + $traffic = PMA_DBI_fetch_result( + "SHOW GLOBAL STATUS + WHERE Variable_name = 'Bytes_received' + OR Variable_name = 'Bytes_sent'", 0, 1);
$ret = array( 'x' => microtime(true)*1000, @@ -102,16 +110,16 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { exit(json_encode($ret));
case 'chartgrid': - $ret = json_decode($_REQUEST['requiredData'],true); - $statusVars = Array(); + $ret = json_decode($_REQUEST['requiredData'], true); + $statusVars = array(); $sysinfo = $cpuload = $memory = 0;
- foreach($ret as $chart_id=>$chartNodes) { - foreach($chartNodes as $node_id=>$node) { - switch($node['dataType']) { + foreach ($ret as $chart_id => $chartNodes) { + foreach ($chartNodes as $node_id => $node) { + switch ($node['dataType']) { case 'statusvar': // Some white list filtering - if(! preg_match('/[^a-zA-Z_]+/',$node['name'])) + if (!preg_match('/[^a-zA-Z_]+/',$node['name'])) $statusVars[] = $node['name']; break;
@@ -121,14 +129,14 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { break;
case 'cpu': - if(! $sysinfo) { + if (!$sysinfo) { require_once('libraries/sysinfo.lib.php'); $sysinfo = getSysInfo(); } - if(! $cpuload) + if (!$cpuload) $cpuload = $sysinfo->loadavg();
- if(PHP_OS == 'Linux') { + if (PHP_OS == 'Linux') { $ret[$chart_id][$node_id]['idle'] = $cpuload['idle']; $ret[$chart_id][$node_id]['busy'] = $cpuload['busy']; } else @@ -137,11 +145,11 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { break;
case 'memory': - if(! $sysinfo) { + if (!$sysinfo) { require_once('libraries/sysinfo.lib.php'); $sysinfo = getSysInfo(); } - if(! $memory) + if (!$memory) $memory = $sysinfo->memory();
$ret[$chart_id][$node_id]['y'] = $memory[$node['name']]; @@ -150,11 +158,13 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { } }
- $vars = PMA_DBI_fetch_result('SHOW GLOBAL STATUS WHERE Variable_name="' . implode('" OR Variable_name="',$statusVars) . '"', 0, 1); + $vars = PMA_DBI_fetch_result( + "SHOW GLOBAL STATUS + WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1);
- foreach($ret as $chart_id=>$chartNodes) { - foreach($chartNodes as $node_id=>$node) { - if($node['dataType'] == 'statusvar') + foreach ($ret as $chart_id => $chartNodes) { + foreach ($chartNodes as $node_id => $node) { + if ($node['dataType'] == 'statusvar') $ret[$chart_id][$node_id]['y'] = $vars[$node['name']]; } } @@ -165,11 +175,11 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { } }
- if(isset($_REQUEST['log_data'])) { + if (isset($_REQUEST['log_data'])) { $start = intval($_REQUEST['time_start']); $end = intval($_REQUEST['time_end']);
- if($_REQUEST['type'] == 'slow') { + if ($_REQUEST['type'] == 'slow') { $q = 'SELECT SUM(query_time) AS TIME(query_time), SUM(lock_time) as lock_time, '. 'SUM(rows_sent) AS rows_sent, SUM(rows_examined) AS rows_examined, sql_text, COUNT(sql_text) AS '#' '. 'FROM `mysql`.`slow_log` WHERE event_time > FROM_UNIXTIME('.$start.') '. @@ -177,7 +187,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
$result = PMA_DBI_try_query($q);
- $return = array( 'rows' => array(), 'sum' => array()); + $return = array('rows' => array(), 'sum' => array()); $type = '';
while ($row = PMA_DBI_fetch_assoc($result)) { @@ -193,14 +203,14 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { exit(json_encode($return)); }
- if($_REQUEST['type'] == 'general') { + if ($_REQUEST['type'] == 'general') { $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' '. 'AND event_time > FROM_UNIXTIME('.$start.') AND event_time < FROM_UNIXTIME('.$end.') '. 'AND argument REGEXP '^(INSERT|SELECT|UPDATE|DELETE)' GROUP by argument'; // HAVING count > 1';
$result = PMA_DBI_try_query($q);
- $return = array( 'rows' => array(), 'sum' => array()); + $return = array('rows' => array(), 'sum' => array()); $type = ''; $insertTables = array(); $insertTablesFirst = -1; @@ -231,9 +241,10 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { }
// Cut off big selects, but append byte count therefor - if(strlen($row['argument']) > 180) + if (strlen($row['argument']) > 180) { $row['argument'] = substr($row['argument'],0,160) . '... [' . PMA_formatByteDown(strlen($row['argument']), 2).']'; + } } $return['rows'][] = $row; $i++; @@ -325,43 +336,44 @@ cleanDeprecated($server_status); */ // Key_buffer_fraction if (isset($server_status['Key_blocks_unused']) - && isset($server_variables['key_cache_block_size']) - && isset($server_variables['key_buffer_size'])) { + && isset($server_variables['key_cache_block_size']) + && isset($server_variables['key_buffer_size'])) { $server_status['Key_buffer_fraction_%'] = 100 - - $server_status['Key_blocks_unused'] - * $server_variables['key_cache_block_size'] - / $server_variables['key_buffer_size'] - * 100; -} elseif ( - isset($server_status['Key_blocks_used']) - && isset($server_variables['key_buffer_size'])) { + - $server_status['Key_blocks_unused'] + * $server_variables['key_cache_block_size'] + / $server_variables['key_buffer_size'] + * 100; +} elseif (isset($server_status['Key_blocks_used']) + && isset($server_variables['key_buffer_size'])) { $server_status['Key_buffer_fraction_%'] = $server_status['Key_blocks_used'] - * 1024 - / $server_variables['key_buffer_size']; + * 1024 + / $server_variables['key_buffer_size']; }
// Ratio for key read/write if (isset($server_status['Key_writes']) - && isset($server_status['Key_write_requests']) - && $server_status['Key_write_requests'] > 0) - $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests']; + && isset($server_status['Key_write_requests']) + && $server_status['Key_write_requests'] > 0) { + $server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests']; +}
if (isset($server_status['Key_reads']) - && isset($server_status['Key_read_requests']) - && $server_status['Key_read_requests'] > 0) - $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests']; + && isset($server_status['Key_read_requests']) + && $server_status['Key_read_requests'] > 0) { + $server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests']; +}
// Threads_cache_hitrate if (isset($server_status['Threads_created']) - && isset($server_status['Connections']) - && $server_status['Connections'] > 0) { + && isset($server_status['Connections']) + && $server_status['Connections'] > 0) { $server_status['Threads_cache_hitrate_%'] = 100 - - $server_status['Threads_created'] - / $server_status['Connections'] - * 100; + - $server_status['Threads_created'] + / $server_status['Connections'] + * 100; }
// Format Uptime_since_flush_status : show as days, hours, minutes, seconds @@ -450,23 +462,23 @@ $links['table'][__('Flush (close) all tables')] = $PMA_PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url(); $links['table'][__('Show open tables')] = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') . - '&goto=server_status.php&' . PMA_generate_common_url(); + '&goto=server_status.php&' . PMA_generate_common_url();
if ($server_master_status) { - $links['repl'][__('Show slave hosts')] - = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') . - '&goto=server_status.php&' . PMA_generate_common_url(); - $links['repl'][__('Show master status')] = '#replication_master'; + $links['repl'][__('Show slave hosts')] + = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') . + '&goto=server_status.php&' . PMA_generate_common_url(); + $links['repl'][__('Show master status')] = '#replication_master'; } if ($server_slave_status) { - $links['repl'][__('Show slave status')] = '#replication_slave'; + $links['repl'][__('Show slave status')] = '#replication_slave'; }
$links['repl']['doc'] = 'replication';
$links['qcache'][__('Flush query cache')] = $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' . - PMA_generate_common_url(); + PMA_generate_common_url(); $links['qcache']['doc'] = 'query_cache';
//$links['threads'][__('Show processes')] @@ -483,7 +495,7 @@ $links['innodb'][__('Variables')] = 'server_engines.php?engine=InnoDB&' . PMA_generate_common_url(); $links['innodb'][__('InnoDB Status')] = 'server_engines.php?engine=InnoDB&page=Status&' . - PMA_generate_common_url(); + PMA_generate_common_url(); $links['innodb']['doc'] = 'innodb';
@@ -1453,6 +1465,8 @@ function refreshList($name,$defaultRate=5, $refreshRates=Array(1, 2, 5, 10, 20,
/** * cleanup of some deprecated values + * + * @param array &$server_status */ function cleanDeprecated(&$server_status) { $deprecated = array( @@ -1462,8 +1476,7 @@ function cleanDeprecated(&$server_status) { );
foreach ($deprecated as $old => $new) { - if (isset($server_status[$old]) - && isset($server_status[$new])) { + if (isset($server_status[$old]) && isset($server_status[$new])) { unset($server_status[$old]); } }
hooks/post-receive