2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * functions for displaying query statistics for the server
6 * @usedby server_status_queries.php
10 use PMA\libraries\ServerStatusData
;
13 * Returns the html content for the query statistics
15 * @param ServerStatusData $ServerStatusData Server status data
19 function PMA_getHtmlForQueryStatistics($ServerStatusData)
23 $hour_factor = 3600 / $ServerStatusData->status
['Uptime'];
24 $used_queries = $ServerStatusData->used_queries
;
25 $total_queries = array_sum($used_queries);
27 $retval .= '<h3 id="serverstatusqueries">';
28 /* l10n: Questions is the name of a MySQL Status variable */
30 __('Questions since startup: %s'),
31 PMA\libraries\Util
::formatNumber($total_queries, 0)
34 $retval .= PMA\libraries\Util
::showMySQLDocu(
35 'server-status-variables',
41 $retval .= 'ø ' . __('per hour:') . ' ';
42 $retval .= PMA\libraries\Util
::formatNumber($total_queries * $hour_factor, 0);
44 $retval .= 'ø ' . __('per minute:') . ' ';
45 $retval .= PMA\libraries\Util
::formatNumber(
46 $total_queries * 60 / $ServerStatusData->status
['Uptime'],
50 if ($total_queries / $ServerStatusData->status
['Uptime'] >= 1) {
51 $retval .= 'ø ' . __('per second:') . ' ';
52 $retval .= PMA\libraries\Util
::formatNumber(
53 $total_queries / $ServerStatusData->status
['Uptime'],
60 $retval .= PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData);
66 * Returns the html content for the query details
68 * @param ServerStatusData $ServerStatusData Server status data
72 function PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData)
74 $hour_factor = 3600 / $ServerStatusData->status
['Uptime'];
75 $used_queries = $ServerStatusData->used_queries
;
76 $total_queries = array_sum($used_queries);
77 // reverse sort by value to show most used statements first
78 arsort($used_queries);
80 //(- $ServerStatusData->status['Connections']);
81 $perc_factor = 100 / $total_queries;
83 $retval = '<table id="serverstatusqueriesdetails" '
84 . 'class="data sortable noclick">';
85 $retval .= '<col class="namecol" />';
86 $retval .= '<col class="valuecol" span="3" />';
88 $retval .= '<tr><th>' . __('Statements') . '</th>';
90 /* l10n: # = Amount of queries */
93 $retval .= '<th>ø ' . __('per hour')
95 $retval .= '<th>%</div></th>';
97 $retval .= '</thead>';
100 $chart_json = array();
101 $query_sum = array_sum($used_queries);
103 foreach ($used_queries as $name => $value) {
104 // For the percentage column, use Questions - Connections, because
105 // the number of connections is not an item of the Query types
106 // but is included in Questions. Then the total of the percentages is 100.
107 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
108 // Group together values that make out less than 2% into "Other", but only
109 // if we have more than 6 fractions already
110 if ($value < $query_sum * 0.02 && count($chart_json)>6) {
111 $other_sum +
= $value;
113 $chart_json[$name] = $value;
116 $retval .= '<th class="name">' . htmlspecialchars($name) . '</th>';
117 $retval .= '<td class="value">';
118 $retval .= htmlspecialchars(
119 PMA\libraries\Util
::formatNumber($value, 5, 0, true)
122 $retval .= '<td class="value">';
123 $retval .= htmlspecialchars(
124 PMA\libraries\Util
::formatNumber($value * $hour_factor, 4, 1, true)
127 $retval .= '<td class="value">';
128 $retval .= htmlspecialchars(
129 PMA\libraries\Util
::formatNumber($value * $perc_factor, 0, 2)
134 $retval .= '</tbody>';
135 $retval .= '</table>';
137 $retval .= '<div id="serverstatusquerieschart" data-chart="';
138 if ($other_sum > 0) {
139 $chart_json[__('Other')] = $other_sum;
141 $retval .= htmlspecialchars(json_encode($chart_json), ENT_QUOTES
);
142 $retval .= '"></div>';