2 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * functions for displaying query statistics for the server
7 * @usedby server_status_queries.php
11 if (! defined('PHPMYADMIN')) {
16 * Returns the html content for the query statistics
18 * @param PMA_ServerStatusData $ServerStatusData Server status data
22 function PMA_getHtmlForQueryStatistics($ServerStatusData)
26 $hour_factor = 3600 / $ServerStatusData->status
['Uptime'];
27 $used_queries = $ServerStatusData->used_queries
;
28 $total_queries = array_sum($used_queries);
30 $retval .= '<h3 id="serverstatusqueries">';
31 /* l10n: Questions is the name of a MySQL Status variable */
33 __('Questions since startup: %s'),
34 PMA_Util
::formatNumber($total_queries, 0)
37 $retval .= PMA_Util
::showMySQLDocu(
38 'server-status-variables',
44 $retval .= 'ø ' . __('per hour:') . ' ';
45 $retval .= PMA_Util
::formatNumber($total_queries * $hour_factor, 0);
47 $retval .= 'ø ' . __('per minute:') . ' ';
48 $retval .= PMA_Util
::formatNumber(
49 $total_queries * 60 / $ServerStatusData->status
['Uptime'],
53 if ($total_queries / $ServerStatusData->status
['Uptime'] >= 1) {
54 $retval .= 'ø ' . __('per second:') . ' ';
55 $retval .= PMA_Util
::formatNumber(
56 $total_queries / $ServerStatusData->status
['Uptime'],
63 $retval .= PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData);
69 * Returns the html content for the query details
71 * @param PMA_ServerStatusData $ServerStatusData Server status data
75 function PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData)
77 $hour_factor = 3600 / $ServerStatusData->status
['Uptime'];
78 $used_queries = $ServerStatusData->used_queries
;
79 $total_queries = array_sum($used_queries);
80 // reverse sort by value to show most used statements first
81 arsort($used_queries);
85 //(- $ServerStatusData->status['Connections']);
86 $perc_factor = 100 / $total_queries;
88 $retval = '<table id="serverstatusqueriesdetails" '
89 . 'class="data sortable noclick">';
90 $retval .= '<col class="namecol" />';
91 $retval .= '<col class="valuecol" span="3" />';
93 $retval .= '<tr><th>' . __('Statements') . '</th>';
95 /* l10n: # = Amount of queries */
98 $retval .= '<th>ø ' . __('per hour') . '</th>';
99 $retval .= '<th>%</th>';
101 $retval .= '</thead>';
102 $retval .= '<tbody>';
104 $chart_json = array();
105 $query_sum = array_sum($used_queries);
107 foreach ($used_queries as $name => $value) {
108 $odd_row = !$odd_row;
109 // For the percentage column, use Questions - Connections, because
110 // the number of connections is not an item of the Query types
111 // but is included in Questions. Then the total of the percentages is 100.
112 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
113 // Group together values that make out less than 2% into "Other", but only
114 // if we have more than 6 fractions already
115 if ($value < $query_sum * 0.02 && count($chart_json)>6) {
116 $other_sum +
= $value;
118 $chart_json[$name] = $value;
120 $retval .= '<tr class="';
121 $retval .= $odd_row ?
'odd' : 'even';
123 $retval .= '<th class="name">' . htmlspecialchars($name) . '</th>';
124 $retval .= '<td class="value">';
125 $retval .= htmlspecialchars(PMA_Util
::formatNumber($value, 5, 0, true));
127 $retval .= '<td class="value">';
128 $retval .= htmlspecialchars(
129 PMA_Util
::formatNumber($value * $hour_factor, 4, 1, true)
132 $retval .= '<td class="value">';
133 $retval .= htmlspecialchars(
134 PMA_Util
::formatNumber($value * $perc_factor, 0, 2)
139 $retval .= '</tbody>';
140 $retval .= '</table>';
142 $retval .= '<div id="serverstatusquerieschart"></div>';
143 $retval .= '<div id="serverstatusquerieschart_data" style="display:none;">';
144 if ($other_sum > 0) {
145 $chart_json[__('Other')] = $other_sum;
147 $retval .= htmlspecialchars(json_encode($chart_json));