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 ($GLOBALS['dbi']->tryQuery('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(PMA_getServerTrafficHtml($ServerStatusData));
50 $response->addHTML('</div>');
55 * Prints server traffic information
57 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
61 function PMA_getServerTrafficHtml($ServerStatusData)
63 //display the server state General Information
64 $retval = PMA_getServerStateGeneralInfoHtml($ServerStatusData);
66 //display the server state traffic
67 $retval .= PMA_getServerStateTrafficHtml($ServerStatusData);
69 //display the server state connection information
70 $retval .= PMA_getServerStateConnectionsHtml($ServerStatusData);
72 //display the Table Process List information
73 $retval .= PMA_getTableProcesslistHtml($ServerStatusData);
79 * Prints server state General information
81 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
85 function PMA_getServerStateGeneralInfoHtml($ServerStatusData)
87 $start_time = $GLOBALS['dbi']->fetchValue(
88 'SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status
['Uptime']
93 __('Network traffic since startup: %s'),
96 PMA_Util
::formatByteDown(
97 $ServerStatusData->status
['Bytes_received'] +
$ServerStatusData->status
['Bytes_sent'],
106 __('This MySQL server has been running for %1$s. It started up on %2$s.'),
107 PMA_Util
::timespanFormat($ServerStatusData->status
['Uptime']),
108 PMA_Util
::localisedDate($start_time)
112 if ($GLOBALS['server_master_status'] ||
$GLOBALS['server_slave_status']) {
113 $retval .= '<p class="notice">';
114 if ($GLOBALS['server_master_status'] && $GLOBALS['server_slave_status']) {
116 'This MySQL server works as <b>master</b> and '
117 . '<b>slave</b> in <b>replication</b> process.'
119 } elseif ($GLOBALS['server_master_status']) {
121 'This MySQL server works as <b>master</b> '
122 . 'in <b>replication</b> process.'
124 } elseif ($GLOBALS['server_slave_status']) {
126 'This MySQL server works as <b>slave</b> '
127 . 'in <b>replication</b> process.'
134 * if the server works as master or slave in replication process,
135 * display useful information
137 if ($GLOBALS['server_master_status'] ||
$GLOBALS['server_slave_status']) {
138 $retval .= '<hr class="clearfloat" />';
139 $retval .= '<h3><a name="replication">';
140 $retval .= __('Replication status');
141 $retval .= '</a></h3>';
142 foreach ($GLOBALS['replication_types'] as $type) {
143 if (isset($
{"server_{$type}_status"}) && $
{"server_{$type}_status"}) {
144 PMA_replication_print_status_table($type);
153 * Prints server state traffic information
155 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
159 function PMA_getServerStateTrafficHtml($ServerStatusData)
161 $hour_factor = 3600 / $ServerStatusData->status
['Uptime'];
162 $retval = '<table id="serverstatustraffic" class="data noclick">';
163 $retval .= '<thead>';
165 $retval .= '<th colspan="2">';
166 $retval .= __('Traffic') . ' ';
167 $retval .= PMA_Util
::showHint(
169 'On a busy server, the byte counters may overrun, so those statistics '
170 . 'as reported by the MySQL server may be incorrect.'
174 $retval .= '<th>ø ' . __('per hour') . '</th>';
176 $retval .= '</thead>';
177 $retval .= '<tbody>';
178 $retval .= '<tr class="odd">';
179 $retval .= '<th class="name">' . __('Received') . '</th>';
180 $retval .= '<td class="value">';
183 PMA_Util
::formatByteDown(
184 $ServerStatusData->status
['Bytes_received'], 3, 1
188 $retval .= '<td class="value">';
191 PMA_Util
::formatByteDown(
192 $ServerStatusData->status
['Bytes_received'] * $hour_factor, 3, 1
197 $retval .= '<tr class="even">';
198 $retval .= '<th class="name">' . __('Sent') . '</th>';
199 $retval .= '<td class="value">';
202 PMA_Util
::formatByteDown(
203 $ServerStatusData->status
['Bytes_sent'], 3, 1
207 $retval .= '<td class="value"><?php echo';
210 PMA_Util
::formatByteDown(
211 $ServerStatusData->status
['Bytes_sent'] * $hour_factor, 3, 1
216 $retval .= '<tr class="odd">';
217 $retval .= '<th class="name">' . __('Total') . '</th>';
218 $retval .= '<td class="value">';
221 PMA_Util
::formatByteDown(
222 $ServerStatusData->status
['Bytes_received'] +
$ServerStatusData->status
['Bytes_sent'], 3, 1
226 $retval .= '<td class="value">';
229 PMA_Util
::formatByteDown(
230 ($ServerStatusData->status
['Bytes_received'] +
$ServerStatusData->status
['Bytes_sent'])
236 $retval .= '</tbody>';
237 $retval .= '</table>';
242 * Prints server state connections information
244 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
248 function PMA_getServerStateConnectionsHtml($ServerStatusData)
250 $hour_factor = 3600 / $ServerStatusData->status
['Uptime'];
251 $retval = '<table id="serverstatusconnections" class="data noclick">';
252 $retval .= '<thead>';
254 $retval .= '<th colspan="2">' . __('Connections') . '</th>';
255 $retval .= '<th>ø ' . __('per hour') . '</th>';
256 $retval .= '<th>%</th>';
258 $retval .= '</thead>';
259 $retval .= '<tbody>';
260 $retval .= '<tr class="odd">';
261 $retval .= '<th class="name">' . __('max. concurrent connections') . '</th>';
262 $retval .= '<td class="value">';
263 $retval .= PMA_Util
::formatNumber(
264 $ServerStatusData->status
['Max_used_connections'], 0
267 $retval .= '<td class="value">--- </td>';
268 $retval .= '<td class="value">--- </td>';
270 $retval .= '<tr class="even">';
271 $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
272 $retval .= '<td class="value">';
273 $retval .= PMA_Util
::formatNumber(
274 $ServerStatusData->status
['Aborted_connects'], 4, 1, true
277 $retval .= '<td class="value">';
278 $retval .= PMA_Util
::formatNumber(
279 $ServerStatusData->status
['Aborted_connects'] * $hour_factor, 4, 2, true
282 $retval .= '<td class="value">';
283 if ($ServerStatusData->status
['Connections'] > 0) {
284 $retval .= PMA_Util
::formatNumber(
285 $ServerStatusData->status
['Aborted_connects'] * 100 / $ServerStatusData->status
['Connections'],
294 $retval .= '<tr class="odd">';
295 $retval .= '<th class="name">' . __('Aborted') . '</th>';
296 $retval .= '<td class="value">';
297 $retval .= PMA_Util
::formatNumber(
298 $ServerStatusData->status
['Aborted_clients'], 4, 1, true
301 $retval .= '<td class="value">';
302 $retval .= PMA_Util
::formatNumber(
303 $ServerStatusData->status
['Aborted_clients'] * $hour_factor, 4, 2, true
306 $retval .= '<td class="value">';
307 if ($ServerStatusData->status
['Connections'] > 0) {
308 $retval .= PMA_Util
::formatNumber(
309 $ServerStatusData->status
['Aborted_clients'] * 100 / $ServerStatusData->status
['Connections'],
318 $retval .= '<tr class="even">';
319 $retval .= '<th class="name">' . __('Total') . '</th>';
320 $retval .= '<td class="value">';
321 $retval .= PMA_Util
::formatNumber(
322 $ServerStatusData->status
['Connections'], 4, 0
325 $retval .= '<td class="value">';
326 $retval .= PMA_Util
::formatNumber(
327 $ServerStatusData->status
['Connections'] * $hour_factor, 4, 2
330 $retval .= '<td class="value">';
331 $retval .= PMA_Util
::formatNumber(100, 0, 2);
334 $retval .= '</tbody>';
335 $retval .= '</table>';
341 * Prints Table Process list
343 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
347 function PMA_getTableProcesslistHtml($ServerStatusData)
349 $url_params = array();
351 $show_full_sql = ! empty($_REQUEST['full']);
352 if ($show_full_sql) {
353 $url_params['full'] = 1;
354 $full_text_link = 'server_status.php' . PMA_generate_common_url(
358 $full_text_link = 'server_status.php' . PMA_generate_common_url(
363 // This array contains display name and real column name of each
364 // sortable column in the table
365 $sortable_columns = array(
367 'column_name' => __('ID'),
368 'order_by_field' => 'Id'
371 'column_name' => __('User'),
372 'order_by_field' => 'User'
375 'column_name' => __('Host'),
376 'order_by_field' => 'Host'
379 'column_name' => __('Database'),
380 'order_by_field' => 'db'
383 'column_name' => __('Command'),
384 'order_by_field' => 'Command'
387 'column_name' => __('Time'),
388 'order_by_field' => 'Time'
391 'column_name' => __('Status'),
392 'order_by_field' => 'State'
395 'column_name' => __('SQL query'),
396 'order_by_field' => 'Info'
399 $sortable_columns_count = count($sortable_columns);
407 p.command AS Command,
410 " . ($show_full_sql ?
's.query' : 'left(p.info, ' . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info
411 FROM data_dictionary.PROCESSLIST p
412 " . ($show_full_sql ?
'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
413 if (! empty($_REQUEST['order_by_field'])
414 && ! empty($_REQUEST['sort_order'])
416 $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' ' . $_REQUEST['sort_order'];
419 $sql_query = $show_full_sql
420 ?
'SHOW FULL PROCESSLIST'
421 : 'SHOW PROCESSLIST';
422 if (! empty($_REQUEST['order_by_field'])
423 && ! empty($_REQUEST['sort_order'])
425 $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ORDER BY `'
426 . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order'];
430 $result = $GLOBALS['dbi']->query($sql_query);
432 $retval = '<table id="tableprocesslist" class="data clearfloat noclick sortable">';
433 $retval .= '<thead>';
435 $retval .= '<th>' . __('Processes') . '</th>';
436 foreach ($sortable_columns as $column) {
438 $is_sorted = ! empty($_REQUEST['order_by_field'])
439 && ! empty($_REQUEST['sort_order'])
440 && ($_REQUEST['order_by_field'] == $column['order_by_field']);
442 $column['sort_order'] = 'ASC';
443 if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
444 $column['sort_order'] = 'DESC';
448 if ($_REQUEST['sort_order'] == 'ASC') {
449 $asc_display_style = 'inline';
450 $desc_display_style = 'none';
451 } elseif ($_REQUEST['sort_order'] == 'DESC') {
452 $desc_display_style = 'inline';
453 $asc_display_style = 'none';
458 $retval .= '<a href="server_status.php' . PMA_generate_common_url($column) . '" ';
460 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
461 . 'onmouseover="$(\'.soimg\').toggle()"';
465 $retval .= $column['column_name'];
468 $retval .= '<img class="icon ic_s_desc soimg" alt="'
469 . __('Descending') . '" title="" src="themes/dot.gif" '
470 . 'style="display: ' . $desc_display_style . '" />';
471 $retval .= '<img class="icon ic_s_asc soimg hide" alt="'
472 . __('Ascending') . '" title="" src="themes/dot.gif" '
473 . 'style="display: ' . $asc_display_style . '" />';
478 if (! PMA_DRIZZLE
&& (0 === --$sortable_columns_count)) {
479 $retval .= '<a href="' . $full_text_link . '">';
480 if ($show_full_sql) {
481 $retval .= PMA_Util
::getImage(
483 __('Truncate Shown Queries')
486 $retval .= PMA_Util
::getImage(
488 __('Show Full Queries')
497 $retval .= '</thead>';
498 $retval .= '<tbody>';
501 while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
503 // Array keys need to modify due to the way it has used
504 // to display column values
505 if (! empty($_REQUEST['order_by_field'])
506 && ! empty($_REQUEST['sort_order'])
508 foreach (array_keys($process) as $key) {
509 $new_key = ucfirst(strtolower($key));
510 $process[$new_key] = $process[$key];
511 unset($process[$key]);
515 $url_params['kill'] = $process['Id'];
516 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
518 $retval .= '<tr class="' . ($odd_row ?
'odd' : 'even') . '">';
519 $retval .= '<td><a href="' . $kill_process . '">' . __('Kill') . '</a></td>';
520 $retval .= '<td class="value">' . $process['Id'] . '</td>';
521 $retval .= '<td>' . $process['User'] . '</td>';
522 $retval .= '<td>' . $process['Host'] . '</td>';
523 $retval .= '<td>' . ((! isset($process['db']) ||
! strlen($process['db'])) ?
'<i>' . __('None') . '</i>' : $process['db']) . '</td>';
524 $retval .= '<td>' . $process['Command'] . '</td>';
525 $retval .= '<td class="value">' . $process['Time'] . '</td>';
526 $retval .= '<td>' . (empty($process['State']) ?
'---' : $process['State']) . '</td>';
529 if (empty($process['Info'])) {
532 if (! $show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
533 $retval .= htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
535 $retval .= PMA_SQP_format(PMA_SQP_parse($process['Info']));
540 $odd_row = ! $odd_row;
542 $retval .= '</tbody>';
543 $retval .= '</table>';