1
|
<?php
|
2
|
/*
|
3
|
status_queues.php
|
4
|
*/
|
5
|
/* ====================================================================
|
6
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
*
|
8
|
* Redistribution and use in source and binary forms, with or without modification,
|
9
|
* are permitted provided that the following conditions are met:
|
10
|
*
|
11
|
* 1. Redistributions of source code must retain the above copyright notice,
|
12
|
* this list of conditions and the following disclaimer.
|
13
|
*
|
14
|
* 2. Redistributions in binary form must reproduce the above copyright
|
15
|
* notice, this list of conditions and the following disclaimer in
|
16
|
* the documentation and/or other materials provided with the
|
17
|
* distribution.
|
18
|
*
|
19
|
* 3. All advertising materials mentioning features or use of this software
|
20
|
* must display the following acknowledgment:
|
21
|
* "This product includes software developed by the pfSense Project
|
22
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
23
|
*
|
24
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
25
|
* endorse or promote products derived from this software without
|
26
|
* prior written permission. For written permission, please contact
|
27
|
* coreteam@pfsense.org.
|
28
|
*
|
29
|
* 5. Products derived from this software may not be called "pfSense"
|
30
|
* nor may "pfSense" appear in their names without prior written
|
31
|
* permission of the Electric Sheep Fencing, LLC.
|
32
|
*
|
33
|
* 6. Redistributions of any form whatsoever must retain the following
|
34
|
* acknowledgment:
|
35
|
*
|
36
|
* "This product includes software developed by the pfSense Project
|
37
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
38
|
*
|
39
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
40
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
41
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
42
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
43
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
44
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
45
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
46
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
47
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
48
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
49
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
50
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
51
|
*
|
52
|
* ====================================================================
|
53
|
*
|
54
|
*/
|
55
|
|
56
|
##|+PRIV
|
57
|
##|*IDENT=page-status-trafficshaper-queues
|
58
|
##|*NAME=Status: Traffic shaper: Queues
|
59
|
##|*DESCR=Allow access to the 'Status: Traffic shaper: Queues' page.
|
60
|
##|*MATCH=status_queues.php*
|
61
|
##|-PRIV
|
62
|
/*
|
63
|
header("Last-Modified: " . gmdate("D, j M Y H:i:s") . " GMT");
|
64
|
header("Expires: " . gmdate("D, j M Y H:i:s", time()) . " GMT");
|
65
|
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP/1.1
|
66
|
header("Pragma: no-cache"); // HTTP/1.0
|
67
|
*/
|
68
|
|
69
|
require("guiconfig.inc");
|
70
|
class QueueStats {
|
71
|
public $queuename;
|
72
|
public $queuelength;
|
73
|
public $pps;
|
74
|
public $bandwidth;
|
75
|
public $borrows;
|
76
|
public $suspends;
|
77
|
public $drops;
|
78
|
}
|
79
|
if (!file_exists("{$g['varrun_path']}/qstats.pid") || !isvalidpid("{$g['varrun_path']}/qstats.pid")) {
|
80
|
/* Start in the background so we don't hang up the GUI */
|
81
|
mwexec_bg("/usr/local/sbin/qstats -p {$g['varrun_path']}/qstats.pid");
|
82
|
/* Give it a moment to start up */
|
83
|
sleep(1);
|
84
|
}
|
85
|
$fd = @fsockopen("unix://{$g['varrun_path']}/qstats");
|
86
|
if (!$fd) {
|
87
|
$error = gettext("Something wrong happened during communication with stat gathering");
|
88
|
} else {
|
89
|
$stats = "";
|
90
|
while (!feof($fd)) {
|
91
|
$stats .= fread($fd, 4096);
|
92
|
}
|
93
|
fclose($fd);
|
94
|
@file_put_contents("{$g['tmp_path']}/qstats", $stats);
|
95
|
$altqstats = @parse_xml_config("{$g['tmp_path']}/qstats", array("altqstats"));
|
96
|
if ($altqstats == -1) {
|
97
|
$error = gettext("No queue statistics could be read.");
|
98
|
}
|
99
|
}
|
100
|
if ($_REQUEST['getactivity']) {
|
101
|
$statistics = array();
|
102
|
$bigger_stat = 0;
|
103
|
$stat_type = $_REQUEST['stats'];
|
104
|
/* build the queue stats. */
|
105
|
foreach ($altqstats['queue'] as $q) {
|
106
|
statsQueues($q);
|
107
|
}
|
108
|
/* calculate the bigger amount of packets or bandwidth being moved through all queues. */
|
109
|
if ($stat_type == "0") {
|
110
|
foreach ($statistics as $q) {
|
111
|
if ($bigger_stat < $q->pps) {
|
112
|
$bigger_stat = $q->pps;
|
113
|
}
|
114
|
}
|
115
|
} else {
|
116
|
foreach ($statistics as $q) {
|
117
|
if ($bigger_stat < $q->bandwidth) {
|
118
|
$bigger_stat = $q->bandwidth;
|
119
|
}
|
120
|
}
|
121
|
}
|
122
|
$finscript = "";
|
123
|
foreach ($statistics as $q) {
|
124
|
if ($stat_type == "0") {
|
125
|
$packet_s = round(100 * ($q->pps / $bigger_stat), 0);
|
126
|
} else {
|
127
|
$packet_s = round(100 * ($q->bandwidth / $bigger_stat), 0);
|
128
|
}
|
129
|
if ($packet_s < 0) {
|
130
|
$packet_s = 0;
|
131
|
}
|
132
|
$finscript .= "$('#queue{$q->queuename}width').css('width','{$packet_s}%');";
|
133
|
$finscript .= "$('#queue{$q->queuename}pps').val('" . number_format($q->pps, 1) . "');";
|
134
|
$finscript .= "$('#queue{$q->queuename}bps').val('" . format_bits($q->bandwidth) . "');";
|
135
|
$finscript .= "$('#queue{$q->queuename}borrows').val('{$q->borrows}');";
|
136
|
$finscript .= "$('#queue{$q->queuename}suspends').val('{$q->suspends}');";
|
137
|
$finscript .= "$('#queue{$q->queuename}drops').val('{$q->drops}');";
|
138
|
$finscript .= "$('#queue{$q->queuename}length').val('{$q->queuelength}');";
|
139
|
}
|
140
|
unset($statistics, $altqstats);
|
141
|
header("Content-type: text/javascript");
|
142
|
echo $finscript;
|
143
|
exit;
|
144
|
}
|
145
|
$pgtitle = array(gettext("Status"), gettext("Traffic shaper"), gettext("Queues"));
|
146
|
$shortcut_section = "trafficshaper";
|
147
|
include("head.inc");
|
148
|
?>
|
149
|
<script src="/jquery/jquery-1.11.2.min.js"></script>
|
150
|
<?php
|
151
|
if (!is_array($config['shaper']['queue']) || count($config['shaper']['queue']) < 1) {
|
152
|
print_info_box(gettext("Traffic shaping is not configured."));
|
153
|
include("foot.inc");
|
154
|
exit;
|
155
|
}
|
156
|
?>
|
157
|
<?php if (!$error): ?>
|
158
|
<form action="status_queues.php" method="post">
|
159
|
<script type="text/javascript">
|
160
|
//<![CDATA[
|
161
|
function getqueueactivity() {
|
162
|
var url = "/status_queues.php";
|
163
|
var pars = "getactivity=yes&stats=" + $("#selStatistic").val();
|
164
|
$.ajax(
|
165
|
url,
|
166
|
{
|
167
|
type: 'post',
|
168
|
data: pars,
|
169
|
complete: activitycallback
|
170
|
});
|
171
|
}
|
172
|
function activitycallback(transport) {
|
173
|
setTimeout('getqueueactivity()', 5100);
|
174
|
}
|
175
|
$(document).ready(function() {
|
176
|
setTimeout('getqueueactivity()', 150);
|
177
|
});
|
178
|
//]]>
|
179
|
</script>
|
180
|
<?php endif;
|
181
|
|
182
|
if ($error):
|
183
|
print_info_box($error);
|
184
|
else: ?>
|
185
|
<div class="panel panel-default">
|
186
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Status Queues"); ?></h2></div>
|
187
|
<div class="panel-body table-responsive">
|
188
|
<table class="table table-striped table-hover">
|
189
|
<thead>
|
190
|
<tr>
|
191
|
<th><?=gettext("Queue"); ?></th>
|
192
|
<th><?=gettext("Statistics"); ?>
|
193
|
<select id="selStatistic" class="form-control">
|
194
|
<option value="0"><?=gettext("PPS");?></option>
|
195
|
<option value="1"><?=gettext("Bandwidth");?></option>
|
196
|
</select>
|
197
|
</th>
|
198
|
<th><?=gettext("PPS"); ?></th>
|
199
|
<th><?=gettext("Bandwidth"); ?></th>
|
200
|
<th><?=gettext("Borrows"); ?></th>
|
201
|
<th><?=gettext("Suspends"); ?></th>
|
202
|
<th><?=gettext("Drops"); ?></th>
|
203
|
<th><?=gettext("Length"); ?></th>
|
204
|
</tr>
|
205
|
</thead>
|
206
|
<tbody>
|
207
|
<?php
|
208
|
$if_queue_list = get_configured_interface_list_by_realif(false, true);
|
209
|
processQueues($altqstats, 0, "");
|
210
|
?>
|
211
|
<?php endif; ?>
|
212
|
</tbody>
|
213
|
</table>
|
214
|
<br />
|
215
|
<div class="infoblock blockopen">
|
216
|
<?php
|
217
|
print_info_box(gettext("Queue graphs take 5 seconds to sample data"), 'info', false);
|
218
|
?>
|
219
|
</div>
|
220
|
</div>
|
221
|
</div>
|
222
|
<br/>
|
223
|
|
224
|
<script type="text/javascript">
|
225
|
//<![CDATA[
|
226
|
function StatsShowHide(classname) {
|
227
|
var firstrow = $("." + classname).first();
|
228
|
if (firstrow.is(':visible')) {
|
229
|
$("." + classname).hide();
|
230
|
} else {
|
231
|
$("." + classname).show();
|
232
|
}
|
233
|
}
|
234
|
//]]>
|
235
|
</script>
|
236
|
</form>
|
237
|
<?php
|
238
|
|
239
|
include("foot.inc");
|
240
|
|
241
|
function processQueues($altqstats, $level, $parent_name) {
|
242
|
global $g;
|
243
|
global $if_queue_list;
|
244
|
|
245
|
$parent_name = $parent_name . " queuerow" . $altqstats['name'] . $altqstats['interface'];
|
246
|
$prev_if = $altqstats['interface'];
|
247
|
foreach ($altqstats['queue'] as $q) {
|
248
|
$if_name = "";
|
249
|
foreach ($if_queue_list as $oif => $real_name) {
|
250
|
if ($oif == $q['interface']) {
|
251
|
$if_name = $real_name;
|
252
|
break;
|
253
|
}
|
254
|
}
|
255
|
if ($prev_if != $q['interface']) {
|
256
|
echo "<tr><td colspan=\"8\"><b>Interface " . htmlspecialchars(convert_real_interface_to_friendly_descr($q['interface'])) . "</b></td></tr>\n";
|
257
|
$prev_if = $q['interface'];
|
258
|
}
|
259
|
?>
|
260
|
<tr class="<?=$parent_name;?>">
|
261
|
<td class="<?=$row_class?>" style="padding-left:<?=$level * 20?>px;">
|
262
|
<?php
|
263
|
if (is_array($q['queue'])) {
|
264
|
echo "<a href=\"#\" onclick=\"StatsShowHide('queuerow{$q['name']}{$q['interface']}');return false\">+/-</a>";
|
265
|
}
|
266
|
if (strstr($q['name'], "root_")) {
|
267
|
echo "<a href=\"firewall_shaper.php?interface={$if_name}&queue={$if_name}&action=show\">Root queue</a>";
|
268
|
} else {
|
269
|
echo "<a href=\"firewall_shaper.php?interface={$if_name}&queue={$q['name']}&action=show\">" . htmlspecialchars($q['name']) . "</a>";
|
270
|
}
|
271
|
?>
|
272
|
</td>
|
273
|
<?php
|
274
|
$cpuUsage = 0;
|
275
|
print('<td>');
|
276
|
print('<div class="progress" style="height: 7px;width: 170px;">');
|
277
|
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>');
|
278
|
print(' </div>');
|
279
|
print('</td>');
|
280
|
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>');
|
281
|
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>');
|
282
|
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>');
|
283
|
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>');
|
284
|
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>');
|
285
|
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>');
|
286
|
?>
|
287
|
</tr>
|
288
|
<?php
|
289
|
if (is_array($q['queue'])) {
|
290
|
processQueues($q, $level + 1, $parent_name);
|
291
|
}
|
292
|
};
|
293
|
}
|
294
|
|
295
|
function statsQueues($xml) {
|
296
|
global $statistics;
|
297
|
|
298
|
$current = new QueueStats();
|
299
|
$child = new QueueStats();
|
300
|
$current->queuename = $xml['name'] . $xml['interface'];
|
301
|
$current->queuelength = $xml['qlength'];
|
302
|
$current->pps = $xml['measured'];
|
303
|
$current->bandwidth = $xml['measuredspeedint'];
|
304
|
$current->borrows = intval($xml['borrows']);
|
305
|
$current->suspends = intval($xml['suspends']);
|
306
|
$current->drops = intval($xml['droppedpkts']);
|
307
|
if (is_array($xml['queue'])) {
|
308
|
foreach ($xml['queue'] as $q) {
|
309
|
$child = statsQueues($q);
|
310
|
$current->pps += $child->pps;
|
311
|
$current->bandwidth += $child->bandwidth;
|
312
|
$current->borrows += $child->borrows;
|
313
|
$current->suspends += $child->suspends;
|
314
|
$current->drops += $child->drops;
|
315
|
}
|
316
|
}
|
317
|
unset($child);
|
318
|
$statistics[] = $current;
|
319
|
return $current;
|
320
|
}
|
321
|
function format_bits($bits) {
|
322
|
if ($bits >= 1000000000) {
|
323
|
return sprintf("%.2f Gbps", $bits/1000000000);
|
324
|
} else if ($bits >= 1000000) {
|
325
|
return sprintf("%.2f Mbps", $bits/1000000);
|
326
|
} else if ($bits >= 1000) {
|
327
|
return sprintf("%.2f Kbps", $bits/1000);
|
328
|
} else {
|
329
|
return sprintf("%d bps", $bits);
|
330
|
}
|
331
|
}
|
332
|
?>
|