Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / ServerStatusData.class.php
blobde23d47e87e2a66c21499d70ddcd8f8e13ce09c4
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * PMA_ServerStatusData class
5 * Used by server_status_*.php pages
7 * @package PhpMyAdmin
8 */
10 require_once 'libraries/common.inc.php';
12 /**
13 * This class provides data about the server status
15 * All properties of the class are read-only
17 * TODO: Use lazy initialisation for some of the properties
18 * since not all of the server_status_*.php pages need
19 * all the data that this class provides.
21 * @package PhpMyAdmin
23 class PMA_ServerStatusData
25 public $status;
26 public $sections;
27 public $variables;
28 public $used_queries;
29 public $allocationMap;
30 public $links;
31 public $db_isLocal;
32 public $section;
33 public $categoryUsed;
34 public $selfUrl;
36 /**
37 * An empty setter makes the above properties read-only
39 * @param string $a key
40 * @param mixed $b value
42 * @return void
44 public function __set($a, $b)
46 // Discard everything
49 /**
50 * Constructor
52 * @return object
54 public function __construct()
56 $this->selfUrl = basename($GLOBALS['PMA_PHP_SELF']);
57 /**
58 * get status from server
60 $server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
61 if (PMA_DRIZZLE) {
62 // Drizzle doesn't put query statistics into variables, add it
63 $sql = "SELECT concat('Com_', variable_name), variable_value
64 FROM data_dictionary.GLOBAL_STATEMENTS";
65 $statements = PMA_DBI_fetch_result($sql, 0, 1);
66 $server_status = array_merge($server_status, $statements);
69 /**
70 * for some calculations we require also some server settings
72 $server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
74 /**
75 * cleanup of some deprecated values
77 $server_status = self::cleanDeprecated($server_status);
79 /**
80 * calculate some values
82 // Key_buffer_fraction
83 if (isset($server_status['Key_blocks_unused'])
84 && isset($server_variables['key_cache_block_size'])
85 && isset($server_variables['key_buffer_size'])
86 ) {
87 $server_status['Key_buffer_fraction_%']
88 = 100
89 - $server_status['Key_blocks_unused']
90 * $server_variables['key_cache_block_size']
91 / $server_variables['key_buffer_size']
92 * 100;
93 } elseif (isset($server_status['Key_blocks_used'])
94 && isset($server_variables['key_buffer_size'])) {
95 $server_status['Key_buffer_fraction_%']
96 = $server_status['Key_blocks_used']
97 * 1024
98 / $server_variables['key_buffer_size'];
101 // Ratio for key read/write
102 if (isset($server_status['Key_writes'])
103 && isset($server_status['Key_write_requests'])
104 && $server_status['Key_write_requests'] > 0
106 $server_status['Key_write_ratio_%']
107 = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
110 if (isset($server_status['Key_reads'])
111 && isset($server_status['Key_read_requests'])
112 && $server_status['Key_read_requests'] > 0
114 $server_status['Key_read_ratio_%']
115 = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
118 // Threads_cache_hitrate
119 if (isset($server_status['Threads_created'])
120 && isset($server_status['Connections'])
121 && $server_status['Connections'] > 0
124 $server_status['Threads_cache_hitrate_%']
125 = 100 - $server_status['Threads_created']
126 / $server_status['Connections'] * 100;
130 * split variables in sections
132 $allocations = array(
133 // variable name => section
134 // variable names match when they begin with the given string
136 'Com_' => 'com',
137 'Innodb_' => 'innodb',
138 'Ndb_' => 'ndb',
139 'Handler_' => 'handler',
140 'Qcache_' => 'qcache',
141 'Threads_' => 'threads',
142 'Slow_launch_threads' => 'threads',
144 'Binlog_cache_' => 'binlog_cache',
145 'Created_tmp_' => 'created_tmp',
146 'Key_' => 'key',
148 'Delayed_' => 'delayed',
149 'Not_flushed_delayed_rows' => 'delayed',
151 'Flush_commands' => 'query',
152 'Last_query_cost' => 'query',
153 'Slow_queries' => 'query',
154 'Queries' => 'query',
155 'Prepared_stmt_count' => 'query',
157 'Select_' => 'select',
158 'Sort_' => 'sort',
160 'Open_tables' => 'table',
161 'Opened_tables' => 'table',
162 'Open_table_definitions' => 'table',
163 'Opened_table_definitions' => 'table',
164 'Table_locks_' => 'table',
166 'Rpl_status' => 'repl',
167 'Slave_' => 'repl',
169 'Tc_' => 'tc',
171 'Ssl_' => 'ssl',
173 'Open_files' => 'files',
174 'Open_streams' => 'files',
175 'Opened_files' => 'files',
178 $sections = array(
179 // section => section name (description)
180 'com' => 'Com',
181 'query' => __('SQL query'),
182 'innodb' => 'InnoDB',
183 'ndb' => 'NDB',
184 'handler' => __('Handler'),
185 'qcache' => __('Query cache'),
186 'threads' => __('Threads'),
187 'binlog_cache' => __('Binary log'),
188 'created_tmp' => __('Temporary data'),
189 'delayed' => __('Delayed inserts'),
190 'key' => __('Key cache'),
191 'select' => __('Joins'),
192 'repl' => __('Replication'),
193 'sort' => __('Sorting'),
194 'table' => __('Tables'),
195 'tc' => __('Transaction coordinator'),
196 'files' => __('Files'),
197 'ssl' => 'SSL',
198 'other' => __('Other')
202 * define some needfull links/commands
204 // variable or section name => (name => url)
205 $links = array();
207 $links['table'][__('Flush (close) all tables')]
208 = $this->selfUrl . '?flush=TABLES&amp;' . PMA_generate_common_url();
209 $links['table'][__('Show open tables')]
210 = 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
211 '&amp;goto=' . $this->selfUrl . '&amp;' . PMA_generate_common_url();
213 if ($GLOBALS['server_master_status']) {
214 $links['repl'][__('Show slave hosts')]
215 = 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS')
216 . '&amp;goto=' . $this->selfUrl . '&amp;'
217 . PMA_generate_common_url();
218 $links['repl'][__('Show master status')] = '#replication_master';
220 if ($GLOBALS['server_slave_status']) {
221 $links['repl'][__('Show slave status')] = '#replication_slave';
224 $links['repl']['doc'] = 'replication';
226 $links['qcache'][__('Flush query cache')]
227 = $this->selfUrl . '?flush=' . urlencode('QUERY CACHE') . '&amp;' .
228 PMA_generate_common_url();
229 $links['qcache']['doc'] = 'query_cache';
231 $links['threads']['doc'] = 'mysql_threads';
233 $links['key']['doc'] = 'myisam_key_cache';
235 $links['binlog_cache']['doc'] = 'binary_log';
237 $links['Slow_queries']['doc'] = 'slow_query_log';
239 $links['innodb'][__('Variables')]
240 = 'server_engines.php?engine=InnoDB&amp;' . PMA_generate_common_url();
241 $links['innodb'][__('InnoDB Status')]
242 = 'server_engines.php?engine=InnoDB&amp;page=Status&amp;' .
243 PMA_generate_common_url();
244 $links['innodb']['doc'] = 'innodb';
247 // Variable to contain all com_ variables (query statistics)
248 $used_queries = array();
250 // Variable to map variable names to their respective section name
251 // (used for js category filtering)
252 $allocationMap = array();
254 // Variable to mark used sections
255 $categoryUsed = array();
257 // sort vars into arrays
258 foreach ($server_status as $name => $value) {
259 $section_found = false;
260 foreach ($allocations as $filter => $section) {
261 if (strpos($name, $filter) !== false) {
262 $allocationMap[$name] = $section;
263 $categoryUsed[$section] = true;
264 $section_found = true;
265 if ($section == 'com' && $value > 0) {
266 $used_queries[$name] = $value;
268 break; // Only exits inner loop
271 if (!$section_found) {
272 $allocationMap[$name] = 'other';
273 $categoryUsed['other'] = true;
277 if (PMA_DRIZZLE) {
278 $used_queries = PMA_DBI_fetch_result(
279 'SELECT * FROM data_dictionary.global_statements',
283 unset($used_queries['admin_commands']);
284 } else {
285 // admin commands are not queries (e.g. they include COM_PING,
286 // which is excluded from $server_status['Questions'])
287 unset($used_queries['Com_admin_commands']);
290 // Set all class properties
291 $this->db_isLocal = false;
292 if (strtolower($GLOBALS['cfg']['Server']['host']) === 'localhost'
293 || $GLOBALS['cfg']['Server']['host'] === '127.0.0.1'
294 || $GLOBALS['cfg']['Server']['host'] === '::1'
296 $this->db_isLocal = true;
298 $this->status = $server_status;
299 $this->sections = $sections;
300 $this->variables = $server_variables;
301 $this->used_queries = $used_queries;
302 $this->allocationMap = $allocationMap;
303 $this->links = $links;
304 $this->categoryUsed = $categoryUsed;
308 * cleanup of some deprecated values
310 * @param array $server_status status array to process
312 * @return array
314 public static function cleanDeprecated($server_status)
316 $deprecated = array(
317 'Com_prepare_sql' => 'Com_stmt_prepare',
318 'Com_execute_sql' => 'Com_stmt_execute',
319 'Com_dealloc_sql' => 'Com_stmt_close',
321 foreach ($deprecated as $old => $new) {
322 if (isset($server_status[$old]) && isset($server_status[$new])) {
323 unset($server_status[$old]);
326 return $server_status;
330 * cleanup of some deprecated values
332 * @return array
334 public function getMenuHtml()
336 $url_params = PMA_generate_common_url();
337 $items = array(
338 array(
339 'name' => __('Server'),
340 'url' => 'server_status.php'
342 array(
343 'name' => __('Query statistics'),
344 'url' => 'server_status_queries.php'
346 array(
347 'name' => __('All status variables'),
348 'url' => 'server_status_variables.php'
350 array(
351 'name' => __('Monitor'),
352 'url' => 'server_status_monitor.php'
354 array(
355 'name' => __('Advisor'),
356 'url' => 'server_status_advisor.php'
360 $retval = '<ul id="topmenu2">';
361 foreach ($items as $item) {
362 $class = '';
363 if ($item['url'] === $this->selfUrl) {
364 $class = ' class="tabactive"';
366 $retval .= '<li>';
367 $retval .= '<a' . $class;
368 $retval .= ' href="' . $item['url'] . '?' . $url_params . '">';
369 $retval .= $item['name'];
370 $retval .= '</a>';
371 $retval .= '</li>';
373 $retval .= '</ul>';
374 $retval .= '<div class="clearfloat"></div>';
376 return $retval;