Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / server_status_queries.lib.php
blob270a7529402fff4add4ece8cbdfa5bbade7bfc73
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * functions for displaying query statistics for the server
6 * @usedby server_status_queries.php
8 * @package PhpMyAdmin
9 */
10 use PMA\libraries\ServerStatusData;
12 /**
13 * Returns the html content for the query statistics
15 * @param ServerStatusData $ServerStatusData Server status data
17 * @return string
19 function PMA_getHtmlForQueryStatistics($ServerStatusData)
21 $retval = '';
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 */
29 $retval .= sprintf(
30 __('Questions since startup: %s'),
31 PMA\libraries\Util::formatNumber($total_queries, 0)
33 $retval .= ' ';
34 $retval .= PMA\libraries\Util::showMySQLDocu(
35 'server-status-variables',
36 false,
37 'statvar_Questions'
39 $retval .= '<br />';
40 $retval .= '<span>';
41 $retval .= '&oslash; ' . __('per hour:') . ' ';
42 $retval .= PMA\libraries\Util::formatNumber($total_queries * $hour_factor, 0);
43 $retval .= '<br />';
44 $retval .= '&oslash; ' . __('per minute:') . ' ';
45 $retval .= PMA\libraries\Util::formatNumber(
46 $total_queries * 60 / $ServerStatusData->status['Uptime'],
49 $retval .= '<br />';
50 if ($total_queries / $ServerStatusData->status['Uptime'] >= 1) {
51 $retval .= '&oslash; ' . __('per second:') . ' ';
52 $retval .= PMA\libraries\Util::formatNumber(
53 $total_queries / $ServerStatusData->status['Uptime'],
57 $retval .= '</span>';
58 $retval .= '</h3>';
60 $retval .= PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData);
62 return $retval;
65 /**
66 * Returns the html content for the query details
68 * @param ServerStatusData $ServerStatusData Server status data
70 * @return string
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" />';
87 $retval .= '<thead>';
88 $retval .= '<tr><th>' . __('Statements') . '</th>';
89 $retval .= '<th>';
90 /* l10n: # = Amount of queries */
91 $retval .= __('#');
92 $retval .= '</th>';
93 $retval .= '<th>&oslash; ' . __('per hour')
94 . '</th>';
95 $retval .= '<th>%</div></th>';
96 $retval .= '</tr>';
97 $retval .= '</thead>';
98 $retval .= '<tbody>';
100 $chart_json = array();
101 $query_sum = array_sum($used_queries);
102 $other_sum = 0;
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;
112 } else {
113 $chart_json[$name] = $value;
115 $retval .= '<tr>';
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)
121 $retval .= '</td>';
122 $retval .= '<td class="value">';
123 $retval .= htmlspecialchars(
124 PMA\libraries\Util::formatNumber($value * $hour_factor, 4, 1, true)
126 $retval .= '</td>';
127 $retval .= '<td class="value">';
128 $retval .= htmlspecialchars(
129 PMA\libraries\Util::formatNumber($value * $perc_factor, 0, 2)
131 $retval .= '</td>';
132 $retval .= '</tr>';
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>';
144 return $retval;