added japanese language
[openemr.git] / phpmyadmin / libraries / server_status.lib.php
blob9e00d0a616a892a0ba4d06d7c70cfb09e2d5d099
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * functions for displaying server status
7 * @usedby server_status.php
9 * @package PhpMyAdmin
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 /**
16 * Prints server status information: processes, connections and traffic
18 * @param PMA_ServerStatusData $ServerStatusData Server status data
20 * @return string
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);
36 return $retval;
39 /**
40 * Prints server state General information
42 * @param PMA_ServerStatusData $ServerStatusData Server status data
44 * @return string
46 function PMA_getHtmlForServerStateGeneralInfo($ServerStatusData)
48 $start_time = $GLOBALS['dbi']->fetchValue(
49 'SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime']
52 $retval = '<h3>';
53 $bytes_received = $ServerStatusData->status['Bytes_received'];
54 $bytes_sent = $ServerStatusData->status['Bytes_sent'];
55 $retval .= sprintf(
56 __('Network traffic since startup: %s'),
57 implode(
58 ' ',
59 PMA_Util::formatByteDown(
60 $bytes_received + $bytes_sent,
66 $retval .= '</h3>';
67 $retval .= '<p>';
68 $retval .= sprintf(
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)
72 ) . "\n";
73 $retval .= '</p>';
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']) {
78 $retval .= __(
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']) {
83 $retval .= __(
84 'This MySQL server works as <b>master</b> '
85 . 'in <b>replication</b> process.'
87 } elseif ($GLOBALS['server_slave_status']) {
88 $retval .= __(
89 'This MySQL server works as <b>slave</b> '
90 . 'in <b>replication</b> process.'
93 $retval .= '</p>';
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);
112 return $retval;
116 * Prints server state traffic information
118 * @param PMA_ServerStatusData $ServerStatusData Server status data
120 * @return string
122 function PMA_getHtmlForServerStateTraffic($ServerStatusData)
124 $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
125 $retval = '<table id="serverstatustraffic" class="data noclick">';
126 $retval .= '<thead>';
127 $retval .= '<tr>';
128 $retval .= '<th colspan="2">';
129 $retval .= __('Traffic') . '&nbsp;';
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.'
136 $retval .= '</th>';
137 $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
138 $retval .= '</tr>';
139 $retval .= '</thead>';
140 $retval .= '<tbody>';
141 $retval .= '<tr class="odd">';
142 $retval .= '<th class="name">' . __('Received') . '</th>';
143 $retval .= '<td class="value">';
144 $retval .= implode(
145 ' ',
146 PMA_Util::formatByteDown(
147 $ServerStatusData->status['Bytes_received'], 3, 1
150 $retval .= '</td>';
151 $retval .= '<td class="value">';
152 $retval .= implode(
153 ' ',
154 PMA_Util::formatByteDown(
155 $ServerStatusData->status['Bytes_received'] * $hour_factor, 3, 1
158 $retval .= '</td>';
159 $retval .= '</tr>';
160 $retval .= '<tr class="even">';
161 $retval .= '<th class="name">' . __('Sent') . '</th>';
162 $retval .= '<td class="value">';
163 $retval .= implode(
164 ' ',
165 PMA_Util::formatByteDown(
166 $ServerStatusData->status['Bytes_sent'], 3, 1
169 $retval .= '</td>';
170 $retval .= '<td class="value">';
171 $retval .= implode(
172 ' ',
173 PMA_Util::formatByteDown(
174 $ServerStatusData->status['Bytes_sent'] * $hour_factor, 3, 1
177 $retval .= '</td>';
178 $retval .= '</tr>';
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'];
184 $retval .= implode(
185 ' ',
186 PMA_Util::formatByteDown(
187 $bytes_received + $bytes_sent, 3, 1
190 $retval .= '</td>';
191 $retval .= '<td class="value">';
192 $bytes_received = $ServerStatusData->status['Bytes_received'];
193 $bytes_sent = $ServerStatusData->status['Bytes_sent'];
194 $retval .= implode(
195 ' ',
196 PMA_Util::formatByteDown(
197 ($bytes_received + $bytes_sent) * $hour_factor, 3, 1
200 $retval .= '</td>';
201 $retval .= '</tr>';
202 $retval .= '</tbody>';
203 $retval .= '</table>';
204 return $retval;
208 * Prints server state connections information
210 * @param PMA_ServerStatusData $ServerStatusData Server status data
212 * @return string
214 function PMA_getHtmlForServerStateConnections($ServerStatusData)
216 $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
217 $retval = '<table id="serverstatusconnections" class="data noclick">';
218 $retval .= '<thead>';
219 $retval .= '<tr>';
220 $retval .= '<th colspan="2">' . __('Connections') . '</th>';
221 $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
222 $retval .= '<th>%</th>';
223 $retval .= '</tr>';
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
232 $retval .= '</td>';
233 $retval .= '<td class="value">--- </td>';
234 $retval .= '<td class="value">--- </td>';
235 $retval .= '</tr>';
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
242 $retval .= '</td>';
243 $retval .= '<td class="value">';
244 $retval .= PMA_Util::formatNumber(
245 $ServerStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true
247 $retval .= '</td>';
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,
255 0, 2, true
257 $retval .= '%';
258 } else {
259 $retval .= '--- ';
261 $retval .= '</td>';
262 $retval .= '</tr>';
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
269 $retval .= '</td>';
270 $retval .= '<td class="value">';
271 $retval .= PMA_Util::formatNumber(
272 $ServerStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true
274 $retval .= '</td>';
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,
282 0, 2, true
284 $retval .= '%';
285 } else {
286 $retval .= '--- ';
288 $retval .= '</td>';
289 $retval .= '</tr>';
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
296 $retval .= '</td>';
297 $retval .= '<td class="value">';
298 $retval .= PMA_Util::formatNumber(
299 $ServerStatusData->status['Connections'] * $hour_factor, 4, 2
301 $retval .= '</td>';
302 $retval .= '<td class="value">';
303 $retval .= PMA_Util::formatNumber(100, 0, 2);
304 $retval .= '%</td>';
305 $retval .= '</tr>';
306 $retval .= '</tbody>';
307 $retval .= '</table>';
309 return $retval;
313 * Prints Server Process list
315 * @return string
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(
325 array(), 'html', '?'
327 } else {
328 $full_text_link = 'server_status.php' . PMA_URL_getCommon(
329 array('full' => 1)
333 // This array contains display name and real column name of each
334 // sortable column in the table
335 $sortable_columns = array(
336 array(
337 'column_name' => __('ID'),
338 'order_by_field' => 'Id'
340 array(
341 'column_name' => __('User'),
342 'order_by_field' => 'User'
344 array(
345 'column_name' => __('Host'),
346 'order_by_field' => 'Host'
348 array(
349 'column_name' => __('Database'),
350 'order_by_field' => 'db'
352 array(
353 'column_name' => __('Command'),
354 'order_by_field' => 'Command'
356 array(
357 'column_name' => __('Time'),
358 'order_by_field' => 'Time'
360 array(
361 'column_name' => __('Status'),
362 'order_by_field' => 'State'
364 array(
365 'column_name' => __('SQL query'),
366 'order_by_field' => 'Info'
369 $sortableColCount = count($sortable_columns);
371 if (PMA_DRIZZLE) {
372 $left_str = 'left(p.info, '
373 . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')';
374 $sql_query = "SELECT
375 p.id AS Id,
376 p.username AS User,
377 p.host AS Host,
378 p.db AS db,
379 p.command AS Command,
380 p.time AS Time,
381 p.state AS State,"
382 . ($show_full_sql ? 's.query' : $left_str )
383 . " AS Info FROM data_dictionary.PROCESSLIST p "
384 . ($show_full_sql
385 ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id'
386 : '');
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'];
393 } else {
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` '
401 . 'ORDER BY `'
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>';
411 $retval .= '<tr>';
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';
424 if ($is_sorted) {
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';
434 $retval .= '<th>';
435 $columnUrl = PMA_URL_getCommon($column);
436 $retval .= '<a href="server_status.php' . $columnUrl . '" ';
437 if ($is_sorted) {
438 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
439 . 'onmouseover="$(\'.soimg\').toggle()"';
441 $retval .= '>';
443 $retval .= $column['column_name'];
445 if ($is_sorted) {
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 . '" />';
454 $retval .= '</a>';
456 if (! PMA_DRIZZLE && (0 === --$sortableColCount)) {
457 $retval .= '<a href="' . $full_text_link . '">';
458 if ($show_full_sql) {
459 $retval .= PMA_Util::getImage(
460 's_partialtext.png',
461 __('Truncate Shown Queries')
463 } else {
464 $retval .= PMA_Util::getImage(
465 's_fulltext.png',
466 __('Show Full Queries')
469 $retval .= '</a>';
471 $retval .= '</th>';
474 $retval .= '</tr>';
475 $retval .= '</thead>';
476 $retval .= '<tbody>';
478 $odd_row = true;
479 while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
480 $retval .= PMA_getHtmlForServerProcessItem(
481 $process,
482 $odd_row,
483 $show_full_sql
485 $odd_row = ! $odd_row;
487 $retval .= '</tbody>';
488 $retval .= '</table>';
490 return $retval;
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
500 * @return string
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>';
530 $retval .= '<td>';
532 if (empty($process['Info'])) {
533 $retval .= '---';
534 } else {
535 $retval .= PMA_Util::formatSql($process['Info'], ! $show_full_sql);
537 $retval .= '</td>';
538 $retval .= '</tr>';
540 return $retval;