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_getServerStatusHtml($ServerStatusData));
50 $response->addHTML('</div>');
55 * Prints server status information: processes, connections and traffic
57 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
61 function PMA_getServerStatusHtml($ServerStatusData)
63 //display the server state General Information
64 $retval = PMA_getServerStateGeneralInfoHtml($ServerStatusData);
66 //display the server state traffic information
67 $retval .= PMA_getServerStateTrafficHtml($ServerStatusData);
69 //display the server state connection information
70 $retval .= PMA_getServerStateConnectionsHtml($ServerStatusData);
72 //display the server Process List information
73 $retval .= PMA_getServerProcesslistHtml($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 $retval .= PMA_getHtmlForReplicationStatusTable($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 Server Process list
343 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
347 function PMA_getServerProcesslistHtml($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);
402 $left_str = 'left(p.info, '
403 . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')';
409 p.command AS Command,
412 . ($show_full_sql ?
's.query' : $left_str )
413 . " AS Info FROM data_dictionary.PROCESSLIST p "
415 ?
'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id'
417 if (! empty($_REQUEST['order_by_field'])
418 && ! empty($_REQUEST['sort_order'])
420 $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' '
421 . $_REQUEST['sort_order'];
424 $sql_query = $show_full_sql
425 ?
'SHOW FULL PROCESSLIST'
426 : 'SHOW PROCESSLIST';
427 if (! empty($_REQUEST['order_by_field'])
428 && ! empty($_REQUEST['sort_order'])
430 $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ORDER BY `'
431 . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order'];
435 $result = $GLOBALS['dbi']->query($sql_query);
437 $retval = '<table id="tableprocesslist" class="data clearfloat noclick sortable">';
438 $retval .= '<thead>';
440 $retval .= '<th>' . __('Processes') . '</th>';
441 foreach ($sortable_columns as $column) {
443 $is_sorted = ! empty($_REQUEST['order_by_field'])
444 && ! empty($_REQUEST['sort_order'])
445 && ($_REQUEST['order_by_field'] == $column['order_by_field']);
447 $column['sort_order'] = 'ASC';
448 if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
449 $column['sort_order'] = 'DESC';
453 if ($_REQUEST['sort_order'] == 'ASC') {
454 $asc_display_style = 'inline';
455 $desc_display_style = 'none';
456 } elseif ($_REQUEST['sort_order'] == 'DESC') {
457 $desc_display_style = 'inline';
458 $asc_display_style = 'none';
463 $retval .= '<a href="server_status.php' . PMA_generate_common_url($column) . '" ';
465 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
466 . 'onmouseover="$(\'.soimg\').toggle()"';
470 $retval .= $column['column_name'];
473 $retval .= '<img class="icon ic_s_desc soimg" alt="'
474 . __('Descending') . '" title="" src="themes/dot.gif" '
475 . 'style="display: ' . $desc_display_style . '" />';
476 $retval .= '<img class="icon ic_s_asc soimg hide" alt="'
477 . __('Ascending') . '" title="" src="themes/dot.gif" '
478 . 'style="display: ' . $asc_display_style . '" />';
483 if (! PMA_DRIZZLE
&& (0 === --$sortable_columns_count)) {
484 $retval .= '<a href="' . $full_text_link . '">';
485 if ($show_full_sql) {
486 $retval .= PMA_Util
::getImage(
488 __('Truncate Shown Queries')
491 $retval .= PMA_Util
::getImage(
493 __('Show Full Queries')
502 $retval .= '</thead>';
503 $retval .= '<tbody>';
506 while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
508 // Array keys need to modify due to the way it has used
509 // to display column values
510 if (! empty($_REQUEST['order_by_field'])
511 && ! empty($_REQUEST['sort_order'])
513 foreach (array_keys($process) as $key) {
514 $new_key = ucfirst(strtolower($key));
515 $process[$new_key] = $process[$key];
516 unset($process[$key]);
520 $url_params['kill'] = $process['Id'];
521 $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
523 $retval .= '<tr class="' . ($odd_row ?
'odd' : 'even') . '">';
524 $retval .= '<td><a href="' . $kill_process . '">' . __('Kill') . '</a></td>';
525 $retval .= '<td class="value">' . $process['Id'] . '</td>';
526 $retval .= '<td>' . $process['User'] . '</td>';
527 $retval .= '<td>' . $process['Host'] . '</td>';
528 $retval .= '<td>' . ((! isset($process['db']) ||
! strlen($process['db']))
529 ?
'<i>' . __('None') . '</i>'
530 : $process['db']) . '</td>';
531 $retval .= '<td>' . $process['Command'] . '</td>';
532 $retval .= '<td class="value">' . $process['Time'] . '</td>';
533 $retval .= '<td>' . (empty($process['State']) ?
'---' : $process['State']) . '</td>';
536 if (empty($process['Info'])) {
539 if (! $show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
540 $retval .= htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']))
543 $retval .= '<code class="sql"><pre>'
550 $odd_row = ! $odd_row;
552 $retval .= '</tbody>';
553 $retval .= '</table>';