Removing old documentation
[openemr.git] / phpmyadmin / libraries / server_status.lib.php
blob824bdfe50db455a441346188d9cd916ec5161fc1
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 replication information
34 if ($GLOBALS['replication_info']['master']['status']
35 || $GLOBALS['replication_info']['slave']['status']
36 ) {
37 $retval .= PMA_getHtmlForReplicationInfo();
40 return $retval;
43 /**
44 * Prints server state General information
46 * @param PMA_ServerStatusData $ServerStatusData Server status data
48 * @return string
50 function PMA_getHtmlForServerStateGeneralInfo($ServerStatusData)
52 $start_time = $GLOBALS['dbi']->fetchValue(
53 'SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime']
56 $retval = '<h3>';
57 $bytes_received = $ServerStatusData->status['Bytes_received'];
58 $bytes_sent = $ServerStatusData->status['Bytes_sent'];
59 $retval .= sprintf(
60 __('Network traffic since startup: %s'),
61 implode(
62 ' ',
63 PMA_Util::formatByteDown(
64 $bytes_received + $bytes_sent,
70 $retval .= '</h3>';
71 $retval .= '<p>';
72 $retval .= sprintf(
73 __('This MySQL server has been running for %1$s. It started up on %2$s.'),
74 PMA_Util::timespanFormat($ServerStatusData->status['Uptime']),
75 PMA_Util::localisedDate($start_time)
76 ) . "\n";
77 $retval .= '</p>';
79 return $retval;
82 /**
83 * Returns HTML to display replication information
85 * @return string HTML on replication
87 function PMA_getHtmlForReplicationInfo()
89 $retval = '<p class="notice clearfloat">';
90 if ($GLOBALS['replication_info']['master']['status']
91 && $GLOBALS['replication_info']['slave']['status']
92 ) {
93 $retval .= __(
94 'This MySQL server works as <b>master</b> and '
95 . '<b>slave</b> in <b>replication</b> process.'
97 } elseif ($GLOBALS['replication_info']['master']['status']) {
98 $retval .= __(
99 'This MySQL server works as <b>master</b> '
100 . 'in <b>replication</b> process.'
102 } elseif ($GLOBALS['replication_info']['slave']['status']) {
103 $retval .= __(
104 'This MySQL server works as <b>slave</b> '
105 . 'in <b>replication</b> process.'
108 $retval .= '</p>';
111 * if the server works as master or slave in replication process,
112 * display useful information
114 $retval .= '<hr class="clearfloat" />';
115 $retval .= '<h3><a name="replication">';
116 $retval .= __('Replication status');
117 $retval .= '</a></h3>';
118 foreach ($GLOBALS['replication_types'] as $type) {
119 if (isset($GLOBALS['replication_info'][$type]['status'])
120 && $GLOBALS['replication_info'][$type]['status']
122 $retval .= PMA_getHtmlForReplicationStatusTable($type);
126 return $retval;
130 * Prints server state traffic information
132 * @param PMA_ServerStatusData $ServerStatusData Server status data
134 * @return string
136 function PMA_getHtmlForServerStateTraffic($ServerStatusData)
138 $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
139 $retval = '<table id="serverstatustraffic" class="data noclick">';
140 $retval .= '<thead>';
141 $retval .= '<tr>';
142 $retval .= '<th>';
143 $retval .= __('Traffic') . '&nbsp;';
144 $retval .= PMA_Util::showHint(
146 'On a busy server, the byte counters may overrun, so those statistics '
147 . 'as reported by the MySQL server may be incorrect.'
150 $retval .= '</th>';
151 $retval .= '<th>#</th>';
152 $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
153 $retval .= '</tr>';
154 $retval .= '</thead>';
155 $retval .= '<tbody>';
156 $retval .= '<tr class="odd">';
157 $retval .= '<th class="name">' . __('Received') . '</th>';
158 $retval .= '<td class="value">';
159 $retval .= implode(
160 ' ',
161 PMA_Util::formatByteDown(
162 $ServerStatusData->status['Bytes_received'], 3, 1
165 $retval .= '</td>';
166 $retval .= '<td class="value">';
167 $retval .= implode(
168 ' ',
169 PMA_Util::formatByteDown(
170 $ServerStatusData->status['Bytes_received'] * $hour_factor, 3, 1
173 $retval .= '</td>';
174 $retval .= '</tr>';
175 $retval .= '<tr class="even">';
176 $retval .= '<th class="name">' . __('Sent') . '</th>';
177 $retval .= '<td class="value">';
178 $retval .= implode(
179 ' ',
180 PMA_Util::formatByteDown(
181 $ServerStatusData->status['Bytes_sent'], 3, 1
184 $retval .= '</td>';
185 $retval .= '<td class="value">';
186 $retval .= implode(
187 ' ',
188 PMA_Util::formatByteDown(
189 $ServerStatusData->status['Bytes_sent'] * $hour_factor, 3, 1
192 $retval .= '</td>';
193 $retval .= '</tr>';
194 $retval .= '<tr class="odd">';
195 $retval .= '<th class="name">' . __('Total') . '</th>';
196 $retval .= '<td class="value">';
197 $bytes_received = $ServerStatusData->status['Bytes_received'];
198 $bytes_sent = $ServerStatusData->status['Bytes_sent'];
199 $retval .= implode(
200 ' ',
201 PMA_Util::formatByteDown(
202 $bytes_received + $bytes_sent, 3, 1
205 $retval .= '</td>';
206 $retval .= '<td class="value">';
207 $bytes_received = $ServerStatusData->status['Bytes_received'];
208 $bytes_sent = $ServerStatusData->status['Bytes_sent'];
209 $retval .= implode(
210 ' ',
211 PMA_Util::formatByteDown(
212 ($bytes_received + $bytes_sent) * $hour_factor, 3, 1
215 $retval .= '</td>';
216 $retval .= '</tr>';
217 $retval .= '</tbody>';
218 $retval .= '</table>';
219 return $retval;
223 * Prints server state connections information
225 * @param PMA_ServerStatusData $ServerStatusData Server status data
227 * @return string
229 function PMA_getHtmlForServerStateConnections($ServerStatusData)
231 $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
232 $retval = '<table id="serverstatusconnections" class="data noclick">';
233 $retval .= '<thead>';
234 $retval .= '<tr>';
235 $retval .= '<th>' . __('Connections') . '</th>';
236 $retval .= '<th>#</th>';
237 $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
238 $retval .= '<th>%</th>';
239 $retval .= '</tr>';
240 $retval .= '</thead>';
241 $retval .= '<tbody>';
242 $retval .= '<tr class="odd">';
243 $retval .= '<th class="name">' . __('Max. concurrent connections') . '</th>';
244 $retval .= '<td class="value">';
245 $retval .= PMA_Util::formatNumber(
246 $ServerStatusData->status['Max_used_connections'], 0
248 $retval .= '</td>';
249 $retval .= '<td class="value">--- </td>';
250 $retval .= '<td class="value">--- </td>';
251 $retval .= '</tr>';
252 $retval .= '<tr class="even">';
253 $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
254 $retval .= '<td class="value">';
255 $retval .= PMA_Util::formatNumber(
256 $ServerStatusData->status['Aborted_connects'], 4, 1, true
258 $retval .= '</td>';
259 $retval .= '<td class="value">';
260 $retval .= PMA_Util::formatNumber(
261 $ServerStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true
263 $retval .= '</td>';
264 $retval .= '<td class="value">';
265 if ($ServerStatusData->status['Connections'] > 0) {
266 $abortNum = $ServerStatusData->status['Aborted_connects'];
267 $connectNum = $ServerStatusData->status['Connections'];
269 $retval .= PMA_Util::formatNumber(
270 $abortNum * 100 / $connectNum,
271 0, 2, true
273 $retval .= '%';
274 } else {
275 $retval .= '--- ';
277 $retval .= '</td>';
278 $retval .= '</tr>';
279 $retval .= '<tr class="odd">';
280 $retval .= '<th class="name">' . __('Aborted') . '</th>';
281 $retval .= '<td class="value">';
282 $retval .= PMA_Util::formatNumber(
283 $ServerStatusData->status['Aborted_clients'], 4, 1, true
285 $retval .= '</td>';
286 $retval .= '<td class="value">';
287 $retval .= PMA_Util::formatNumber(
288 $ServerStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true
290 $retval .= '</td>';
291 $retval .= '<td class="value">';
292 if ($ServerStatusData->status['Connections'] > 0) {
293 $abortNum = $ServerStatusData->status['Aborted_clients'];
294 $connectNum = $ServerStatusData->status['Connections'];
296 $retval .= PMA_Util::formatNumber(
297 $abortNum * 100 / $connectNum,
298 0, 2, true
300 $retval .= '%';
301 } else {
302 $retval .= '--- ';
304 $retval .= '</td>';
305 $retval .= '</tr>';
306 $retval .= '<tr class="even">';
307 $retval .= '<th class="name">' . __('Total') . '</th>';
308 $retval .= '<td class="value">';
309 $retval .= PMA_Util::formatNumber(
310 $ServerStatusData->status['Connections'], 4, 0
312 $retval .= '</td>';
313 $retval .= '<td class="value">';
314 $retval .= PMA_Util::formatNumber(
315 $ServerStatusData->status['Connections'] * $hour_factor, 4, 2
317 $retval .= '</td>';
318 $retval .= '<td class="value">';
319 $retval .= PMA_Util::formatNumber(100, 0, 2);
320 $retval .= '%</td>';
321 $retval .= '</tr>';
322 $retval .= '</tbody>';
323 $retval .= '</table>';
325 return $retval;