2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * object the server status page: processes, connections and traffic
9 require_once 'libraries/common.inc.php';
10 require_once 'libraries/server_common.inc.php';
11 require_once 'libraries/ServerStatusData.class.php';
17 $server_master_status = false;
18 $server_slave_status = false;
20 include_once 'libraries/replication.inc.php';
21 include_once 'libraries/replication_gui.lib.php';
24 $ServerStatusData = new PMA_ServerStatusData();
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.'));
33 $message = PMA_Message
::error(
35 'phpMyAdmin was unable to kill thread %s.'
36 . ' It probably has already been closed.'
40 $message->addParam($_REQUEST['kill']);
46 $response = PMA_Response
::getInstance();
47 $response->addHTML('<div>');
48 $response->addHTML($ServerStatusData->getMenuHtml());
49 $response->addHTML(getServerTrafficHtml($ServerStatusData));
50 $response->addHTML('</div>');
55 * Prints server traffic information
57 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
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']
70 __('Network traffic since startup: %s'),
73 PMA_Util
::formatByteDown(
74 $ServerStatusData->status
['Bytes_received'] +
$ServerStatusData->status
['Bytes_sent'],
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)
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']) {
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']) {
98 'This MySQL server works as <b>master</b> '
99 . 'in <b>replication</b> process.'
101 } elseif ($GLOBALS['server_slave_status']) {
103 'This MySQL server works as <b>slave</b> '
104 . 'in <b>replication</b> process.'
109 'For further information about replication status on the server, '
110 . 'please visit the <a href="#replication">replication section</a>.'
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>';
134 $retval .= '<th colspan="2">';
135 $retval .= __('Traffic') . ' ';
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.'
143 $retval .= '<th>ø ' . __('per hour') . '</th>';
145 $retval .= '</thead>';
146 $retval .= '<tbody>';
147 $retval .= '<tr class="odd">';
148 $retval .= '<th class="name">' . __('Received') . '</th>';
149 $retval .= '<td class="value">';
152 PMA_Util
::formatByteDown(
153 $ServerStatusData->status
['Bytes_received'], 3, 1
157 $retval .= '<td class="value">';
160 PMA_Util
::formatByteDown(
161 $ServerStatusData->status
['Bytes_received'] * $hour_factor, 3, 1
166 $retval .= '<tr class="even">';
167 $retval .= '<th class="name">' . __('Sent') . '</th>';
168 $retval .= '<td class="value">';
171 PMA_Util
::formatByteDown(
172 $ServerStatusData->status
['Bytes_sent'], 3, 1
176 $retval .= '<td class="value"><?php echo';
179 PMA_Util
::formatByteDown(
180 $ServerStatusData->status
['Bytes_sent'] * $hour_factor, 3, 1
185 $retval .= '<tr class="odd">';
186 $retval .= '<th class="name">' . __('Total') . '</th>';
187 $retval .= '<td class="value">';
190 PMA_Util
::formatByteDown(
191 $ServerStatusData->status
['Bytes_received'] +
$ServerStatusData->status
['Bytes_sent'], 3, 1
195 $retval .= '<td class="value">';
198 PMA_Util
::formatByteDown(
199 ($ServerStatusData->status
['Bytes_received'] +
$ServerStatusData->status
['Bytes_sent'])
205 $retval .= '</tbody>';
206 $retval .= '</table>';
208 $retval .= '<table id="serverstatusconnections" class="data noclick">';
209 $retval .= '<thead>';
211 $retval .= '<th colspan="2">' . __('Connections') . '</th>';
212 $retval .= '<th>ø ' . __('per hour') . '</th>';
213 $retval .= '<th>%</th>';
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
224 $retval .= '<td class="value">--- </td>';
225 $retval .= '<td class="value">--- </td>';
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
234 $retval .= '<td class="value">';
235 $retval .= PMA_Util
::formatNumber(
236 $ServerStatusData->status
['Aborted_connects'] * $hour_factor, 4, 2, true
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'],
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
258 $retval .= '<td class="value">';
259 $retval .= PMA_Util
::formatNumber(
260 $ServerStatusData->status
['Aborted_clients'] * $hour_factor, 4, 2, true
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'],
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
282 $retval .= '<td class="value">';
283 $retval .= PMA_Util
::formatNumber(
284 $ServerStatusData->status
['Connections'] * $hour_factor, 4, 2
287 $retval .= '<td class="value">';
288 $retval .= PMA_Util
::formatNumber(100, 0, 2);
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(
303 $full_text_link = 'server_status.php' . PMA_generate_common_url(
308 // This array contains display name and real column name of each
309 // sortable column in the table
310 $sortable_columns = array(
312 'column_name' => __('ID'),
313 'order_by_field' => 'Id'
316 'column_name' => __('User'),
317 'order_by_field' => 'User'
320 'column_name' => __('Host'),
321 'order_by_field' => 'Host'
324 'column_name' => __('Database'),
325 'order_by_field' => 'db'
328 'column_name' => __('Command'),
329 'order_by_field' => 'Command'
332 'column_name' => __('Time'),
333 'order_by_field' => 'Time'
336 'column_name' => __('Status'),
337 'order_by_field' => 'State'
340 'column_name' => __('SQL query'),
341 'order_by_field' => 'Info'
344 $sortable_columns_count = count($sortable_columns);
352 p.command AS Command,
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'];
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);
380 $retval .= '<table id="tableprocesslist" class="data clearfloat noclick sortable">';
381 $retval .= '<thead>';
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';
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';
406 $retval .= '<a href="server_status.php' . PMA_generate_common_url($column) . '" ';
408 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
409 . 'onmouseover="$(\'.soimg\').toggle()"';
413 $retval .= $column['column_name'];
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 . '" />';
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(
431 __('Truncate Shown Queries')
434 $retval .= PMA_Util
::getImage(
436 __('Show Full Queries')
445 $retval .= '</thead>';
446 $retval .= '<tbody>';
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>';
477 if (empty($process['Info'])) {
480 if (! $show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
481 $retval .= htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
483 $retval .= PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
488 $odd_row = ! $odd_row;
490 $retval .= '</tbody>';
491 $retval .= '</table>';