1 |
aa280d10
|
Bill Marquette
|
<?php
|
2 |
|
|
/*
|
3 |
c5d81585
|
Renato Botelho
|
* status_queues.php
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
81299b5c
|
Renato Botelho
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7 |
c5d81585
|
Renato Botelho
|
* All rights reserved.
|
8 |
|
|
*
|
9 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
10 |
|
|
* you may not use this file except in compliance with the License.
|
11 |
|
|
* You may obtain a copy of the License at
|
12 |
c5d81585
|
Renato Botelho
|
*
|
13 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
14 |
c5d81585
|
Renato Botelho
|
*
|
15 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
16 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
17 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18 |
|
|
* See the License for the specific language governing permissions and
|
19 |
|
|
* limitations under the License.
|
20 |
39881492
|
Stephen Beaver
|
*/
|
21 |
aa280d10
|
Bill Marquette
|
|
22 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
23 |
|
|
##|*IDENT=page-status-trafficshaper-queues
|
24 |
48157a04
|
Phil Davis
|
##|*NAME=Status: Traffic Shaper: Queues
|
25 |
|
|
##|*DESCR=Allow access to the 'Status: Traffic Shaper: Queues' page.
|
26 |
6b07c15a
|
Matthew Grooms
|
##|*MATCH=status_queues.php*
|
27 |
|
|
##|-PRIV
|
28 |
39881492
|
Stephen Beaver
|
/*
|
29 |
42b0c921
|
Phil Davis
|
header("Last-Modified: " . gmdate("D, j M Y H:i:s") . " GMT");
|
30 |
|
|
header("Expires: " . gmdate("D, j M Y H:i:s", time()) . " GMT");
|
31 |
|
|
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP/1.1
|
32 |
5f471c95
|
Ermal
|
header("Pragma: no-cache"); // HTTP/1.0
|
33 |
39881492
|
Stephen Beaver
|
*/
|
34 |
5f471c95
|
Ermal
|
|
35 |
c81ef6e2
|
Phil Davis
|
require_once("guiconfig.inc");
|
36 |
21b94a54
|
Michele Di Maria
|
class QueueStats {
|
37 |
|
|
public $queuename;
|
38 |
2c5fda82
|
Jose Luis Duran
|
public $queuelength;
|
39 |
6ba3121b
|
Michele Di Maria
|
public $pps;
|
40 |
|
|
public $bandwidth;
|
41 |
21b94a54
|
Michele Di Maria
|
public $borrows;
|
42 |
|
|
public $suspends;
|
43 |
|
|
public $drops;
|
44 |
|
|
}
|
45 |
3a1e12cf
|
jim-p
|
if (!file_exists("{$g['varrun_path']}/qstats.pid") || !isvalidpid("{$g['varrun_path']}/qstats.pid")) {
|
46 |
9c1bbdef
|
Stephen Beaver
|
/* Start in the background so we don't hang up the GUI */
|
47 |
a3eab908
|
Michele Di Maria
|
mwexec_bg("/usr/local/sbin/qstats -p {$g['varrun_path']}/qstats.pid");
|
48 |
9c1bbdef
|
Stephen Beaver
|
/* Give it a moment to start up */
|
49 |
3a1e12cf
|
jim-p
|
sleep(1);
|
50 |
|
|
}
|
51 |
5f471c95
|
Ermal
|
$fd = @fsockopen("unix://{$g['varrun_path']}/qstats");
|
52 |
42b0c921
|
Phil Davis
|
if (!$fd) {
|
53 |
8545adde
|
k-paulius
|
$error = gettext("Something wrong happened during communication with stat gathering.");
|
54 |
3a1e12cf
|
jim-p
|
} else {
|
55 |
|
|
$stats = "";
|
56 |
6c07db48
|
Phil Davis
|
while (!feof($fd)) {
|
57 |
3a1e12cf
|
jim-p
|
$stats .= fread($fd, 4096);
|
58 |
42b0c921
|
Phil Davis
|
}
|
59 |
3a1e12cf
|
jim-p
|
fclose($fd);
|
60 |
|
|
@file_put_contents("{$g['tmp_path']}/qstats", $stats);
|
61 |
|
|
$altqstats = @parse_xml_config("{$g['tmp_path']}/qstats", array("altqstats"));
|
62 |
42b0c921
|
Phil Davis
|
if ($altqstats == -1) {
|
63 |
3bd74348
|
bruno
|
$error = gettext("No queue statistics could be read.");
|
64 |
42b0c921
|
Phil Davis
|
}
|
65 |
5f471c95
|
Ermal
|
}
|
66 |
2c5fda82
|
Jose Luis Duran
|
if ($_REQUEST['getactivity']) {
|
67 |
21b94a54
|
Michele Di Maria
|
$statistics = array();
|
68 |
87428ee8
|
Michele Di Maria
|
$bigger_stat = 0;
|
69 |
|
|
$stat_type = $_REQUEST['stats'];
|
70 |
9c1bbdef
|
Stephen Beaver
|
/* build the queue stats. */
|
71 |
42b0c921
|
Phil Davis
|
foreach ($altqstats['queue'] as $q) {
|
72 |
21b94a54
|
Michele Di Maria
|
statsQueues($q);
|
73 |
|
|
}
|
74 |
9c1bbdef
|
Stephen Beaver
|
/* calculate the bigger amount of packets or bandwidth being moved through all queues. */
|
75 |
6c07db48
|
Phil Davis
|
if ($stat_type == "0") {
|
76 |
42b0c921
|
Phil Davis
|
foreach ($statistics as $q) {
|
77 |
|
|
if ($bigger_stat < $q->pps) {
|
78 |
87428ee8
|
Michele Di Maria
|
$bigger_stat = $q->pps;
|
79 |
42b0c921
|
Phil Davis
|
}
|
80 |
87428ee8
|
Michele Di Maria
|
}
|
81 |
6c07db48
|
Phil Davis
|
} else {
|
82 |
42b0c921
|
Phil Davis
|
foreach ($statistics as $q) {
|
83 |
|
|
if ($bigger_stat < $q->bandwidth) {
|
84 |
87428ee8
|
Michele Di Maria
|
$bigger_stat = $q->bandwidth;
|
85 |
42b0c921
|
Phil Davis
|
}
|
86 |
87428ee8
|
Michele Di Maria
|
}
|
87 |
2c5fda82
|
Jose Luis Duran
|
}
|
88 |
f2b8daad
|
Ermal Lu?i
|
$finscript = "";
|
89 |
42b0c921
|
Phil Davis
|
foreach ($statistics as $q) {
|
90 |
88377787
|
Chris Buechler
|
if ($stat_type == "0" && $bigger_stat != "0") {
|
91 |
9f605c1c
|
Hari
|
$packet_s = round(100 * ($q->pps / $bigger_stat), 0);
|
92 |
88377787
|
Chris Buechler
|
} else if ($bigger_stat != "0") {
|
93 |
9f605c1c
|
Hari
|
$packet_s = round(100 * ($q->bandwidth / $bigger_stat), 0);
|
94 |
6f069e92
|
Chris Buechler
|
} else {
|
95 |
42b0c921
|
Phil Davis
|
$packet_s = 0;
|
96 |
|
|
}
|
97 |
3f98044a
|
Francisco Cavalcante
|
$finscript .= "$('#queue{$q->queuename}width').css('width','{$packet_s}%');";
|
98 |
|
|
$finscript .= "$('#queue{$q->queuename}pps').val('" . number_format($q->pps, 1) . "');";
|
99 |
|
|
$finscript .= "$('#queue{$q->queuename}bps').val('" . format_bits($q->bandwidth) . "');";
|
100 |
|
|
$finscript .= "$('#queue{$q->queuename}borrows').val('{$q->borrows}');";
|
101 |
|
|
$finscript .= "$('#queue{$q->queuename}suspends').val('{$q->suspends}');";
|
102 |
|
|
$finscript .= "$('#queue{$q->queuename}drops').val('{$q->drops}');";
|
103 |
|
|
$finscript .= "$('#queue{$q->queuename}length').val('{$q->queuelength}');";
|
104 |
21b94a54
|
Michele Di Maria
|
}
|
105 |
b06abfe3
|
Michele Di Maria
|
unset($statistics, $altqstats);
|
106 |
9c1bbdef
|
Stephen Beaver
|
header("Content-type: text/javascript");
|
107 |
f2b8daad
|
Ermal Lu?i
|
echo $finscript;
|
108 |
c5d63426
|
Bill Marquette
|
exit;
|
109 |
|
|
}
|
110 |
f4741421
|
k-paulius
|
$pgtitle = array(gettext("Status"), gettext("Queues"));
|
111 |
9c1bbdef
|
Stephen Beaver
|
$shortcut_section = "trafficshaper";
|
112 |
|
|
include("head.inc");
|
113 |
625c4a8b
|
Stephen Beaver
|
|
114 |
9c1bbdef
|
Stephen Beaver
|
if (!is_array($config['shaper']['queue']) || count($config['shaper']['queue']) < 1) {
|
115 |
|
|
print_info_box(gettext("Traffic shaping is not configured."));
|
116 |
|
|
include("foot.inc");
|
117 |
|
|
exit;
|
118 |
|
|
}
|
119 |
625c4a8b
|
Stephen Beaver
|
|
120 |
|
|
if (!$error): ?>
|
121 |
9c1bbdef
|
Stephen Beaver
|
<form action="status_queues.php" method="post">
|
122 |
|
|
<script type="text/javascript">
|
123 |
|
|
//<![CDATA[
|
124 |
625c4a8b
|
Stephen Beaver
|
events.push(function() {
|
125 |
|
|
|
126 |
9c1bbdef
|
Stephen Beaver
|
function getqueueactivity() {
|
127 |
|
|
var url = "/status_queues.php";
|
128 |
3f98044a
|
Francisco Cavalcante
|
var pars = "getactivity=yes&stats=" + $("#selStatistic").val();
|
129 |
|
|
$.ajax(
|
130 |
9c1bbdef
|
Stephen Beaver
|
url,
|
131 |
|
|
{
|
132 |
|
|
type: 'post',
|
133 |
|
|
data: pars,
|
134 |
|
|
complete: activitycallback
|
135 |
|
|
});
|
136 |
|
|
}
|
137 |
625c4a8b
|
Stephen Beaver
|
|
138 |
9c1bbdef
|
Stephen Beaver
|
function activitycallback(transport) {
|
139 |
625c4a8b
|
Stephen Beaver
|
setTimeout(getqueueactivity, 5100);
|
140 |
9c1bbdef
|
Stephen Beaver
|
}
|
141 |
625c4a8b
|
Stephen Beaver
|
|
142 |
3f98044a
|
Francisco Cavalcante
|
$(document).ready(function() {
|
143 |
625c4a8b
|
Stephen Beaver
|
setTimeout(getqueueactivity, 150);
|
144 |
9c1bbdef
|
Stephen Beaver
|
});
|
145 |
625c4a8b
|
Stephen Beaver
|
});
|
146 |
9c1bbdef
|
Stephen Beaver
|
//]]>
|
147 |
|
|
</script>
|
148 |
|
|
<?php endif;
|
149 |
|
|
|
150 |
|
|
if ($error):
|
151 |
|
|
print_info_box($error);
|
152 |
|
|
else: ?>
|
153 |
|
|
<div class="panel panel-default">
|
154 |
|
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Status Queues"); ?></h2></div>
|
155 |
|
|
<div class="panel-body table-responsive">
|
156 |
|
|
<table class="table table-striped table-hover">
|
157 |
|
|
<thead>
|
158 |
|
|
<tr>
|
159 |
|
|
<th><?=gettext("Queue"); ?></th>
|
160 |
|
|
<th><?=gettext("Statistics"); ?>
|
161 |
e9feb2d4
|
Stephen Beaver
|
<select id="selStatistic" class="form-control">
|
162 |
3bd74348
|
bruno
|
<option value="0"><?=gettext("PPS");?></option>
|
163 |
|
|
<option value="1"><?=gettext("Bandwidth");?></option>
|
164 |
9c1bbdef
|
Stephen Beaver
|
</select>
|
165 |
|
|
</th>
|
166 |
|
|
<th><?=gettext("PPS"); ?></th>
|
167 |
|
|
<th><?=gettext("Bandwidth"); ?></th>
|
168 |
|
|
<th><?=gettext("Borrows"); ?></th>
|
169 |
|
|
<th><?=gettext("Suspends"); ?></th>
|
170 |
|
|
<th><?=gettext("Drops"); ?></th>
|
171 |
|
|
<th><?=gettext("Length"); ?></th>
|
172 |
|
|
</tr>
|
173 |
|
|
</thead>
|
174 |
|
|
<tbody>
|
175 |
|
|
<?php
|
176 |
|
|
$if_queue_list = get_configured_interface_list_by_realif(false, true);
|
177 |
|
|
processQueues($altqstats, 0, "");
|
178 |
|
|
?>
|
179 |
|
|
<?php endif; ?>
|
180 |
|
|
</tbody>
|
181 |
|
|
</table>
|
182 |
f78bbe16
|
Phil Davis
|
<br />
|
183 |
c95dabdd
|
Stephen Beaver
|
<div class="infoblock blockopen">
|
184 |
9c1bbdef
|
Stephen Beaver
|
<?php
|
185 |
8545adde
|
k-paulius
|
print_info_box(gettext("Queue graphs take 5 seconds to sample data."), 'info', false);
|
186 |
9c1bbdef
|
Stephen Beaver
|
?>
|
187 |
f78bbe16
|
Phil Davis
|
</div>
|
188 |
9c1bbdef
|
Stephen Beaver
|
</div>
|
189 |
|
|
</div>
|
190 |
9cad1b8e
|
Colin Fleming
|
<br/>
|
191 |
9c1bbdef
|
Stephen Beaver
|
|
192 |
|
|
<script type="text/javascript">
|
193 |
|
|
//<![CDATA[
|
194 |
|
|
function StatsShowHide(classname) {
|
195 |
3f98044a
|
Francisco Cavalcante
|
var firstrow = $("." + classname).first();
|
196 |
9c1bbdef
|
Stephen Beaver
|
if (firstrow.is(':visible')) {
|
197 |
3f98044a
|
Francisco Cavalcante
|
$("." + classname).hide();
|
198 |
9c1bbdef
|
Stephen Beaver
|
} else {
|
199 |
3f98044a
|
Francisco Cavalcante
|
$("." + classname).show();
|
200 |
9c1bbdef
|
Stephen Beaver
|
}
|
201 |
|
|
}
|
202 |
|
|
//]]>
|
203 |
|
|
</script>
|
204 |
|
|
</form>
|
205 |
|
|
<?php
|
206 |
|
|
|
207 |
|
|
include("foot.inc");
|
208 |
9f605c1c
|
Hari
|
|
209 |
42b0c921
|
Phil Davis
|
function processQueues($altqstats, $level, $parent_name) {
|
210 |
21b94a54
|
Michele Di Maria
|
global $g;
|
211 |
6ba3121b
|
Michele Di Maria
|
global $if_queue_list;
|
212 |
ebfbb1b3
|
Stephen Beaver
|
|
213 |
ff3003df
|
Michele Di Maria
|
$parent_name = $parent_name . " queuerow" . $altqstats['name'] . $altqstats['interface'];
|
214 |
1679b68c
|
Michele Di Maria
|
$prev_if = $altqstats['interface'];
|
215 |
6ba3121b
|
Michele Di Maria
|
foreach ($altqstats['queue'] as $q) {
|
216 |
|
|
$if_name = "";
|
217 |
1679b68c
|
Michele Di Maria
|
foreach ($if_queue_list as $oif => $real_name) {
|
218 |
|
|
if ($oif == $q['interface']) {
|
219 |
6ba3121b
|
Michele Di Maria
|
$if_name = $real_name;
|
220 |
|
|
break;
|
221 |
|
|
}
|
222 |
|
|
}
|
223 |
1679b68c
|
Michele Di Maria
|
if ($prev_if != $q['interface']) {
|
224 |
9cad1b8e
|
Colin Fleming
|
echo "<tr><td colspan=\"8\"><b>Interface " . htmlspecialchars(convert_real_interface_to_friendly_descr($q['interface'])) . "</b></td></tr>\n";
|
225 |
1679b68c
|
Michele Di Maria
|
$prev_if = $q['interface'];
|
226 |
|
|
}
|
227 |
42b0c921
|
Phil Davis
|
?>
|
228 |
5c0ab3cd
|
NewEraCracker
|
<tr class="<?=$parent_name;?>">
|
229 |
ebfbb1b3
|
Stephen Beaver
|
<td class="<?=$row_class?>" style="padding-left:<?=$level * 20?>px;">
|
230 |
9cad1b8e
|
Colin Fleming
|
<?php
|
231 |
|
|
if (is_array($q['queue'])) {
|
232 |
|
|
echo "<a href=\"#\" onclick=\"StatsShowHide('queuerow{$q['name']}{$q['interface']}');return false\">+/-</a>";
|
233 |
|
|
}
|
234 |
|
|
if (strstr($q['name'], "root_")) {
|
235 |
|
|
echo "<a href=\"firewall_shaper.php?interface={$if_name}&queue={$if_name}&action=show\">Root queue</a>";
|
236 |
|
|
} else {
|
237 |
|
|
echo "<a href=\"firewall_shaper.php?interface={$if_name}&queue={$q['name']}&action=show\">" . htmlspecialchars($q['name']) . "</a>";
|
238 |
|
|
}
|
239 |
|
|
?>
|
240 |
ff3003df
|
Michele Di Maria
|
</td>
|
241 |
42b0c921
|
Phil Davis
|
<?php
|
242 |
|
|
$cpuUsage = 0;
|
243 |
6c961924
|
Stephen Beaver
|
print('<td>');
|
244 |
ebfbb1b3
|
Stephen Beaver
|
print('<div class="progress" style="height: 7px;width: 170px;">');
|
245 |
c69a1a74
|
doktornotor
|
print(' <div class="progress-bar" role="progressbar" id="queue' . $q['name'] . $q['interface'] . 'width" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width: ' . $cpuUsage*100 . '%;"></div>');
|
246 |
ebfbb1b3
|
Stephen Beaver
|
print(' </div>');
|
247 |
|
|
print('</td>');
|
248 |
6c961924
|
Stephen Beaver
|
print('<td><input readonly style="border:0;width:70px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'pps" id="queue' . $q['name'] . $q['interface'] . 'pps" value="(' . gettext("Loading") . ')" /></td>');
|
249 |
|
|
print('<td><input readonly style="border:0;width:80px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'bps" id="queue' . $q['name'] . $q['interface'] . 'bps" value="" /></td>');
|
250 |
|
|
print('<td><input readonly style="border:0;width:70px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'borrows" id="queue' . $q['name'] . $q['interface'] . 'borrows" value="" /></td>');
|
251 |
|
|
print('<td><input readonly style="border:0;width:70px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'suspends" id="queue' . $q['name'] . $q['interface'] . 'suspends" value="" /></td>');
|
252 |
|
|
print('<td><input readonly style="border:0;width:70px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'drops" id="queue' . $q['name'] . $q['interface'] . 'drops" value="" /></td>');
|
253 |
|
|
print('<td><input readonly style="border:0;width:70px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'length" id="queue' . $q['name'] . $q['interface'] . 'length" value="" /></td>');
|
254 |
42b0c921
|
Phil Davis
|
?>
|
255 |
21b94a54
|
Michele Di Maria
|
</tr>
|
256 |
42b0c921
|
Phil Davis
|
<?php
|
257 |
|
|
if (is_array($q['queue'])) {
|
258 |
ff3003df
|
Michele Di Maria
|
processQueues($q, $level + 1, $parent_name);
|
259 |
42b0c921
|
Phil Davis
|
}
|
260 |
9c1bbdef
|
Stephen Beaver
|
};
|
261 |
21b94a54
|
Michele Di Maria
|
}
|
262 |
39881492
|
Stephen Beaver
|
|
263 |
42b0c921
|
Phil Davis
|
function statsQueues($xml) {
|
264 |
21b94a54
|
Michele Di Maria
|
global $statistics;
|
265 |
b06abfe3
|
Michele Di Maria
|
|
266 |
21b94a54
|
Michele Di Maria
|
$current = new QueueStats();
|
267 |
|
|
$child = new QueueStats();
|
268 |
|
|
$current->queuename = $xml['name'] . $xml['interface'];
|
269 |
2c5fda82
|
Jose Luis Duran
|
$current->queuelength = $xml['qlength'];
|
270 |
ff3003df
|
Michele Di Maria
|
$current->pps = $xml['measured'];
|
271 |
|
|
$current->bandwidth = $xml['measuredspeedint'];
|
272 |
21b94a54
|
Michele Di Maria
|
$current->borrows = intval($xml['borrows']);
|
273 |
|
|
$current->suspends = intval($xml['suspends']);
|
274 |
8e006931
|
Michele Di Maria
|
$current->drops = intval($xml['droppedpkts']);
|
275 |
1679b68c
|
Michele Di Maria
|
if (is_array($xml['queue'])) {
|
276 |
42b0c921
|
Phil Davis
|
foreach ($xml['queue'] as $q) {
|
277 |
21b94a54
|
Michele Di Maria
|
$child = statsQueues($q);
|
278 |
|
|
$current->pps += $child->pps;
|
279 |
|
|
$current->bandwidth += $child->bandwidth;
|
280 |
|
|
$current->borrows += $child->borrows;
|
281 |
|
|
$current->suspends += $child->suspends;
|
282 |
|
|
$current->drops += $child->drops;
|
283 |
|
|
}
|
284 |
|
|
}
|
285 |
a3eab908
|
Michele Di Maria
|
unset($child);
|
286 |
21b94a54
|
Michele Di Maria
|
$statistics[] = $current;
|
287 |
|
|
return $current;
|
288 |
|
|
}
|
289 |
b06abfe3
|
Michele Di Maria
|
function format_bits($bits) {
|
290 |
|
|
if ($bits >= 1000000000) {
|
291 |
|
|
return sprintf("%.2f Gbps", $bits/1000000000);
|
292 |
|
|
} else if ($bits >= 1000000) {
|
293 |
|
|
return sprintf("%.2f Mbps", $bits/1000000);
|
294 |
|
|
} else if ($bits >= 1000) {
|
295 |
31e41cf4
|
Michele Di Maria
|
return sprintf("%.2f Kbps", $bits/1000);
|
296 |
b06abfe3
|
Michele Di Maria
|
} else {
|
297 |
31e41cf4
|
Michele Di Maria
|
return sprintf("%d bps", $bits);
|
298 |
b06abfe3
|
Michele Di Maria
|
}
|
299 |
|
|
}
|
300 |
39881492
|
Stephen Beaver
|
?>
|