Skip to content

Commit 71fcb2f

Browse files
committed
refactor server_status_queries.php: 1. move functions to lib file
1 parent 1d2f4a5 commit 71fcb2f

2 files changed

Lines changed: 148 additions & 131 deletions

File tree

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?php
2+
/* vim: set expandtab sw=4 ts=4 sts=4: */
3+
4+
/**
5+
* functions for displaying query statistics for the server
6+
*
7+
* @usedby server_status_queries.php
8+
*
9+
* @package PhpMyAdmin
10+
*/
11+
if (! defined('PHPMYADMIN')) {
12+
exit;
13+
}
14+
15+
/**
16+
* Returns the html content for the query statistics
17+
*
18+
* @param object $ServerStatusData An instance of the PMA_ServerStatusData class
19+
*
20+
* @return string
21+
*/
22+
function PMA_getHtmlForQueryStatistics($ServerStatusData)
23+
{
24+
$retval = '';
25+
26+
$hour_factor = 3600 / $ServerStatusData->status['Uptime'];
27+
$used_queries = $ServerStatusData->used_queries;
28+
$total_queries = array_sum($used_queries);
29+
30+
$retval .= '<h3 id="serverstatusqueries">';
31+
/* l10n: Questions is the name of a MySQL Status variable */
32+
$retval .= sprintf(
33+
__('Questions since startup: %s'),
34+
PMA_Util::formatNumber($total_queries, 0)
35+
);
36+
$retval .= ' ';
37+
$retval .= PMA_Util::showMySQLDocu(
38+
'server-status-variables',
39+
'server-status-variables',
40+
false,
41+
'statvar_Questions'
42+
);
43+
$retval .= '<br />';
44+
$retval .= '<span>';
45+
$retval .= '&oslash; ' . __('per hour:') . ' ';
46+
$retval .= PMA_Util::formatNumber($total_queries * $hour_factor, 0);
47+
$retval .= '<br />';
48+
$retval .= '&oslash; ' . __('per minute:') . ' ';
49+
$retval .= PMA_Util::formatNumber($total_queries * 60 / $ServerStatusData->status['Uptime'], 0);
50+
$retval .= '<br />';
51+
if ($total_queries / $ServerStatusData->status['Uptime'] >= 1) {
52+
$retval .= '&oslash; ' . __('per second:') . ' ';
53+
$retval .= PMA_Util::formatNumber($total_queries / $ServerStatusData->status['Uptime'], 0);
54+
}
55+
$retval .= '</span>';
56+
$retval .= '</h3>';
57+
58+
$retval .= PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData);
59+
60+
return $retval;
61+
}
62+
63+
/**
64+
* Returns the html content for the query details
65+
*
66+
* @param object $ServerStatusData An instance of the PMA_ServerStatusData class
67+
*
68+
* @return string
69+
*/
70+
function PMA_getHtmlForServerStatusQueriesDetails($ServerStatusData)
71+
{
72+
$hour_factor = 3600 / $ServerStatusData->status['Uptime'];
73+
$used_queries = $ServerStatusData->used_queries;
74+
$total_queries = array_sum($used_queries);
75+
// reverse sort by value to show most used statements first
76+
arsort($used_queries);
77+
78+
$odd_row = true;
79+
$perc_factor = 100 / $total_queries; //(- $ServerStatusData->status['Connections']);
80+
81+
$retval = '<table id="serverstatusqueriesdetails" class="data sortable noclick">';
82+
$retval .= '<col class="namecol" />';
83+
$retval .= '<col class="valuecol" span="3" />';
84+
$retval .= '<thead>';
85+
$retval .= '<tr><th>' . __('Statements') . '</th>';
86+
$retval .= '<th>';
87+
/* l10n: # = Amount of queries */
88+
$retval .= __('#');
89+
$retval .= '</th>';
90+
$retval .= '<th>&oslash; ' . __('per hour') . '</th>';
91+
$retval .= '<th>%</th>';
92+
$retval .= '</tr>';
93+
$retval .= '</thead>';
94+
$retval .= '<tbody>';
95+
96+
$chart_json = array();
97+
$query_sum = array_sum($used_queries);
98+
$other_sum = 0;
99+
foreach ($used_queries as $name => $value) {
100+
$odd_row = !$odd_row;
101+
// For the percentage column, use Questions - Connections, because
102+
// the number of connections is not an item of the Query types
103+
// but is included in Questions. Then the total of the percentages is 100.
104+
$name = str_replace(array('Com_', '_'), array('', ' '), $name);
105+
// Group together values that make out less than 2% into "Other", but only
106+
// if we have more than 6 fractions already
107+
if ($value < $query_sum * 0.02 && count($chart_json)>6) {
108+
$other_sum += $value;
109+
} else {
110+
$chart_json[$name] = $value;
111+
}
112+
$retval .= '<tr class="';
113+
$retval .= $odd_row ? 'odd' : 'even';
114+
$retval .= '">';
115+
$retval .= '<th class="name">' . htmlspecialchars($name) . '</th>';
116+
$retval .= '<td class="value">';
117+
$retval .= htmlspecialchars(PMA_Util::formatNumber($value, 5, 0, true));
118+
$retval .= '</td>';
119+
$retval .= '<td class="value">';
120+
$retval .= htmlspecialchars(
121+
PMA_Util::formatNumber($value * $hour_factor, 4, 1, true)
122+
);
123+
$retval .= '</td>';
124+
$retval .= '<td class="value">';
125+
$retval .= htmlspecialchars(
126+
PMA_Util::formatNumber($value * $perc_factor, 0, 2)
127+
);
128+
$retval .= '</td>';
129+
$retval .= '</tr>';
130+
}
131+
$retval .= '</tbody>';
132+
$retval .= '</table>';
133+
134+
$retval .= '<div id="serverstatusquerieschart"></div>';
135+
$retval .= '<div id="serverstatusquerieschart_data" style="display:none;">';
136+
if ($other_sum > 0) {
137+
$chart_json[__('Other')] = $other_sum;
138+
}
139+
$retval .= htmlspecialchars(json_encode($chart_json));
140+
$retval .= '</div>';
141+
142+
return $retval;
143+
}
144+
145+
?>

server_status_queries.php

Lines changed: 3 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
require_once 'libraries/common.inc.php';
1010
require_once 'libraries/server_common.inc.php';
1111
require_once 'libraries/ServerStatusData.class.php';
12+
require_once 'libraries/server_status_queries.lib.php';
13+
1214
if (PMA_DRIZZLE) {
1315
$server_master_status = false;
1416
$server_slave_status = false;
@@ -42,138 +44,8 @@
4244
// Add the html content to the response
4345
$response->addHTML('<div>');
4446
$response->addHTML($ServerStatusData->getMenuHtml());
45-
$response->addHTML(PMA_getQueryStatisticsHtml($ServerStatusData));
47+
$response->addHTML(PMA_getHtmlForQueryStatistics($ServerStatusData));
4648
$response->addHTML('</div>');
4749
exit;
4850

49-
/**
50-
* Returns the html content for the query statistics
51-
*
52-
* @param object $ServerStatusData An instance of the PMA_ServerStatusData class
53-
*
54-
* @return string
55-
*/
56-
function PMA_getQueryStatisticsHtml($ServerStatusData)
57-
{
58-
$retval = '';
59-
60-
$hour_factor = 3600 / $ServerStatusData->status['Uptime'];
61-
$used_queries = $ServerStatusData->used_queries;
62-
$total_queries = array_sum($used_queries);
63-
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)
69-
);
70-
$retval .= ' ';
71-
$retval .= PMA_Util::showMySQLDocu(
72-
'server-status-variables',
73-
'server-status-variables',
74-
false,
75-
'statvar_Questions'
76-
);
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);
88-
}
89-
$retval .= '</span>';
90-
$retval .= '</h3>';
91-
92-
$retval .= PMA_getServerStatusQueriesDetailsHtml($ServerStatusData);
93-
94-
return $retval;
95-
}
96-
97-
/**
98-
* Returns the html content for the query details
99-
*
100-
* @param object $ServerStatusData An instance of the PMA_ServerStatusData class
101-
*
102-
* @return string
103-
*/
104-
function PMA_getServerStatusQueriesDetailsHtml($ServerStatusData)
105-
{
106-
$hour_factor = 3600 / $ServerStatusData->status['Uptime'];
107-
$used_queries = $ServerStatusData->used_queries;
108-
$total_queries = array_sum($used_queries);
109-
// reverse sort by value to show most used statements first
110-
arsort($used_queries);
111-
112-
$odd_row = true;
113-
$perc_factor = 100 / $total_queries; //(- $ServerStatusData->status['Connections']);
114-
115-
$retval = '<table id="serverstatusqueriesdetails" class="data sortable noclick">';
116-
$retval .= '<col class="namecol" />';
117-
$retval .= '<col class="valuecol" span="3" />';
118-
$retval .= '<thead>';
119-
$retval .= '<tr><th>' . __('Statements') . '</th>';
120-
$retval .= '<th>';
121-
/* l10n: # = Amount of queries */
122-
$retval .= __('#');
123-
$retval .= '</th>';
124-
$retval .= '<th>&oslash; ' . __('per hour') . '</th>';
125-
$retval .= '<th>%</th>';
126-
$retval .= '</tr>';
127-
$retval .= '</thead>';
128-
$retval .= '<tbody>';
129-
130-
$chart_json = array();
131-
$query_sum = array_sum($used_queries);
132-
$other_sum = 0;
133-
foreach ($used_queries as $name => $value) {
134-
$odd_row = !$odd_row;
135-
// For the percentage column, use Questions - Connections, because
136-
// the number of connections is not an item of the Query types
137-
// but is included in Questions. Then the total of the percentages is 100.
138-
$name = str_replace(array('Com_', '_'), array('', ' '), $name);
139-
// Group together values that make out less than 2% into "Other", but only
140-
// if we have more than 6 fractions already
141-
if ($value < $query_sum * 0.02 && count($chart_json)>6) {
142-
$other_sum += $value;
143-
} else {
144-
$chart_json[$name] = $value;
145-
}
146-
$retval .= '<tr class="';
147-
$retval .= $odd_row ? 'odd' : 'even';
148-
$retval .= '">';
149-
$retval .= '<th class="name">' . htmlspecialchars($name) . '</th>';
150-
$retval .= '<td class="value">';
151-
$retval .= htmlspecialchars(PMA_Util::formatNumber($value, 5, 0, true));
152-
$retval .= '</td>';
153-
$retval .= '<td class="value">';
154-
$retval .= htmlspecialchars(
155-
PMA_Util::formatNumber($value * $hour_factor, 4, 1, true)
156-
);
157-
$retval .= '</td>';
158-
$retval .= '<td class="value">';
159-
$retval .= htmlspecialchars(
160-
PMA_Util::formatNumber($value * $perc_factor, 0, 2)
161-
);
162-
$retval .= '</td>';
163-
$retval .= '</tr>';
164-
}
165-
$retval .= '</tbody>';
166-
$retval .= '</table>';
167-
168-
$retval .= '<div id="serverstatusquerieschart"></div>';
169-
$retval .= '<div id="serverstatusquerieschart_data" style="display:none;">';
170-
if ($other_sum > 0) {
171-
$chart_json[__('Other')] = $other_sum;
172-
}
173-
$retval .= htmlspecialchars(json_encode($chart_json));
174-
$retval .= '</div>';
175-
176-
return $retval;
177-
}
178-
17951
?>

0 commit comments

Comments
 (0)