1
|
<?php
|
2
|
/*
|
3
|
* status_queues.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
|
7
|
* All rights reserved.
|
8
|
*
|
9
|
* 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
|
*
|
13
|
* http://www.apache.org/licenses/LICENSE-2.0
|
14
|
*
|
15
|
* 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
|
*/
|
21
|
|
22
|
##|+PRIV
|
23
|
##|*IDENT=page-status-trafficshaper-queues
|
24
|
##|*NAME=Status: Traffic Shaper: Queues
|
25
|
##|*DESCR=Allow access to the 'Status: Traffic Shaper: Queues' page.
|
26
|
##|*MATCH=status_queues.php*
|
27
|
##|-PRIV
|
28
|
/*
|
29
|
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
|
header("Pragma: no-cache"); // HTTP/1.0
|
33
|
*/
|
34
|
|
35
|
require_once("guiconfig.inc");
|
36
|
class QueueStats {
|
37
|
public $queuename;
|
38
|
public $queuelength;
|
39
|
public $pps;
|
40
|
public $bandwidth;
|
41
|
public $borrows;
|
42
|
public $suspends;
|
43
|
public $drops;
|
44
|
}
|
45
|
|
46
|
include_once("shaper.inc");
|
47
|
|
48
|
$stats = get_queue_stats();
|
49
|
|
50
|
$pgtitle = array(gettext("Status"), gettext("Queues"));
|
51
|
$shortcut_section = "trafficshaper";
|
52
|
include("head.inc");
|
53
|
|
54
|
if (!is_array($config['shaper']['queue']) || count($config['shaper']['queue']) < 1) {
|
55
|
print_info_box(gettext("Traffic shaping is not configured."));
|
56
|
include("foot.inc");
|
57
|
exit;
|
58
|
}
|
59
|
|
60
|
if (!$error): ?>
|
61
|
<form action="status_queues.php" method="post">
|
62
|
<script type="text/javascript">
|
63
|
//<![CDATA[
|
64
|
var refreshrate = 1000;
|
65
|
var queuestathistorylength = 0;
|
66
|
var queuestathistory = [];
|
67
|
var queuestatprevious = [];
|
68
|
var timestampprevious;
|
69
|
var graphstatmax = 0;
|
70
|
events.push(function() {
|
71
|
$('#updatespeed').on('change', function() {
|
72
|
refreshrate = $("#updatespeed").val();
|
73
|
});
|
74
|
|
75
|
function getqueueactivity() {
|
76
|
var url = "/getqueuestats.php";
|
77
|
var pars = "format=json";
|
78
|
$.ajax(
|
79
|
url,
|
80
|
{
|
81
|
type: 'post',
|
82
|
data: pars,
|
83
|
complete: activitycallback
|
84
|
});
|
85
|
}
|
86
|
|
87
|
function escapeStr(str)
|
88
|
{
|
89
|
if (str)
|
90
|
return str.replace(/([ #;?%&,.+*~\':"!^$[\]()=>|\/@])/g,'\\$1');
|
91
|
return str;
|
92
|
}
|
93
|
|
94
|
function activitycallback(transport) {
|
95
|
setTimeout(getqueueactivity, refreshrate);
|
96
|
json = transport.responseJSON;
|
97
|
if (!json) {
|
98
|
return;
|
99
|
}
|
100
|
timestamp = json.timestamp;
|
101
|
timestampdiff = timestamp - timestampprevious;
|
102
|
$stattype = $('#selStatistic').val();
|
103
|
|
104
|
interfacename_stats = [];
|
105
|
for (interfacename in json.interfacestats) {
|
106
|
var queueparents = [];
|
107
|
interface = json.interfacestats[interfacename];
|
108
|
interfacename_stats[interfacename] = [];
|
109
|
for (queuename in interface) {
|
110
|
queue = interface[queuename];
|
111
|
statqname = queue['name'] + queue['interface'];
|
112
|
|
113
|
for(childnr in queue['contains']) {
|
114
|
child = queue['contains'][childnr];
|
115
|
if (!queueparents[child]) {
|
116
|
queueparents[child] = [];
|
117
|
}
|
118
|
queueparents[child] = queuename;
|
119
|
}
|
120
|
|
121
|
if (queuestatprevious[statqname]) {
|
122
|
interfacename_stats[interfacename][statqname] = [];
|
123
|
pkts_ps = (queue['pkts'] - queuestatprevious[statqname]['pkts']) / timestampdiff
|
124
|
bytes_ps = (queue['bytes'] - queuestatprevious[statqname]['bytes']) / timestampdiff
|
125
|
droppedpkts = parseFloat(queue['droppedpkts']);
|
126
|
borrows = parseFloat(queue['borrows']);
|
127
|
suspends = parseFloat(queue['suspends']);
|
128
|
interfacename_stats[interfacename][statqname]['pkts_ps'] = pkts_ps;
|
129
|
interfacename_stats[interfacename][statqname]['bytes_ps'] = bytes_ps;
|
130
|
interfacename_stats[interfacename][statqname]['borrows'] = borrows;
|
131
|
interfacename_stats[interfacename][statqname]['suspends'] = suspends;
|
132
|
interfacename_stats[interfacename][statqname]['droppedpkts'] = droppedpkts;
|
133
|
interfacename_stats[interfacename][statqname]['qlengthitems'] = queue['qlengthitems'];
|
134
|
interfacename_stats[interfacename][statqname]['qlengthsize'] = queue['qlengthsize'];
|
135
|
find = queuename;
|
136
|
while(queueparents[find]) {
|
137
|
// add diff values also to parent queues
|
138
|
parentname = queueparents[find];
|
139
|
parentqueuename = parentname+interfacename;
|
140
|
interfacename_stats[interfacename][parentqueuename]['pkts_ps'] += pkts_ps;
|
141
|
interfacename_stats[interfacename][parentqueuename]['bytes_ps'] += bytes_ps;
|
142
|
interfacename_stats[interfacename][parentqueuename]['borrows'] += borrows;
|
143
|
interfacename_stats[interfacename][parentqueuename]['suspends'] += suspends;
|
144
|
interfacename_stats[interfacename][parentqueuename]['droppedpkts'] += droppedpkts;
|
145
|
find = parentname;
|
146
|
}
|
147
|
}
|
148
|
queuestatprevious[statqname] = queue;
|
149
|
}
|
150
|
}
|
151
|
// Find max pps/bps needed for any scale bar
|
152
|
statmax = 0;
|
153
|
for (interfacename in interfacename_stats) {
|
154
|
interface = interfacename_stats[interfacename];
|
155
|
for (queuename in interface) {
|
156
|
queue = interface[queuename];
|
157
|
if ($stattype == "0") {
|
158
|
if (statmax < queue['pkts_ps']) {
|
159
|
statmax = queue['pkts_ps'];
|
160
|
}
|
161
|
} else {
|
162
|
if (statmax < queue['bytes_ps']) {
|
163
|
statmax = queue['bytes_ps'];
|
164
|
}
|
165
|
}
|
166
|
}
|
167
|
}
|
168
|
// use a slowly sliding max scale value but do make sure its always large enough to accomodate the largest value..
|
169
|
if (graphstatmax < statmax) {
|
170
|
// peek value + 10% keeps a little room for it to increase
|
171
|
graphstatmax = statmax * 1.1;
|
172
|
} else {
|
173
|
// in general make largest bar fill +- 2/3 of the scale
|
174
|
graphstatmax = (graphstatmax * 20 + statmax * 1.5) / 21;
|
175
|
}
|
176
|
// set values on the objects
|
177
|
for (interfacename in interfacename_stats) {
|
178
|
interface = interfacename_stats[interfacename];
|
179
|
for (queuename in interface) {
|
180
|
queue = interface[queuename];
|
181
|
statqname = escapeStr(queuename);
|
182
|
if ($stattype == "0") {
|
183
|
$('#queue'+statqname+'width').css('width', (queue['pkts_ps']*100/graphstatmax).toFixed(0) + '%');
|
184
|
} else {
|
185
|
$('#queue'+statqname+'width').css('width', (queue['bytes_ps']*100/graphstatmax).toFixed(0) + '%');
|
186
|
}
|
187
|
$('#queue'+statqname+'pps').val(queue['pkts_ps'].toFixed(1));
|
188
|
$('#queue'+statqname+'bps').val(formatSpeedBits(queue['bytes_ps']));
|
189
|
$('#queue'+statqname+'borrows').val(queue['borrows']);
|
190
|
$('#queue'+statqname+'suspends').val(queue['suspends']);
|
191
|
$('#queue'+statqname+'drops').val(queue['droppedpkts']);
|
192
|
$('#queue'+statqname+'length').val(queue['qlengthitems']+'/'+queue['qlengthsize']);
|
193
|
}
|
194
|
}
|
195
|
timestampprevious = timestamp;
|
196
|
}
|
197
|
|
198
|
$(document).ready(function() {
|
199
|
setTimeout(getqueueactivity, 150);
|
200
|
});
|
201
|
});
|
202
|
|
203
|
function formatSpeedBits(speed) {
|
204
|
// format speed in bits/sec, input: bytes/sec
|
205
|
if (speed < 125000) {
|
206
|
return Math.round(speed / 125) + " <?=gettext("Kbps"); ?>";
|
207
|
}
|
208
|
if (speed < 125000000) {
|
209
|
return Math.round(speed / 1250)/100 + " <?=gettext("Mbps"); ?>";
|
210
|
}
|
211
|
// else
|
212
|
return Math.round(speed / 1250000)/100 + " <?=gettext("Gbps"); ?>"; /* wow! */
|
213
|
}
|
214
|
//]]>
|
215
|
</script>
|
216
|
<?php endif;
|
217
|
|
218
|
if ($error):
|
219
|
print_info_box($error);
|
220
|
else: ?>
|
221
|
<div class="panel panel-default">
|
222
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Settings"); ?></h2></div>
|
223
|
<div class="panel-body table-responsive">
|
224
|
<label class="col-sm-2 control-label">
|
225
|
<span>Refresh rate</span>
|
226
|
</label>
|
227
|
<div class="col-sm-10">
|
228
|
<select id="updatespeed" class="form-control">
|
229
|
<option value="500">0.5 <?=gettext("seconds");?></option>
|
230
|
<option value="1000" selected>1 <?=gettext("seconds");?></option>
|
231
|
<option value="2000">2 <?=gettext("seconds");?></option>
|
232
|
<option value="5000">5 <?=gettext("seconds");?></option>
|
233
|
</select>
|
234
|
</div>
|
235
|
</div>
|
236
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Status Queues"); ?></h2></div>
|
237
|
<div class="panel-body table-responsive">
|
238
|
<table class="table table-striped table-hover">
|
239
|
<thead>
|
240
|
<tr>
|
241
|
<th><?=gettext("Queue"); ?></th>
|
242
|
<th><?=gettext("Statistics"); ?>
|
243
|
<select id="selStatistic" class="form-control">
|
244
|
<option value="0"><?=gettext("PPS");?></option>
|
245
|
<option value="1"><?=gettext("Bandwidth");?></option>
|
246
|
</select>
|
247
|
</th>
|
248
|
<th><?=gettext("PPS"); ?></th>
|
249
|
<th><?=gettext("Bandwidth"); ?></th>
|
250
|
<th><?=gettext("Borrows"); ?></th>
|
251
|
<th><?=gettext("Suspends"); ?></th>
|
252
|
<th><?=gettext("Drops"); ?></th>
|
253
|
<th><?=gettext("Length"); ?></th>
|
254
|
</tr>
|
255
|
</thead>
|
256
|
<tbody>
|
257
|
<?php
|
258
|
$if_queue_list = get_configured_interface_list_by_realif(true);
|
259
|
processInterfaceQueues($stats, 0, "");
|
260
|
?>
|
261
|
<?php endif; ?>
|
262
|
</tbody>
|
263
|
</table>
|
264
|
<br />
|
265
|
<div class="infoblock blockopen">
|
266
|
<?php
|
267
|
print_info_box(gettext("Queue graphs sample data on a regular interval."), 'info', false);
|
268
|
?>
|
269
|
</div>
|
270
|
</div>
|
271
|
</div>
|
272
|
<br/>
|
273
|
|
274
|
<script type="text/javascript">
|
275
|
//<![CDATA[
|
276
|
function StatsShowHide(classname) {
|
277
|
var firstrow = $("." + classname).first();
|
278
|
if (firstrow.is(':visible')) {
|
279
|
$("." + classname).hide();
|
280
|
} else {
|
281
|
$("." + classname).show();
|
282
|
}
|
283
|
}
|
284
|
//]]>
|
285
|
</script>
|
286
|
</form>
|
287
|
<?php
|
288
|
|
289
|
include("foot.inc");
|
290
|
|
291
|
function processInterfaceQueues($altqstats, $parent_name) {
|
292
|
global $g;
|
293
|
global $if_queue_list;
|
294
|
|
295
|
$parent_name = $parent_name . " queuerow" . $altqstats['name'] . convert_real_interface_to_friendly_interface_name($altqstats['interface']);
|
296
|
$prev_if = $altqstats['interface'];
|
297
|
if (!is_array($altqstats['interfacestats'])) {
|
298
|
print("<tr><td>");
|
299
|
print("No Queue data available");
|
300
|
print("</td></tr>");
|
301
|
return;
|
302
|
}
|
303
|
foreach ($altqstats['interfacestats'] as $if => $ifq) {
|
304
|
$parents = array();
|
305
|
echo "<tr><td colspan=\"8\"><b>Interface " . htmlspecialchars(convert_real_interface_to_friendly_descr($if)) . "</b></td></tr>\n";
|
306
|
$if_name = "";
|
307
|
foreach ($if_queue_list as $oif => $real_name) {
|
308
|
if ($oif == $if) {
|
309
|
$if_name = $real_name;
|
310
|
break;
|
311
|
}
|
312
|
}
|
313
|
if ($prev_if != $q['interface']) {
|
314
|
$prev_if = $q['interface'];
|
315
|
}
|
316
|
foreach($ifq as $qkey => $q) {
|
317
|
$parent_name = $if . " queuerow" . $altqstats['name'] . convert_real_interface_to_friendly_interface_name($altqstats['interface']);
|
318
|
if (isset($q['contains'])) {
|
319
|
foreach($q['contains'] as $child) {
|
320
|
$parents[$child] = $qkey;
|
321
|
}
|
322
|
}
|
323
|
$find = $qkey;
|
324
|
$level = 0;
|
325
|
while(isset($parents[$find])) {
|
326
|
$find = $parents[$find];
|
327
|
$level++;
|
328
|
$parent_name = $parent_name . " queuerow" . $find . $q['interface'];
|
329
|
}
|
330
|
$qfinterface = convert_real_interface_to_friendly_interface_name($q['interface']);
|
331
|
$qname = str_replace($q['interface'], $qfinterface, $q['name']);
|
332
|
?>
|
333
|
<tr class="<?=$parent_name;?>">
|
334
|
<td class="<?=$row_class?>" style="padding-left:<?=$level * 20?>px;">
|
335
|
<?php
|
336
|
if (is_array($q['contains'])) {
|
337
|
echo "<a href=\"#\" onclick=\"StatsShowHide('queuerow{$qname}{$qfinterface}');return false\">+/-</a>";
|
338
|
}
|
339
|
if (strstr($qname, "root_")) {
|
340
|
echo "<a href=\"firewall_shaper.php?interface={$if_name}&queue={$if_name}&action=show\">Root queue</a>";
|
341
|
} else {
|
342
|
echo "<a href=\"firewall_shaper.php?interface={$if_name}&queue={$qname}&action=show\">" . htmlspecialchars($qname) . "</a>";
|
343
|
}
|
344
|
?>
|
345
|
</td>
|
346
|
<?php
|
347
|
$cpuUsage = 0;
|
348
|
$stat_prefix = "queue" . $q['name'] . $q['interface'];
|
349
|
print('<td>');
|
350
|
print('<div class="progress" style="height: 7px;width: 170px;">');
|
351
|
print(' <div class="progress-bar" role="progressbar" id="' . $stat_prefix . 'width" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width: ' . $cpuUsage*100 . '%;"></div>');
|
352
|
print(' </div>');
|
353
|
print('</td>');
|
354
|
print('<td><input readonly style="border:0;width:70px;text-align:right;" name="' . $stat_prefix . 'pps" id="' . $stat_prefix . 'pps" value="(' . gettext("Loading") . ')" /></td>');
|
355
|
print('<td><input readonly style="border:0;width:80px;text-align:right;" name="' . $stat_prefix . 'bps" id="' . $stat_prefix . 'bps" value="" /></td>');
|
356
|
print('<td><input readonly style="border:0;width:70px;text-align:right;" name="' . $stat_prefix . 'borrows" id="' . $stat_prefix . 'borrows" value="" /></td>');
|
357
|
print('<td><input readonly style="border:0;width:70px;text-align:right;" name="' . $stat_prefix . 'suspends" id="' . $stat_prefix . 'suspends" value="" /></td>');
|
358
|
print('<td><input readonly style="border:0;width:70px;text-align:right;" name="' . $stat_prefix . 'drops" id="' . $stat_prefix . 'drops" value="" /></td>');
|
359
|
print('<td><input readonly style="border:0;width:70px;text-align:right;" name="' . $stat_prefix . 'length" id="' . $stat_prefix . 'length" value="" /></td>');
|
360
|
?>
|
361
|
</tr>
|
362
|
<?php
|
363
|
if (is_array($q['queue'])) {
|
364
|
processInterfaceQueues($q, $level + 1, $parent_name);
|
365
|
}
|
366
|
}
|
367
|
};
|
368
|
}
|
369
|
|
370
|
function statsQueues($xml) {
|
371
|
global $statistics;
|
372
|
|
373
|
$fname = convert_real_interface_to_friendly_interface_name($xml['interface']);
|
374
|
$qname = str_replace($xml['interface'], $fname, $xml['name']);
|
375
|
|
376
|
$current = new QueueStats();
|
377
|
$child = new QueueStats();
|
378
|
$current->queuename = $qname . $fname;
|
379
|
$current->queuelength = $xml['qlength'];
|
380
|
$current->pps = $xml['measured'];
|
381
|
$current->bandwidth = $xml['measuredspeedint'];
|
382
|
$current->borrows = intval($xml['borrows']);
|
383
|
$current->suspends = intval($xml['suspends']);
|
384
|
$current->drops = intval($xml['droppedpkts']);
|
385
|
if (is_array($xml['queue'])) {
|
386
|
foreach ($xml['queue'] as $q) {
|
387
|
$child = statsQueues($q);
|
388
|
$current->pps += $child->pps;
|
389
|
$current->bandwidth += $child->bandwidth;
|
390
|
$current->borrows += $child->borrows;
|
391
|
$current->suspends += $child->suspends;
|
392
|
$current->drops += $child->drops;
|
393
|
}
|
394
|
}
|
395
|
unset($child);
|
396
|
$statistics[] = $current;
|
397
|
return $current;
|
398
|
}
|
399
|
function format_bits($bits) {
|
400
|
if ($bits >= 1000000000) {
|
401
|
return sprintf("%.2f Gbps", $bits/1000000000);
|
402
|
} else if ($bits >= 1000000) {
|
403
|
return sprintf("%.2f Mbps", $bits/1000000);
|
404
|
} else if ($bits >= 1000) {
|
405
|
return sprintf("%.2f Kbps", $bits/1000);
|
406
|
} else {
|
407
|
return sprintf("%d bps", $bits);
|
408
|
}
|
409
|
}
|
410
|
?>
|