2 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * functions for displaying server status
7 * @usedby server_status.php
11 if (! defined('PHPMYADMIN')) {
16 * Prints server status information: processes, connections and traffic
18 * @param PMA_ServerStatusData $ServerStatusData Server status data
22 function PMA_getHtmlForServerStatus($ServerStatusData)
24 //display the server state General Information
25 $retval = PMA_getHtmlForServerStateGeneralInfo($ServerStatusData);
27 //display the server state traffic information
28 $retval .= PMA_getHtmlForServerStateTraffic($ServerStatusData);
30 //display the server state connection information
31 $retval .= PMA_getHtmlForServerStateConnections($ServerStatusData);
33 //display the server Process List information
34 $retval .= PMA_getHtmlForServerProcesslist($ServerStatusData);
40 * Prints server state General information
42 * @param PMA_ServerStatusData $ServerStatusData Server status data
46 function PMA_getHtmlForServerStateGeneralInfo($ServerStatusData)
48 $start_time = $GLOBALS['dbi']->fetchValue(
49 'SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status
['Uptime']
53 $bytes_received = $ServerStatusData->status
['Bytes_received'];
54 $bytes_sent = $ServerStatusData->status
['Bytes_sent'];
56 __('Network traffic since startup: %s'),
59 PMA_Util
::formatByteDown(
60 $bytes_received +
$bytes_sent,
69 __('This MySQL server has been running for %1$s. It started up on %2$s.'),
70 PMA_Util
::timespanFormat($ServerStatusData->status
['Uptime']),
71 PMA_Util
::localisedDate($start_time)
75 if ($GLOBALS['server_master_status'] ||
$GLOBALS['server_slave_status']) {
76 $retval .= '<p class="notice">';
77 if ($GLOBALS['server_master_status'] && $GLOBALS['server_slave_status']) {
79 'This MySQL server works as <b>master</b> and '
80 . '<b>slave</b> in <b>replication</b> process.'
82 } elseif ($GLOBALS['server_master_status']) {
84 'This MySQL server works as <b>master</b> '
85 . 'in <b>replication</b> process.'
87 } elseif ($GLOBALS['server_slave_status']) {
89 'This MySQL server works as <b>slave</b> '
90 . 'in <b>replication</b> process.'
97 * if the server works as master or slave in replication process,
98 * display useful information
100 if ($GLOBALS['server_master_status'] ||
$GLOBALS['server_slave_status']) {
101 $retval .= '<hr class="clearfloat" />';
102 $retval .= '<h3><a name="replication">';
103 $retval .= __('Replication status');
104 $retval .= '</a></h3>';
105 foreach ($GLOBALS['replication_types'] as $type) {
106 if (isset($
{"server_{$type}_status"}) && $
{"server_{$type}_status"}) {
107 $retval .= PMA_getHtmlForReplicationStatusTable($type);
116 * Prints server state traffic information
118 * @param PMA_ServerStatusData $ServerStatusData Server status data
122 function PMA_getHtmlForServerStateTraffic($ServerStatusData)
124 $hour_factor = 3600 / $ServerStatusData->status
['Uptime'];
125 $retval = '<table id="serverstatustraffic" class="data noclick">';
126 $retval .= '<thead>';
128 $retval .= '<th colspan="2">';
129 $retval .= __('Traffic') . ' ';
130 $retval .= PMA_Util
::showHint(
132 'On a busy server, the byte counters may overrun, so those statistics '
133 . 'as reported by the MySQL server may be incorrect.'
137 $retval .= '<th>ø ' . __('per hour') . '</th>';
139 $retval .= '</thead>';
140 $retval .= '<tbody>';
141 $retval .= '<tr class="odd">';
142 $retval .= '<th class="name">' . __('Received') . '</th>';
143 $retval .= '<td class="value">';
146 PMA_Util
::formatByteDown(
147 $ServerStatusData->status
['Bytes_received'], 3, 1
151 $retval .= '<td class="value">';
154 PMA_Util
::formatByteDown(
155 $ServerStatusData->status
['Bytes_received'] * $hour_factor, 3, 1
160 $retval .= '<tr class="even">';
161 $retval .= '<th class="name">' . __('Sent') . '</th>';
162 $retval .= '<td class="value">';
165 PMA_Util
::formatByteDown(
166 $ServerStatusData->status
['Bytes_sent'], 3, 1
170 $retval .= '<td class="value">';
173 PMA_Util
::formatByteDown(
174 $ServerStatusData->status
['Bytes_sent'] * $hour_factor, 3, 1
179 $retval .= '<tr class="odd">';
180 $retval .= '<th class="name">' . __('Total') . '</th>';
181 $retval .= '<td class="value">';
182 $bytes_received = $ServerStatusData->status
['Bytes_received'];
183 $bytes_sent = $ServerStatusData->status
['Bytes_sent'];
186 PMA_Util
::formatByteDown(
187 $bytes_received +
$bytes_sent, 3, 1
191 $retval .= '<td class="value">';
192 $bytes_received = $ServerStatusData->status
['Bytes_received'];
193 $bytes_sent = $ServerStatusData->status
['Bytes_sent'];
196 PMA_Util
::formatByteDown(
197 ($bytes_received +
$bytes_sent) * $hour_factor, 3, 1
202 $retval .= '</tbody>';
203 $retval .= '</table>';
208 * Prints server state connections information
210 * @param PMA_ServerStatusData $ServerStatusData Server status data
214 function PMA_getHtmlForServerStateConnections($ServerStatusData)
216 $hour_factor = 3600 / $ServerStatusData->status
['Uptime'];
217 $retval = '<table id="serverstatusconnections" class="data noclick">';
218 $retval .= '<thead>';
220 $retval .= '<th colspan="2">' . __('Connections') . '</th>';
221 $retval .= '<th>ø ' . __('per hour') . '</th>';
222 $retval .= '<th>%</th>';
224 $retval .= '</thead>';
225 $retval .= '<tbody>';
226 $retval .= '<tr class="odd">';
227 $retval .= '<th class="name">' . __('max. concurrent connections') . '</th>';
228 $retval .= '<td class="value">';
229 $retval .= PMA_Util
::formatNumber(
230 $ServerStatusData->status
['Max_used_connections'], 0
233 $retval .= '<td class="value">--- </td>';
234 $retval .= '<td class="value">--- </td>';
236 $retval .= '<tr class="even">';
237 $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
238 $retval .= '<td class="value">';
239 $retval .= PMA_Util
::formatNumber(
240 $ServerStatusData->status
['Aborted_connects'], 4, 1, true
243 $retval .= '<td class="value">';
244 $retval .= PMA_Util
::formatNumber(
245 $ServerStatusData->status
['Aborted_connects'] * $hour_factor, 4, 2, true
248 $retval .= '<td class="value">';
249 if ($ServerStatusData->status
['Connections'] > 0) {
250 $abortNum = $ServerStatusData->status
['Aborted_connects'];
251 $connectNum = $ServerStatusData->status
['Connections'];
253 $retval .= PMA_Util
::formatNumber(
254 $abortNum * 100 / $connectNum,
263 $retval .= '<tr class="odd">';
264 $retval .= '<th class="name">' . __('Aborted') . '</th>';
265 $retval .= '<td class="value">';
266 $retval .= PMA_Util
::formatNumber(
267 $ServerStatusData->status
['Aborted_clients'], 4, 1, true
270 $retval .= '<td class="value">';
271 $retval .= PMA_Util
::formatNumber(
272 $ServerStatusData->status
['Aborted_clients'] * $hour_factor, 4, 2, true
275 $retval .= '<td class="value">';
276 if ($ServerStatusData->status
['Connections'] > 0) {
277 $abortNum = $ServerStatusData->status
['Aborted_clients'];
278 $connectNum = $ServerStatusData->status
['Connections'];
280 $retval .= PMA_Util
::formatNumber(
281 $abortNum * 100 / $connectNum,
290 $retval .= '<tr class="even">';
291 $retval .= '<th class="name">' . __('Total') . '</th>';
292 $retval .= '<td class="value">';
293 $retval .= PMA_Util
::formatNumber(
294 $ServerStatusData->status
['Connections'], 4, 0
297 $retval .= '<td class="value">';
298 $retval .= PMA_Util
::formatNumber(
299 $ServerStatusData->status
['Connections'] * $hour_factor, 4, 2
302 $retval .= '<td class="value">';
303 $retval .= PMA_Util
::formatNumber(100, 0, 2);
306 $retval .= '</tbody>';
307 $retval .= '</table>';
313 * Prints Server Process list
317 function PMA_getHtmlForServerProcesslist()
319 $url_params = array();
321 $show_full_sql = ! empty($_REQUEST['full']);
322 if ($show_full_sql) {
323 $url_params['full'] = 1;
324 $full_text_link = 'server_status.php' . PMA_URL_getCommon(
328 $full_text_link = 'server_status.php' . PMA_URL_getCommon(
333 // This array contains display name and real column name of each
334 // sortable column in the table
335 $sortable_columns = array(
337 'column_name' => __('ID'),
338 'order_by_field' => 'Id'
341 'column_name' => __('User'),
342 'order_by_field' => 'User'
345 'column_name' => __('Host'),
346 'order_by_field' => 'Host'
349 'column_name' => __('Database'),
350 'order_by_field' => 'db'
353 'column_name' => __('Command'),
354 'order_by_field' => 'Command'
357 'column_name' => __('Time'),
358 'order_by_field' => 'Time'
361 'column_name' => __('Status'),
362 'order_by_field' => 'State'
365 'column_name' => __('SQL query'),
366 'order_by_field' => 'Info'
369 $sortableColCount = count($sortable_columns);
372 $left_str = 'left(p.info, '
373 . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')';
379 p.command AS Command,
382 . ($show_full_sql ?
's.query' : $left_str )
383 . " AS Info FROM data_dictionary.PROCESSLIST p "
385 ?
'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id'
387 if (! empty($_REQUEST['order_by_field'])
388 && ! empty($_REQUEST['sort_order'])
390 $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' '
391 . $_REQUEST['sort_order'];
394 $sql_query = $show_full_sql
395 ?
'SHOW FULL PROCESSLIST'
396 : 'SHOW PROCESSLIST';
397 if (! empty($_REQUEST['order_by_field'])
398 && ! empty($_REQUEST['sort_order'])
400 $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` '
402 . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order'];
406 $result = $GLOBALS['dbi']->query($sql_query);
408 $retval = '<table id="tableprocesslist" '
409 . 'class="data clearfloat noclick sortable">';
410 $retval .= '<thead>';
412 $retval .= '<th>' . __('Processes') . '</th>';
413 foreach ($sortable_columns as $column) {
415 $is_sorted = ! empty($_REQUEST['order_by_field'])
416 && ! empty($_REQUEST['sort_order'])
417 && ($_REQUEST['order_by_field'] == $column['order_by_field']);
419 $column['sort_order'] = 'ASC';
420 if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
421 $column['sort_order'] = 'DESC';
425 if ($_REQUEST['sort_order'] == 'ASC') {
426 $asc_display_style = 'inline';
427 $desc_display_style = 'none';
428 } elseif ($_REQUEST['sort_order'] == 'DESC') {
429 $desc_display_style = 'inline';
430 $asc_display_style = 'none';
435 $columnUrl = PMA_URL_getCommon($column);
436 $retval .= '<a href="server_status.php' . $columnUrl . '" ';
438 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
439 . 'onmouseover="$(\'.soimg\').toggle()"';
443 $retval .= $column['column_name'];
446 $retval .= '<img class="icon ic_s_desc soimg" alt="'
447 . __('Descending') . '" title="" src="themes/dot.gif" '
448 . 'style="display: ' . $desc_display_style . '" />';
449 $retval .= '<img class="icon ic_s_asc soimg hide" alt="'
450 . __('Ascending') . '" title="" src="themes/dot.gif" '
451 . 'style="display: ' . $asc_display_style . '" />';
456 if (! PMA_DRIZZLE
&& (0 === --$sortableColCount)) {
457 $retval .= '<a href="' . $full_text_link . '">';
458 if ($show_full_sql) {
459 $retval .= PMA_Util
::getImage(
461 __('Truncate Shown Queries')
464 $retval .= PMA_Util
::getImage(
466 __('Show Full Queries')
475 $retval .= '</thead>';
476 $retval .= '<tbody>';
479 while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
480 $retval .= PMA_getHtmlForServerProcessItem(
485 $odd_row = ! $odd_row;
487 $retval .= '</tbody>';
488 $retval .= '</table>';
494 * Prints Every Item of Server Process
496 * @param Array $process data of Every Item of Server Process
497 * @param bool $odd_row display odd row or not
498 * @param bool $show_full_sql show full sql or not
502 function PMA_getHtmlForServerProcessItem($process, $odd_row, $show_full_sql)
504 // Array keys need to modify due to the way it has used
505 // to display column values
506 if (! empty($_REQUEST['order_by_field']) && ! empty($_REQUEST['sort_order']) ) {
507 foreach (array_keys($process) as $key) {
508 $new_key = ucfirst(strtolower($key));
509 $process[$new_key] = $process[$key];
510 unset($process[$key]);
514 $url_params = array();
515 $url_params['kill'] = $process['Id'];
516 $kill_process = 'server_status.php' . PMA_URL_getCommon($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>' . htmlspecialchars($process['User']) . '</td>';
522 $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
523 $retval .= '<td>' . ((! isset($process['db']) ||
! strlen($process['db']))
524 ?
'<i>' . __('None') . '</i>'
525 : htmlspecialchars($process['db'])) . '</td>';
526 $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
527 $retval .= '<td class="value">' . $process['Time'] . '</td>';
528 $processStatusStr = empty($process['State']) ?
'---' : $process['State'];
529 $retval .= '<td>' . $processStatusStr . '</td>';
532 if (empty($process['Info'])) {
535 $retval .= PMA_Util
::formatSql($process['Info'], ! $show_full_sql);