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
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
|
32
|
##|+PRIV
|
33
|
##|*IDENT=page-status-trafficshaper-queues
|
34
|
##|*NAME=Status: Traffic shaper: Queues page
|
35
|
##|*DESCR=Allow access to the 'Status: Traffic shaper: Queues' page.
|
36
|
##|*MATCH=status_queues.php*
|
37
|
##|-PRIV
|
38
|
|
39
|
|
40
|
require("guiconfig.inc");
|
41
|
|
42
|
if($_GET['reset'] <> "") {
|
43
|
Header("Location: status_queues.php");
|
44
|
exit;
|
45
|
}
|
46
|
|
47
|
$a_queues = array();
|
48
|
|
49
|
$pfctl_vsq = `/sbin/pfctl -vsq`;
|
50
|
$pfctl_vsq_array = split("\n", $pfctl_vsq);
|
51
|
$if = "";
|
52
|
foreach($pfctl_vsq_array as $pfctl) {
|
53
|
if (preg_match_all("/queue\s+(\w+)\s+(\w+)\s+(\w+)\s+/",$pfctl,$match_array)) {
|
54
|
if (stristr($match_array[1][0],"root_"))
|
55
|
continue;
|
56
|
$a_queues[] = $match_array[1][0] . " on " .
|
57
|
convert_real_interface_to_friendly_descr($match_array[3][0]);
|
58
|
}
|
59
|
}
|
60
|
|
61
|
$pgtitle = array("Status","Traffic shaper","Queues");
|
62
|
include("head.inc");
|
63
|
|
64
|
?>
|
65
|
|
66
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
67
|
<?php include("fbegin.inc"); ?>
|
68
|
<?php
|
69
|
if(!is_array($config['shaper']['queue']) && count($config['shaper']['queue']) < 1) {
|
70
|
echo "Traffic shaping is not configured.";
|
71
|
include("fend.inc");
|
72
|
exit;
|
73
|
}
|
74
|
?>
|
75
|
|
76
|
<form action="status_queues.php" method="post">
|
77
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
78
|
<tr>
|
79
|
<td class="listhdr" colspan="1">Queue</td>
|
80
|
<td class="listhdr" colspan="6">Statistics</td>
|
81
|
</tr>
|
82
|
<?php $i = 0; foreach ($a_queues as $queue): ?>
|
83
|
<tr><td bgcolor="#DDDDDD" colspan="7"> </td></tr>
|
84
|
<tr valign="top">
|
85
|
<td bgcolor="#DDDDDD">
|
86
|
<font color="#000000"> <?echo "<a href=\"firewall_shaper.php?id={$queue}\">" . htmlspecialchars($queue) . "</a>";?> </td>
|
87
|
<td bgcolor="#DDDDDD">
|
88
|
<nobr>
|
89
|
<?php
|
90
|
$cpuUsage = 0;
|
91
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
|
92
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='15' name='queue{$i}widtha' id='queue{$i}widtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
|
93
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='15' name='queue{$i}widthb' id='queue{$i}widthb' width='" . (400 - $cpuUsage) . "' border='0' align='absmiddle'>";
|
94
|
echo "<nobr><img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
|
95
|
echo "</nobr></td></tr>";
|
96
|
echo "<tr><td bgcolor=\"#DDDDDD\" colspan=\"7\">";
|
97
|
echo " ";
|
98
|
echo "<nobr>";
|
99
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='15' name='queue{$i}pps' id='queue{$i}pps' value=' (Loading)' align='right'>";
|
100
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='15' name='queue{$i}bps' id='queue{$i}bps' value='' align='right'>";
|
101
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='15' name='queue{$i}borrows' id='queue{$i}borrows' value='' align='right'>";
|
102
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='15' name='queue{$i}suspends' id='queue{$i}suspends' value='' align='right'>";
|
103
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='15' name='queue{$i}drops' id='queue{$i}drops' value='' align='right'>";
|
104
|
echo "</nobr>";
|
105
|
?>
|
106
|
|
107
|
</td>
|
108
|
</tr>
|
109
|
<tr><td class="vncell" bgcolor="#DDDDDD" colspan="7"> </td></tr>
|
110
|
<?php $i++; endforeach; $total_queues = $i; ?>
|
111
|
</table>
|
112
|
<p>
|
113
|
<strong><span class="red">Note:</span></strong><strong><br></strong>
|
114
|
Queue graphs take 5 seconds to sample data.<br>
|
115
|
You can configure the Traffic Shaper <a href="firewall_shaper.php?reset=true">here</a>.
|
116
|
</p>
|
117
|
</form>
|
118
|
<br><a href="status_queues.php?reset=true">Reset</a> queues if they do not load.
|
119
|
|
120
|
<?php include("fend.inc"); ?>
|
121
|
</body>
|
122
|
</html>
|
123
|
|
124
|
<?php
|
125
|
|
126
|
ob_flush();
|
127
|
|
128
|
sleep(3);
|
129
|
|
130
|
$counter = 0;
|
131
|
While(!Connection_Aborted()) {
|
132
|
|
133
|
$stats_array = gather_altq_queue_stats(true);
|
134
|
|
135
|
/* calculate total packets being moved through all queues. */
|
136
|
$total_packets_s = 0;
|
137
|
foreach($stats_array as $stats_line) {
|
138
|
$stat_line_split = split("\|", $stats_line);
|
139
|
$total_packets_s = $total_packets_s + intval($stat_line_split[2]);
|
140
|
}
|
141
|
|
142
|
$i = 0;
|
143
|
foreach($stats_array as $stats_line) {
|
144
|
if($stat_line_split[2] == "" and $counter > 1) {
|
145
|
exit;
|
146
|
}
|
147
|
|
148
|
$stat_line_split = split("\|", $stats_line);
|
149
|
$packet_sampled = intval($stat_line_split[2]);
|
150
|
$speed = $stat_line_split[1];
|
151
|
$borrows = intval($stat_line_split[3]);
|
152
|
$suspends = intval($stat_line_split[4]);
|
153
|
$drops = intval($stat_line_split[5]);
|
154
|
|
155
|
echo "<script language='javascript'>\n";
|
156
|
|
157
|
$packet_s = round(400 * (1 - $packet_sampled / $total_packets_s), 0);
|
158
|
|
159
|
echo "document.queue{$i}widthb.style.width='{$packet_s}px';\n";
|
160
|
echo "document.queue{$i}widtha.style.width='" . (400 - $packet_s) . "px';\n";
|
161
|
$borrows_txt = "{$borrows} borrows";
|
162
|
$suspends_txt = "{$suspends} suspends";
|
163
|
$drops_txt = "${drops} drops";
|
164
|
echo "document.forms[0].queue{$i}pps.value = '{$packet_sampled}/pps';\n";
|
165
|
echo "document.forms[0].queue{$i}bps.value = '{$speed}';\n";
|
166
|
echo "document.forms[0].queue{$i}borrows.value = '{$borrows_txt}';\n";
|
167
|
echo "document.forms[0].queue{$i}suspends.value = '{$suspends_txt}';\n";
|
168
|
echo "document.forms[0].queue{$i}drops.value = '{$drops_txt}';\n";
|
169
|
echo "</script>\n";
|
170
|
$i++;
|
171
|
}
|
172
|
|
173
|
/*
|
174
|
* prevent user from running out of ram.
|
175
|
* firefox and ie can be a bear on ram usage!
|
176
|
*/
|
177
|
$counter++;
|
178
|
if($counter > 100) {
|
179
|
echo "Redirecting to <a href=\"status_queues.php\">Queue Status</a>.<p>";
|
180
|
echo "<meta http-equiv=\"refresh\" content=\"1;url={$_SERVER['SCRIPT_NAME']}\">";
|
181
|
exit;
|
182
|
}
|
183
|
}
|
184
|
?>
|