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 Object $ServerStatusData An instance of the PMA_ServerStatusData class
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 Object $ServerStatusData An instance of the PMA_ServerStatusData class
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 Object $ServerStatusData An instance of the PMA_ServerStatusData class
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"><?php echo';
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 Object $ServerStatusData An instance of the PMA_ServerStatusData class
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
315 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
319 function PMA_getHtmlForServerProcesslist($ServerStatusData)
321 $url_params = array();
323 $show_full_sql = ! empty($_REQUEST['full']);
324 if ($show_full_sql) {
325 $url_params['full'] = 1;
326 $full_text_link = 'server_status.php' . PMA_URL_getCommon(
330 $full_text_link = 'server_status.php' . PMA_URL_getCommon(
335 // This array contains display name and real column name of each
336 // sortable column in the table
337 $sortable_columns = array(
339 'column_name' => __('ID'),
340 'order_by_field' => 'Id'
343 'column_name' => __('User'),
344 'order_by_field' => 'User'
347 'column_name' => __('Host'),
348 'order_by_field' => 'Host'
351 'column_name' => __('Database'),
352 'order_by_field' => 'db'
355 'column_name' => __('Command'),
356 'order_by_field' => 'Command'
359 'column_name' => __('Time'),
360 'order_by_field' => 'Time'
363 'column_name' => __('Status'),
364 'order_by_field' => 'State'
367 'column_name' => __('SQL query'),
368 'order_by_field' => 'Info'
371 $sortable_columns_count = count($sortable_columns);
374 $left_str = 'left(p.info, '
375 . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')';
381 p.command AS Command,
384 . ($show_full_sql ?
's.query' : $left_str )
385 . " AS Info FROM data_dictionary.PROCESSLIST p "
387 ?
'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id'
389 if (! empty($_REQUEST['order_by_field'])
390 && ! empty($_REQUEST['sort_order'])
392 $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' '
393 . $_REQUEST['sort_order'];
396 $sql_query = $show_full_sql
397 ?
'SHOW FULL PROCESSLIST'
398 : 'SHOW PROCESSLIST';
399 if (! empty($_REQUEST['order_by_field'])
400 && ! empty($_REQUEST['sort_order'])
402 $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` '
404 . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order'];
408 $result = $GLOBALS['dbi']->query($sql_query);
410 $retval = '<table id="tableprocesslist" '
411 . 'class="data clearfloat noclick sortable">';
412 $retval .= '<thead>';
414 $retval .= '<th>' . __('Processes') . '</th>';
415 foreach ($sortable_columns as $column) {
417 $is_sorted = ! empty($_REQUEST['order_by_field'])
418 && ! empty($_REQUEST['sort_order'])
419 && ($_REQUEST['order_by_field'] == $column['order_by_field']);
421 $column['sort_order'] = 'ASC';
422 if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
423 $column['sort_order'] = 'DESC';
427 if ($_REQUEST['sort_order'] == 'ASC') {
428 $asc_display_style = 'inline';
429 $desc_display_style = 'none';
430 } elseif ($_REQUEST['sort_order'] == 'DESC') {
431 $desc_display_style = 'inline';
432 $asc_display_style = 'none';
437 $columnUrl = PMA_URL_getCommon($column);
438 $retval .= '<a href="server_status.php' . $columnUrl . '" ';
440 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
441 . 'onmouseover="$(\'.soimg\').toggle()"';
445 $retval .= $column['column_name'];
448 $retval .= '<img class="icon ic_s_desc soimg" alt="'
449 . __('Descending') . '" title="" src="themes/dot.gif" '
450 . 'style="display: ' . $desc_display_style . '" />';
451 $retval .= '<img class="icon ic_s_asc soimg hide" alt="'
452 . __('Ascending') . '" title="" src="themes/dot.gif" '
453 . 'style="display: ' . $asc_display_style . '" />';
458 if (! PMA_DRIZZLE
&& (0 === --$sortable_columns_count)) {
459 $retval .= '<a href="' . $full_text_link . '">';
460 if ($show_full_sql) {
461 $retval .= PMA_Util
::getImage(
463 __('Truncate Shown Queries')
466 $retval .= PMA_Util
::getImage(
468 __('Show Full Queries')
477 $retval .= '</thead>';
478 $retval .= '<tbody>';
481 while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
482 $retval .= PMA_getHtmlForServerProcessItem(
487 $odd_row = ! $odd_row;
489 $retval .= '</tbody>';
490 $retval .= '</table>';
496 * Prints Every Item of Server Process
498 * @param Array $process data of Every Item of Server Process
499 * @param bool $odd_row display odd row or not
500 * @param bool $show_full_sql show full sql or not
504 function PMA_getHtmlForServerProcessItem($process, $odd_row, $show_full_sql)
506 // Array keys need to modify due to the way it has used
507 // to display column values
508 if (! empty($_REQUEST['order_by_field']) && ! empty($_REQUEST['sort_order']) ) {
509 foreach (array_keys($process) as $key) {
510 $new_key = ucfirst(strtolower($key));
511 $process[$new_key] = $process[$key];
512 unset($process[$key]);
516 $url_params['kill'] = $process['Id'];
517 $kill_process = 'server_status.php' . PMA_URL_getCommon($url_params);
519 $retval = '<tr class="' . ($odd_row ?
'odd' : 'even') . '">';
520 $retval .= '<td><a href="' . $kill_process . '">' . __('Kill') . '</a></td>';
521 $retval .= '<td class="value">' . $process['Id'] . '</td>';
522 $retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
523 $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
524 $retval .= '<td>' . ((! isset($process['db']) ||
! strlen($process['db']))
525 ?
'<i>' . __('None') . '</i>'
526 : htmlspecialchars($process['db'])) . '</td>';
527 $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
528 $retval .= '<td class="value">' . $process['Time'] . '</td>';
529 $processStatusStr = empty($process['State']) ?
'---' : $process['State'];
530 $retval .= '<td>' . $processStatusStr . '</td>';
533 if (empty($process['Info'])) {
536 $retval .= PMA_Util
::formatSql($process['Info'], ! $show_full_sql);