1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
status_queues.php
|
6
|
Part of the pfSense project
|
7
|
Copyright (C) 2004, 2005 Scott Ullrich
|
8
|
Copyright (C) 2009 Ermal Luçi
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
/*
|
33
|
pfSense_BUILDER_BINARIES: /sbin/pfctl
|
34
|
pfSense_MODULE: shaper
|
35
|
*/
|
36
|
|
37
|
##|+PRIV
|
38
|
##|*IDENT=page-status-trafficshaper-queues
|
39
|
##|*NAME=Status: Traffic shaper: Queues page
|
40
|
##|*DESCR=Allow access to the 'Status: Traffic shaper: Queues' page.
|
41
|
##|*MATCH=status_queues.php*
|
42
|
##|-PRIV
|
43
|
|
44
|
header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
|
45
|
header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT" );
|
46
|
header("Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1
|
47
|
header("Cache-Control: post-check=0, pre-check=0", FALSE );
|
48
|
header("Pragma: no-cache"); // HTTP/1.0
|
49
|
|
50
|
require("guiconfig.inc");
|
51
|
class QueueStats {
|
52
|
public $queuename;
|
53
|
public $queuelength;
|
54
|
public $pps;
|
55
|
public $bandwidth;
|
56
|
public $borrows;
|
57
|
public $suspends;
|
58
|
public $drops;
|
59
|
}
|
60
|
if (!file_exists("{$g['varrun_path']}/qstats.pid") || !isvalidpid("{$g['varrun_path']}/qstats.pid")) {
|
61
|
/* Start in the background so we don't hang up the GUI */
|
62
|
mwexec_bg("/usr/local/sbin/qstats -p {$g['varrun_path']}/qstats.pid");
|
63
|
/* Give it a moment to start up */
|
64
|
sleep(1);
|
65
|
}
|
66
|
$fd = @fsockopen("unix://{$g['varrun_path']}/qstats");
|
67
|
if (!$fd) {
|
68
|
$error = "Something wrong happened during comunication with stat gathering";
|
69
|
} else {
|
70
|
$stats = "";
|
71
|
while(!feof($fd))
|
72
|
$stats .= fread($fd, 4096);
|
73
|
fclose($fd);
|
74
|
@file_put_contents("{$g['tmp_path']}/qstats", $stats);
|
75
|
$altqstats = @parse_xml_config("{$g['tmp_path']}/qstats", array("altqstats"));
|
76
|
if ($altqstats == -1)
|
77
|
$error = "No queue statistics could be read.";
|
78
|
}
|
79
|
if ($_REQUEST['getactivity']) {
|
80
|
$statistics = array();
|
81
|
$bigger_stat = 0;
|
82
|
$stat_type = $_REQUEST['stats'];
|
83
|
/* build the queue stats. */
|
84
|
foreach($altqstats['queue'] as $q) {
|
85
|
statsQueues($q);
|
86
|
}
|
87
|
/* calculate the bigger amount of packets or bandwidth being moved through all queues. */
|
88
|
if ($stat_type == "0")
|
89
|
{
|
90
|
foreach($statistics as $q) {
|
91
|
if ($bigger_stat < $q->pps)
|
92
|
$bigger_stat = $q->pps;
|
93
|
}
|
94
|
}
|
95
|
else
|
96
|
{
|
97
|
foreach($statistics as $q) {
|
98
|
if ($bigger_stat < $q->bandwidth)
|
99
|
$bigger_stat = $q->bandwidth;
|
100
|
}
|
101
|
}
|
102
|
$finscript = "";
|
103
|
foreach($statistics as $q) {
|
104
|
if ($stat_type == "0")
|
105
|
$packet_s = round(150 * (1 - $q->pps / $bigger_stat), 0);
|
106
|
else
|
107
|
$packet_s = round(150 * (1 - $q->bandwidth / $bigger_stat), 0);
|
108
|
if ($packet_s < 0) {$packet_s = 0;}
|
109
|
$finscript .= "jQuery('#queue{$q->queuename}widthb').width('{$packet_s}');";
|
110
|
$finscript .= "jQuery('#queue{$q->queuename}widtha').width('" . (150 - $packet_s) . "');";
|
111
|
$finscript .= "jQuery('#queue{$q->queuename}pps').val('" . number_format($q->pps,1) . "');";
|
112
|
$finscript .= "jQuery('#queue{$q->queuename}bps').val('" . format_bits($q->bandwidth) . "');";
|
113
|
$finscript .= "jQuery('#queue{$q->queuename}borrows').val('{$q->borrows}');";
|
114
|
$finscript .= "jQuery('#queue{$q->queuename}suspends').val('{$q->suspends}');";
|
115
|
$finscript .= "jQuery('#queue{$q->queuename}drops').val('{$q->drops}');";
|
116
|
$finscript .= "jQuery('#queue{$q->queuename}length').val('{$q->queuelength}');";
|
117
|
}
|
118
|
unset($statistics, $altqstats);
|
119
|
header("Content-type: text/javascript");
|
120
|
echo $finscript;
|
121
|
exit;
|
122
|
}
|
123
|
$pgtitle = array(gettext("Status"),gettext("Traffic shaper"),gettext("Queues"));
|
124
|
$shortcut_section = "trafficshaper";
|
125
|
include("head.inc");
|
126
|
?>
|
127
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
128
|
<?php include("fbegin.inc"); ?>
|
129
|
<?php
|
130
|
if(!is_array($config['shaper']['queue']) || count($config['shaper']['queue']) < 1) {
|
131
|
echo gettext("Traffic shaping is not configured.");
|
132
|
include("fend.inc");
|
133
|
exit;}
|
134
|
?>
|
135
|
<?php if (!$error): ?>
|
136
|
<form action="status_queues.php" method="post">
|
137
|
<script type="text/javascript">
|
138
|
//<![CDATA[
|
139
|
function getqueueactivity() {
|
140
|
var url = "/status_queues.php";
|
141
|
var pars = "getactivity=yes&stats=" + jQuery("#selStatistic").val();
|
142
|
jQuery.ajax(
|
143
|
url,
|
144
|
{
|
145
|
type: 'post',
|
146
|
data: pars,
|
147
|
complete: activitycallback
|
148
|
});
|
149
|
}
|
150
|
function activitycallback(transport) {
|
151
|
setTimeout('getqueueactivity()', 5100);
|
152
|
}
|
153
|
jQuery(document).ready(function(){
|
154
|
setTimeout('getqueueactivity()', 150);
|
155
|
});
|
156
|
//]]>
|
157
|
</script>
|
158
|
<?php endif; ?>
|
159
|
<table width="100%" border="1" cellpadding="0" cellspacing="0" summary="status queues">
|
160
|
<?php if ($error): ?>
|
161
|
<tr><td><?php echo $error; ?></td></tr>
|
162
|
<?php else: ?>
|
163
|
<tr>
|
164
|
<td class="listhdr"><?=gettext("Queue"); ?></td>
|
165
|
<td class="listhdr">
|
166
|
<?=gettext("Statistics"); ?>
|
167
|
<select id="selStatistic">
|
168
|
<option value="0">PPS</option>
|
169
|
<option value="1">Bandwidth</option>
|
170
|
</select>
|
171
|
</td>
|
172
|
<td class="listhdr" width="1%"><?=gettext("PPS"); ?></td>
|
173
|
<td class="listhdr" width="1%"><?=gettext("Bandwidth"); ?></td>
|
174
|
<td class="listhdr" width="1%"><?=gettext("Borrows"); ?></td>
|
175
|
<td class="listhdr" width="1%"><?=gettext("Suspends"); ?></td>
|
176
|
<td class="listhdr" width="1%"><?=gettext("Drops"); ?></td>
|
177
|
<td class="listhdr" width="1%"><?=gettext("Length"); ?></td>
|
178
|
</tr>
|
179
|
<?php
|
180
|
$if_queue_list = get_configured_interface_list_by_realif(false, true);
|
181
|
processQueues($altqstats, 0, "")?>
|
182
|
<?php endif; ?>
|
183
|
</table>
|
184
|
<p>
|
185
|
<strong><span class="red"><?=gettext("Note"); ?>:</span></strong><br />
|
186
|
<?=gettext("Queue graphs take 5 seconds to sample data"); ?>.<br />
|
187
|
<?=gettext("You can configure the Traffic Shaper"); ?> <a href="/firewall_shaper_wizards.php"><?=gettext("here"); ?></a>.
|
188
|
</p>
|
189
|
<script type="text/javascript">
|
190
|
//<![CDATA[
|
191
|
function StatsShowHide(classname) {
|
192
|
var firstrow = jQuery("." + classname).first();
|
193
|
if (firstrow.is(':visible')) {
|
194
|
jQuery("." + classname).hide();}
|
195
|
else {
|
196
|
jQuery("." + classname).show();}
|
197
|
}
|
198
|
//]]>
|
199
|
</script>
|
200
|
</form>
|
201
|
<?php include("fend.inc"); ?>
|
202
|
</body>
|
203
|
</html>
|
204
|
<?php
|
205
|
function processQueues($altqstats, $level, $parent_name){
|
206
|
global $g;
|
207
|
global $if_queue_list;
|
208
|
$gray_value = 190 + $level * 10;
|
209
|
if ($gray_value > 250) $gray_value = 255;
|
210
|
$row_background = str_repeat(dechex($gray_value), 3);
|
211
|
$parent_name = $parent_name . " queuerow" . $altqstats['name'] . $altqstats['interface'];
|
212
|
$prev_if = $altqstats['interface'];
|
213
|
foreach ($altqstats['queue'] as $q) {
|
214
|
$if_name = "";
|
215
|
foreach ($if_queue_list as $oif => $real_name) {
|
216
|
if ($oif == $q['interface']) {
|
217
|
$if_name = $real_name;
|
218
|
break;
|
219
|
}
|
220
|
}
|
221
|
if ($prev_if != $q['interface']) {
|
222
|
echo "<tr><td colspan=\"8\" style=\"padding: 2px;\"><b>Interface ". htmlspecialchars(convert_real_interface_to_friendly_descr($q['interface'])) . "</b></td></tr>";
|
223
|
$prev_if = $q['interface'];
|
224
|
}
|
225
|
?>
|
226
|
<tr class="<?php echo $parent_name?>">
|
227
|
<td bgcolor="#<?php echo $row_background?>" style="padding-left: <?php echo $level * 20?>px;">
|
228
|
<font color="#000000">
|
229
|
<?
|
230
|
if (strstr($q['name'], "root_"))
|
231
|
echo "<a href=\"firewall_shaper.php?interface={$if_name}&queue={$if_name}&action=show\">Root queue</a>";
|
232
|
else
|
233
|
echo "<a href=\"firewall_shaper.php?interface={$if_name}&queue={$q['name']}&action=show\">" . htmlspecialchars($q['name']) . "</a>";
|
234
|
?>
|
235
|
</font>
|
236
|
</td>
|
237
|
<?php
|
238
|
$cpuUsage = 0;
|
239
|
echo "<td class=\"nowrap\" width=\"1%\" bgcolor=\"#{$row_background}\">";
|
240
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='10' width='4' border='0' align='middle' alt='' />";
|
241
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='10' name='queue{$q['name']}{$q['interface']}widtha' id='queue{$q['name']}{$q['interface']}widtha' width='" . $cpuUsage . "' border='0' align='middle' alt='" . htmlspecialchars($q['name']) . "' />";
|
242
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='10' name='queue{$q['name']}{$q['interface']}widthb' id='queue{$q['name']}{$q['interface']}widthb' width='" . (150 - $cpuUsage) . "' border='0' align='middle' alt='" . htmlspecialchars($q['name']) . "' />";
|
243
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='10' width='5' border='0' align='middle' alt='' /> ";
|
244
|
if (is_array($q['queue'])) {
|
245
|
echo "<a href=\"#\" onclick=\"StatsShowHide('queuerow{$q['name']}{$q['interface']}');return false\">+/-</a> ";
|
246
|
}
|
247
|
echo " </td>";
|
248
|
echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:70px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}pps' id='queue{$q['name']}{$q['interface']}pps' value='(" . gettext("Loading") . ")' align='left' /></td>";
|
249
|
echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:80px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}bps' id='queue{$q['name']}{$q['interface']}bps' value='' align='right' /></td>";
|
250
|
echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:70px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}borrows' id='queue{$q['name']}{$q['interface']}borrows' value='' align='right' /></td>";
|
251
|
echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:70px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}suspends' id='queue{$q['name']}{$q['interface']}suspends' value='' align='right' /></td>";
|
252
|
echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:70px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}drops' id='queue{$q['name']}{$q['interface']}drops' value='' align='right' /></td>";
|
253
|
echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:70px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}length' id='queue{$q['name']}{$q['interface']}length' value='' align='right' /></td>";
|
254
|
?>
|
255
|
</tr>
|
256
|
<?php
|
257
|
if (is_array($q['queue']))
|
258
|
processQueues($q, $level + 1, $parent_name);
|
259
|
};
|
260
|
}
|
261
|
function statsQueues($xml){
|
262
|
global $statistics;
|
263
|
|
264
|
$current = new QueueStats();
|
265
|
$child = new QueueStats();
|
266
|
$current->queuename = $xml['name'] . $xml['interface'];
|
267
|
$current->queuelength = $xml['qlength'];
|
268
|
$current->pps = $xml['measured'];
|
269
|
$current->bandwidth = $xml['measuredspeedint'];
|
270
|
$current->borrows = intval($xml['borrows']);
|
271
|
$current->suspends = intval($xml['suspends']);
|
272
|
$current->drops = intval($xml['droppedpkts']);
|
273
|
if (is_array($xml['queue'])) {
|
274
|
foreach($xml['queue'] as $q) {
|
275
|
$child = statsQueues($q);
|
276
|
$current->pps += $child->pps;
|
277
|
$current->bandwidth += $child->bandwidth;
|
278
|
$current->borrows += $child->borrows;
|
279
|
$current->suspends += $child->suspends;
|
280
|
$current->drops += $child->drops;
|
281
|
}
|
282
|
}
|
283
|
unset($child);
|
284
|
$statistics[] = $current;
|
285
|
return $current;
|
286
|
}
|
287
|
function format_bits($bits) {
|
288
|
if ($bits >= 1000000000) {
|
289
|
return sprintf("%.2f Gbps", $bits/1000000000);
|
290
|
} else if ($bits >= 1000000) {
|
291
|
return sprintf("%.2f Mbps", $bits/1000000);
|
292
|
} else if ($bits >= 1000) {
|
293
|
return sprintf("%.2f Kbps", $bits/1000);
|
294
|
} else {
|
295
|
return sprintf("%d bps", $bits);
|
296
|
}
|
297
|
}
|
298
|
?>
|