Translated using Weblate (Spanish)
[phpmyadmin.git] / server_status_queries.php
blob3df0725b7687d85e7e6c3024078ec1a33c85ea69
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays query statistics for the server
6 * @package PhpMyAdmin
7 */
9 require_once 'libraries/common.inc.php';
10 require_once 'libraries/server_common.inc.php';
11 require_once 'libraries/ServerStatusData.class.php';
12 if (PMA_DRIZZLE) {
13 $server_master_status = false;
14 $server_slave_status = false;
15 } else {
16 include_once 'libraries/replication.inc.php';
17 include_once 'libraries/replication_gui.lib.php';
20 $ServerStatusData = new PMA_ServerStatusData();
22 $response = PMA_Response::getInstance();
23 $header = $response->getHeader();
24 $scripts = $header->getScripts();
25 $scripts->addFile('server_status_queries.js');
26 /* < IE 9 doesn't support canvas natively */
27 if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
28 $scripts->addFile('jqplot/excanvas.js');
31 // for charting
32 $scripts->addFile('jqplot/jquery.jqplot.js');
33 $scripts->addFile('jqplot/plugins/jqplot.pieRenderer.js');
34 $scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
35 $scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
36 $scripts->addFile('jqplot/plugins/jqplot.dateAxisRenderer.js');
37 $scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
38 $scripts->addFile('jqplot/plugins/jqplot.cursor.js');
39 $scripts->addFile('jquery/jquery.tablesorter.js');
40 $scripts->addFile('server_status_sorter.js');
42 // Add the html content to the response
43 $response->addHTML('<div>');
44 $response->addHTML($ServerStatusData->getMenuHtml());
45 $response->addHTML(getQueryStatisticsHtml($ServerStatusData));
46 $response->addHTML('</div>');
47 exit;
49 /**
50 * Returns the html content for the query statistics
52 * @param object $ServerStatusData An instance of the PMA_ServerStatusData class
54 * @return string
56 function getQueryStatisticsHtml($ServerStatusData)
58 $retval = '';
60 $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
61 $used_queries = $ServerStatusData->used_queries;
62 $total_queries = array_sum($used_queries);
64 $retval .= '<h3 id="serverstatusqueries">';
65 /* l10n: Questions is the name of a MySQL Status variable */
66 $retval .= sprintf(
67 __('Questions since startup: %s'),
68 PMA_Util::formatNumber($total_queries, 0)
70 $retval .= ' ';
71 $retval .= PMA_Util::showMySQLDocu(
72 'server-status-variables',
73 'server-status-variables',
74 false,
75 'statvar_Questions'
77 $retval .= '<br />';
78 $retval .= '<span>';
79 $retval .= '&oslash; ' . __('per hour:') . ' ';
80 $retval .= PMA_Util::formatNumber($total_queries * $hour_factor, 0);
81 $retval .= '<br />';
82 $retval .= '&oslash; ' . __('per minute:') . ' ';
83 $retval .= PMA_Util::formatNumber($total_queries * 60 / $ServerStatusData->status['Uptime'], 0);
84 $retval .= '<br />';
85 if ($total_queries / $ServerStatusData->status['Uptime'] >= 1) {
86 $retval .= '&oslash; ' . __('per second:') . ' ';
87 $retval .= PMA_Util::formatNumber($total_queries / $ServerStatusData->status['Uptime'], 0);
89 $retval .= '</span>';
90 $retval .= '</h3>';
92 $retval .= getServerStatusQueriesDetailsHtml($ServerStatusData);
94 return $retval;
97 /**
98 * Returns the html content for the query details
100 * @param object $ServerStatusData An instance of the PMA_ServerStatusData class
102 * @return string
104 function getServerStatusQueriesDetailsHtml($ServerStatusData)
106 $used_queries = $ServerStatusData->used_queries;
107 $total_queries = array_sum($used_queries);
108 // reverse sort by value to show most used statements first
109 arsort($used_queries);
111 $odd_row = true;
112 $perc_factor = 100 / $total_queries; //(- $ServerStatusData->status['Connections']);
114 $retval = '<table id="serverstatusqueriesdetails" class="data sortable noclick">';
115 $retval .= '<col class="namecol" />';
116 $retval .= '<col class="valuecol" span="3" />';
117 $retval .= '<thead>';
118 $retval .= '<tr><th>' . __('Statements') . '</th>';
119 $retval .= '<th>';
120 /* l10n: # = Amount of queries */
121 $retval .= __('#');
122 $retval .= '</th>';
123 $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
124 $retval .= '<th>%</th>';
125 $retval .= '</tr>';
126 $retval .= '</thead>';
127 $retval .= '<tbody>';
129 $chart_json = array();
130 $query_sum = array_sum($used_queries);
131 $other_sum = 0;
132 foreach ($used_queries as $name => $value) {
133 $odd_row = !$odd_row;
134 // For the percentage column, use Questions - Connections, because
135 // the number of connections is not an item of the Query types
136 // but is included in Questions. Then the total of the percentages is 100.
137 $name = str_replace(array('Com_', '_'), array('', ' '), $name);
138 // Group together values that make out less than 2% into "Other", but only
139 // if we have more than 6 fractions already
140 if ($value < $query_sum * 0.02 && count($chart_json)>6) {
141 $other_sum += $value;
142 } else {
143 $chart_json[$name] = $value;
145 $retval .= '<tr class="';
146 $retval .= $odd_row ? 'odd' : 'even';
147 $retval .= '">';
148 $retval .= '<th class="name">' . htmlspecialchars($name) . '</th>';
149 $retval .= '<td class="value">';
150 $retval .= htmlspecialchars(PMA_Util::formatNumber($value, 5, 0, true));
151 $retval .= '</td>';
152 $retval .= '<td class="value">';
153 $retval .= htmlspecialchars(
154 PMA_Util::formatNumber($value * $hour_factor, 4, 1, true)
156 $retval .= '</td>';
157 $retval .= '<td class="value">';
158 $retval .= htmlspecialchars(
159 PMA_Util::formatNumber($value * $perc_factor, 0, 2)
161 $retval .= '</td>';
162 $retval .= '</tr>';
164 $retval .= '</tbody>';
165 $retval .= '</table>';
167 $retval .= '<div id="serverstatusquerieschart"></div>';
168 $retval .= '<div id="serverstatusquerieschart_data" style="display:none;">';
169 if ($other_sum > 0) {
170 $chart_json[__('Other')] = $other_sum;
172 $retval .= htmlspecialchars(json_encode($chart_json));
173 $retval .= '</div>';
175 return $retval;