Translated using Weblate (Polish)
[phpmyadmin.git] / libraries / server_status.lib.php
blob4c12d3099ab0361fc0a1737db7523e6c2ad16944
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 Object $ServerStatusData An instance of the PMA_ServerStatusData class
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 Object $ServerStatusData An instance of the PMA_ServerStatusData class
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 Object $ServerStatusData An instance of the PMA_ServerStatusData class
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"><?php echo';
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 Object $ServerStatusData An instance of the PMA_ServerStatusData class
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 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
317 * @return string
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(
327 array(), 'html', '?'
329 } else {
330 $full_text_link = 'server_status.php' . PMA_URL_getCommon(
331 array('full' => 1)
335 // This array contains display name and real column name of each
336 // sortable column in the table
337 $sortable_columns = array(
338 array(
339 'column_name' => __('ID'),
340 'order_by_field' => 'Id'
342 array(
343 'column_name' => __('User'),
344 'order_by_field' => 'User'
346 array(
347 'column_name' => __('Host'),
348 'order_by_field' => 'Host'
350 array(
351 'column_name' => __('Database'),
352 'order_by_field' => 'db'
354 array(
355 'column_name' => __('Command'),
356 'order_by_field' => 'Command'
358 array(
359 'column_name' => __('Time'),
360 'order_by_field' => 'Time'
362 array(
363 'column_name' => __('Status'),
364 'order_by_field' => 'State'
366 array(
367 'column_name' => __('SQL query'),
368 'order_by_field' => 'Info'
371 $sortable_columns_count = count($sortable_columns);
373 if (PMA_DRIZZLE) {
374 $left_str = 'left(p.info, '
375 . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')';
376 $sql_query = "SELECT
377 p.id AS Id,
378 p.username AS User,
379 p.host AS Host,
380 p.db AS db,
381 p.command AS Command,
382 p.time AS Time,
383 p.state AS State,"
384 . ($show_full_sql ? 's.query' : $left_str )
385 . " AS Info FROM data_dictionary.PROCESSLIST p "
386 . ($show_full_sql
387 ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id'
388 : '');
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'];
395 } else {
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` '
403 . 'ORDER BY `'
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>';
413 $retval .= '<tr>';
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';
426 if ($is_sorted) {
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';
436 $retval .= '<th>';
437 $columnUrl = PMA_URL_getCommon($column);
438 $retval .= '<a href="server_status.php' . $columnUrl . '" ';
439 if ($is_sorted) {
440 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
441 . 'onmouseover="$(\'.soimg\').toggle()"';
443 $retval .= '>';
445 $retval .= $column['column_name'];
447 if ($is_sorted) {
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 . '" />';
456 $retval .= '</a>';
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(
462 's_partialtext.png',
463 __('Truncate Shown Queries')
465 } else {
466 $retval .= PMA_Util::getImage(
467 's_fulltext.png',
468 __('Show Full Queries')
471 $retval .= '</a>';
473 $retval .= '</th>';
476 $retval .= '</tr>';
477 $retval .= '</thead>';
478 $retval .= '<tbody>';
480 $odd_row = true;
481 while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
482 $retval .= PMA_getHtmlForServerProcessItem(
483 $process,
484 $odd_row,
485 $show_full_sql
487 $odd_row = ! $odd_row;
489 $retval .= '</tbody>';
490 $retval .= '</table>';
492 return $retval;
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
502 * @return string
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>';
531 $retval .= '<td>';
533 if (empty($process['Info'])) {
534 $retval .= '---';
535 } else {
536 $retval .= PMA_Util::formatSql($process['Info'], ! $show_full_sql);
538 $retval .= '</td>';
539 $retval .= '</tr>';
541 return $retval;