Merge remote-tracking branch 'origin/QA_4_0' into QA_4_0
[phpmyadmin.git] / server_status.php
blob1db92fac5ad3e4cd1d60c6b8a07d49d779eb2509
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * object the server status page: processes, connections and traffic
6 * @package PhpMyAdmin
7 */
9 require_once 'libraries/common.inc.php';
10 require_once 'libraries/server_common.inc.php';
11 require_once 'libraries/ServerStatusData.class.php';
13 /**
14 * Replication library
16 if (PMA_DRIZZLE) {
17 $server_master_status = false;
18 $server_slave_status = false;
19 } else {
20 include_once 'libraries/replication.inc.php';
21 include_once 'libraries/replication_gui.lib.php';
24 $ServerStatusData = new PMA_ServerStatusData();
26 /**
27 * Kills a selected process
29 if (! empty($_REQUEST['kill'])) {
30 if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
31 $message = PMA_Message::success(__('Thread %s was successfully killed.'));
32 } else {
33 $message = PMA_Message::error(
34 __(
35 'phpMyAdmin was unable to kill thread %s.'
36 . ' It probably has already been closed.'
40 $message->addParam($_REQUEST['kill']);
43 /**
44 * start output
46 $response = PMA_Response::getInstance();
47 $response->addHTML('<div>');
48 $response->addHTML($ServerStatusData->getMenuHtml());
49 $response->addHTML(getServerTrafficHtml($ServerStatusData));
50 $response->addHTML('</div>');
52 exit;
54 /**
55 * Prints server traffic information
57 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
59 * @return string
61 function getServerTrafficHtml($ServerStatusData)
63 $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
64 $start_time = PMA_DBI_fetch_value(
65 'SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime']
68 $retval = '<h3>';
69 $retval .= sprintf(
70 __('Network traffic since startup: %s'),
71 implode(
72 ' ',
73 PMA_Util::formatByteDown(
74 $ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'],
80 $retval .= '</h3>';
81 $retval .= '<p>';
82 $retval .= sprintf(
83 __('This MySQL server has been running for %1$s. It started up on %2$s.'),
84 PMA_Util::timespanFormat($ServerStatusData->status['Uptime']),
85 PMA_Util::localisedDate($start_time)
86 ) . "\n";
87 $retval .= '</p>';
89 if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
90 $retval .= '<p class="notice">';
91 if ($GLOBALS['server_master_status'] && $GLOBALS['server_slave_status']) {
92 $retval .= __(
93 'This MySQL server works as <b>master</b> and '
94 . '<b>slave</b> in <b>replication</b> process.'
96 } elseif ($GLOBALS['server_master_status']) {
97 $retval .= __(
98 'This MySQL server works as <b>master</b> '
99 . 'in <b>replication</b> process.'
101 } elseif ($GLOBALS['server_slave_status']) {
102 $retval .= __(
103 'This MySQL server works as <b>slave</b> '
104 . 'in <b>replication</b> process.'
107 $retval .= ' ';
108 $retval .= __(
109 'For further information about replication status on the server, '
110 . 'please visit the <a href="#replication">replication section</a>.'
112 $retval .= '</p>';
116 * if the server works as master or slave in replication process,
117 * display useful information
119 if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
120 $retval .= '<hr class="clearfloat" />';
121 $retval .= '<h3><a name="replication">';
122 $retval .= __('Replication status');
123 $retval .= '</a></h3>';
124 foreach ($GLOBALS['replication_types'] as $type) {
125 if (isset(${"server_{$type}_status"}) && ${"server_{$type}_status"}) {
126 PMA_replication_print_status_table($type);
131 $retval .= '<table id="serverstatustraffic" class="data noclick">';
132 $retval .= '<thead>';
133 $retval .= '<tr>';
134 $retval .= '<th colspan="2">';
135 $retval .= __('Traffic') . '&nbsp;';
136 $retval .= PMA_Util::showHint(
138 'On a busy server, the byte counters may overrun, so those statistics '
139 . 'as reported by the MySQL server may be incorrect.'
142 $retval .= '</th>';
143 $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
144 $retval .= '</tr>';
145 $retval .= '</thead>';
146 $retval .= '<tbody>';
147 $retval .= '<tr class="odd">';
148 $retval .= '<th class="name">' . __('Received') . '</th>';
149 $retval .= '<td class="value">';
150 $retval .= implode(
151 ' ',
152 PMA_Util::formatByteDown(
153 $ServerStatusData->status['Bytes_received'], 3, 1
156 $retval .= '</td>';
157 $retval .= '<td class="value">';
158 $retval .= implode(
159 ' ',
160 PMA_Util::formatByteDown(
161 $ServerStatusData->status['Bytes_received'] * $hour_factor, 3, 1
164 $retval .= '</td>';
165 $retval .= '</tr>';
166 $retval .= '<tr class="even">';
167 $retval .= '<th class="name">' . __('Sent') . '</th>';
168 $retval .= '<td class="value">';
169 $retval .= implode(
170 ' ',
171 PMA_Util::formatByteDown(
172 $ServerStatusData->status['Bytes_sent'], 3, 1
175 $retval .= '</td>';
176 $retval .= '<td class="value"><?php echo';
177 $retval .= implode(
178 ' ',
179 PMA_Util::formatByteDown(
180 $ServerStatusData->status['Bytes_sent'] * $hour_factor, 3, 1
183 $retval .= '</td>';
184 $retval .= '</tr>';
185 $retval .= '<tr class="odd">';
186 $retval .= '<th class="name">' . __('Total') . '</th>';
187 $retval .= '<td class="value">';
188 $retval .= implode(
189 ' ',
190 PMA_Util::formatByteDown(
191 $ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1
194 $retval .= '</td>';
195 $retval .= '<td class="value">';
196 $retval .= implode(
197 ' ',
198 PMA_Util::formatByteDown(
199 ($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'])
200 * $hour_factor, 3, 1
203 $retval .= '</td>';
204 $retval .= '</tr>';
205 $retval .= '</tbody>';
206 $retval .= '</table>';
208 $retval .= '<table id="serverstatusconnections" class="data noclick">';
209 $retval .= '<thead>';
210 $retval .= '<tr>';
211 $retval .= '<th colspan="2">' . __('Connections') . '</th>';
212 $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
213 $retval .= '<th>%</th>';
214 $retval .= '</tr>';
215 $retval .= '</thead>';
216 $retval .= '<tbody>';
217 $retval .= '<tr class="odd">';
218 $retval .= '<th class="name">' . __('max. concurrent connections') . '</th>';
219 $retval .= '<td class="value">';
220 $retval .= PMA_Util::formatNumber(
221 $ServerStatusData->status['Max_used_connections'], 0
223 $retval .= '</td>';
224 $retval .= '<td class="value">--- </td>';
225 $retval .= '<td class="value">--- </td>';
226 $retval .= '</tr>';
227 $retval .= '<tr class="even">';
228 $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
229 $retval .= '<td class="value">';
230 $retval .= PMA_Util::formatNumber(
231 $ServerStatusData->status['Aborted_connects'], 4, 1, true
233 $retval .= '</td>';
234 $retval .= '<td class="value">';
235 $retval .= PMA_Util::formatNumber(
236 $ServerStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true
238 $retval .= '</td>';
239 $retval .= '<td class="value">';
240 if ($ServerStatusData->status['Connections'] > 0) {
241 $retval .= PMA_Util::formatNumber(
242 $ServerStatusData->status['Aborted_connects'] * 100 / $ServerStatusData->status['Connections'],
243 0, 2, true
245 $retval .= '%';
246 } else {
247 $retval .= '--- ';
249 $retval .= '</td>';
250 $retval .= '</tr>';
251 $retval .= '<tr class="odd">';
252 $retval .= '<th class="name">' . __('Aborted') . '</th>';
253 $retval .= '<td class="value">';
254 $retval .= PMA_Util::formatNumber(
255 $ServerStatusData->status['Aborted_clients'], 4, 1, true
257 $retval .= '</td>';
258 $retval .= '<td class="value">';
259 $retval .= PMA_Util::formatNumber(
260 $ServerStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true
262 $retval .= '</td>';
263 $retval .= '<td class="value">';
264 if ($ServerStatusData->status['Connections'] > 0) {
265 $retval .= PMA_Util::formatNumber(
266 $ServerStatusData->status['Aborted_clients'] * 100 / $ServerStatusData->status['Connections'],
267 0, 2, true
269 $retval .= '%';
270 } else {
271 $retval .= '--- ';
273 $retval .= '</td>';
274 $retval .= '</tr>';
275 $retval .= '<tr class="even">';
276 $retval .= '<th class="name">' . __('Total') . '</th>';
277 $retval .= '<td class="value">';
278 $retval .= PMA_Util::formatNumber(
279 $ServerStatusData->status['Connections'], 4, 0
281 $retval .= '</td>';
282 $retval .= '<td class="value">';
283 $retval .= PMA_Util::formatNumber(
284 $ServerStatusData->status['Connections'] * $hour_factor, 4, 2
286 $retval .= '</td>';
287 $retval .= '<td class="value">';
288 $retval .= PMA_Util::formatNumber(100, 0, 2);
289 $retval .= '%</td>';
290 $retval .= '</tr>';
291 $retval .= '</tbody>';
292 $retval .= '</table>';
294 $url_params = array();
296 $show_full_sql = ! empty($_REQUEST['full']);
297 if ($show_full_sql) {
298 $url_params['full'] = 1;
299 $full_text_link = 'server_status.php' . PMA_generate_common_url(
300 array(), 'html', '?'
302 } else {
303 $full_text_link = 'server_status.php' . PMA_generate_common_url(
304 array('full' => 1)
308 // This array contains display name and real column name of each
309 // sortable column in the table
310 $sortable_columns = array(
311 array(
312 'column_name' => __('ID'),
313 'order_by_field' => 'Id'
315 array(
316 'column_name' => __('User'),
317 'order_by_field' => 'User'
319 array(
320 'column_name' => __('Host'),
321 'order_by_field' => 'Host'
323 array(
324 'column_name' => __('Database'),
325 'order_by_field' => 'db'
327 array(
328 'column_name' => __('Command'),
329 'order_by_field' => 'Command'
331 array(
332 'column_name' => __('Time'),
333 'order_by_field' => 'Time'
335 array(
336 'column_name' => __('Status'),
337 'order_by_field' => 'State'
339 array(
340 'column_name' => __('SQL query'),
341 'order_by_field' => 'Info'
344 $sortable_columns_count = count($sortable_columns);
346 if (PMA_DRIZZLE) {
347 $sql_query = "SELECT
348 p.id AS Id,
349 p.username AS User,
350 p.host AS Host,
351 p.db AS db,
352 p.command AS Command,
353 p.time AS Time,
354 p.state AS State,
355 " . ($show_full_sql ? 's.query' : 'left(p.info, ' . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info
356 FROM data_dictionary.PROCESSLIST p
357 " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
358 if (! empty($_REQUEST['order_by_field'])
359 && ! empty($_REQUEST['sort_order'])
361 $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' ' . $_REQUEST['sort_order'];
363 } else {
364 $sql_query = $show_full_sql
365 ? 'SHOW FULL PROCESSLIST'
366 : 'SHOW PROCESSLIST';
367 if (! empty($_REQUEST['order_by_field'])
368 && ! empty($_REQUEST['sort_order'])
370 $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ORDER BY `'
371 . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order'];
375 $result = PMA_DBI_query($sql_query);
378 * Displays the page
380 $retval .= '<table id="tableprocesslist" class="data clearfloat noclick sortable">';
381 $retval .= '<thead>';
382 $retval .= '<tr>';
383 $retval .= '<th>' . __('Processes') . '</th>';
384 foreach ($sortable_columns as $column) {
386 $is_sorted = ! empty($_REQUEST['order_by_field'])
387 && ! empty($_REQUEST['sort_order'])
388 && ($_REQUEST['order_by_field'] == $column['order_by_field']);
390 $column['sort_order'] = 'ASC';
391 if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
392 $column['sort_order'] = 'DESC';
395 if ($is_sorted) {
396 if ($_REQUEST['sort_order'] == 'ASC') {
397 $asc_display_style = 'inline';
398 $desc_display_style = 'none';
399 } elseif ($_REQUEST['sort_order'] == 'DESC') {
400 $desc_display_style = 'inline';
401 $asc_display_style = 'none';
405 $retval .= '<th>';
406 $retval .= '<a href="server_status.php' . PMA_generate_common_url($column) . '" ';
407 if ($is_sorted) {
408 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
409 . 'onmouseover="$(\'.soimg\').toggle()"';
411 $retval .= '>';
413 $retval .= $column['column_name'];
415 if ($is_sorted) {
416 $retval .= '<img class="icon ic_s_desc soimg" alt="'
417 . __('Descending') . '" title="" src="themes/dot.gif" '
418 . 'style="display: ' . $desc_display_style . '" />';
419 $retval .= '<img class="icon ic_s_asc soimg hide" alt="'
420 . __('Ascending') . '" title="" src="themes/dot.gif" '
421 . 'style="display: ' . $asc_display_style . '" />';
424 $retval .= '</a>';
426 if (! PMA_DRIZZLE && (0 === --$sortable_columns_count)) {
427 $retval .= '<a href="' . $full_text_link . '">';
428 if ($show_full_sql) {
429 $retval .= PMA_Util::getImage(
430 's_partialtext.png',
431 __('Truncate Shown Queries')
433 } else {
434 $retval .= PMA_Util::getImage(
435 's_fulltext.png',
436 __('Show Full Queries')
439 $retval .= '</a>';
441 $retval .= '</th>';
444 $retval .= '</tr>';
445 $retval .= '</thead>';
446 $retval .= '<tbody>';
448 $odd_row = true;
449 while ($process = PMA_DBI_fetch_assoc($result)) {
451 // Array keys need to modify due to the way it has used
452 // to display column values
453 if (! empty($_REQUEST['order_by_field'])
454 && ! empty($_REQUEST['sort_order'])
456 foreach (array_keys($process) as $key) {
457 $new_key = ucfirst(strtolower($key));
458 $process[$new_key] = $process[$key];
459 unset($process[$key]);
463 $url_params['kill'] = $process['Id'];
464 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
466 $retval .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
467 $retval .= '<td><a href="' . $kill_process . '">' . __('Kill') . '</a></td>';
468 $retval .= '<td class="value">' . $process['Id'] . '</td>';
469 $retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
470 $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
471 $retval .= '<td>' . ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . __('None') . '</i>' : htmlspecialchars($process['db'])) . '</td>';
472 $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
473 $retval .= '<td class="value">' . $process['Time'] . '</td>';
474 $retval .= '<td>' . (empty($process['State']) ? '---' : $process['State']) . '</td>';
475 $retval .= '<td>';
477 if (empty($process['Info'])) {
478 $retval .= '---';
479 } else {
480 if (! $show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
481 $retval .= htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
482 } else {
483 $retval .= PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
486 $retval .= '</td>';
487 $retval .= '</tr>';
488 $odd_row = ! $odd_row;
490 $retval .= '</tbody>';
491 $retval .= '</table>';
493 return $retval;