Project

General

Profile

Download (7.4 KB) Statistics
| Branch: | Tag: | Revision:
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
	mwexec("killall pfctl");
44
	Header("Location: status_queues.php");
45
	exit;
46
}
47

    
48
$a_queues = array();
49

    
50
$pfctl_vsq = `/sbin/pfctl -vsq`;
51
$pfctl_vsq_array = split("\n", $pfctl_vsq);
52
$if = "";
53
foreach($pfctl_vsq_array as $pfctl) {
54
	if (preg_match_all("/queue\s+(\w+)\s+(\w+)\s+(\w+)\s+/",$pfctl,$match_array)) {
55
		if (stristr($match_array[1][0],"root_"))
56
			continue;
57
               $a_queues[] = $match_array[1][0] . " on " .
58
				convert_real_interface_to_friendly_descr($match_array[3][0]);
59
	}
60
}
61

    
62
$pgtitle = array("Status","Traffic shaper","Queues");
63
include("head.inc");
64

    
65
?>
66

    
67
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
68
<?php include("fbegin.inc"); ?>
69
<?php
70
if(!is_array($config['shaper']['queue']) && count($config['shaper']['queue']) < 1) {
71
	echo "Traffic shaping is not configured.";
72
	include("fend.inc");
73
	exit;	
74
}
75
?>
76

    
77
<form action="status_queues.php" method="post">
78
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
79
                      <tr>
80
                        <td class="listhdr" colspan="1">Queue</td>
81
			<td class="listhdr" colspan="6">Statistics</td>
82
                      </tr>
83
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
84
		      <tr><td bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
85
                      <tr valign="top">
86
                        <td bgcolor="#DDDDDD">
87
                          <font color="#000000">&nbsp;&nbsp;&nbsp;<?echo "<a href=\"firewall_shaper.php?id={$queue}\">" . htmlspecialchars($queue) . "</a>";?>&nbsp;&nbsp;&nbsp;</td>
88
			<td bgcolor="#DDDDDD">
89
			<nobr>
90
<?php
91
			$cpuUsage = 0;
92
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
93
			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'>";
94
			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'>";
95
			echo "<nobr><img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
96
			echo "</nobr></td></tr>";
97
			echo "<tr><td bgcolor=\"#DDDDDD\" colspan=\"7\">";
98
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
99
			echo "<nobr>";
100
			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'>";
101
			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'>";
102
			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'>";
103
			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'>";
104
			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'>";
105
			echo "</nobr>";
106
?>
107

    
108
			</td>
109
                      </tr>
110
		      <tr><td class="vncell" bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
111
                      <?php $i++; endforeach; $total_queues = $i; ?>
112
                    </table>
113
		    <p>
114
                    <strong><span class="red">Note:</span></strong><strong><br></strong>
115
		      Queue graphs take 5 seconds to sample data.<br>
116
                      You can configure the Traffic Shaper <a href="firewall_shaper.php?reset=true">here</a>.
117
		    </p>
118
            </form>
119
<br><a href="status_queues.php?reset=true">Reset</a> queues if they do not load.
120

    
121
<?php include("fend.inc"); ?>
122
</body>
123
</html>
124

    
125
<?php
126

    
127
ob_flush();
128

    
129
sleep(3);
130

    
131
$counter = 0;
132
While(!Connection_Aborted()) {
133

    
134
	$stats_array = gather_altq_queue_stats(true);
135

    
136
	/* calculate total packets being moved through all queues. */
137
	$total_packets_s = 0;
138
	foreach($stats_array as $stats_line) {
139
		$stat_line_split = split("\|", $stats_line);
140
		$total_packets_s = $total_packets_s + intval($stat_line_split[2]);
141
	}
142

    
143
	$i = 0;
144
	foreach($stats_array as $stats_line) {
145
		if($stat_line_split[2] == "" and $counter > 1) {
146
			mwexec("/usr/bin/killall pfctl");
147
			exit;
148
		}
149

    
150
		$stat_line_split = split("\|", $stats_line);
151
		$packet_sampled = intval($stat_line_split[2]);
152
		$speed = $stat_line_split[1];
153
		$borrows = intval($stat_line_split[3]);
154
		$suspends = intval($stat_line_split[4]);
155
		$drops = intval($stat_line_split[5]);
156

    
157
		echo "<script language='javascript'>\n";
158

    
159
		$packet_s = round(400 * (1 - $packet_sampled / $total_packets_s), 0);
160

    
161
		echo "document.queue{$i}widthb.style.width='{$packet_s}px';\n";
162
		echo "document.queue{$i}widtha.style.width='" . (400 - $packet_s) . "px';\n";
163
		$borrows_txt = "{$borrows} borrows";
164
		$suspends_txt = "{$suspends} suspends";
165
		$drops_txt = "${drops} drops";
166
		echo "document.forms[0].queue{$i}pps.value = '{$packet_sampled}/pps';\n";
167
		echo "document.forms[0].queue{$i}bps.value = '{$speed}';\n";
168
		echo "document.forms[0].queue{$i}borrows.value = '{$borrows_txt}';\n";
169
		echo "document.forms[0].queue{$i}suspends.value = '{$suspends_txt}';\n";
170
		echo "document.forms[0].queue{$i}drops.value = '{$drops_txt}';\n";
171
		echo "</script>\n";
172
		$i++;
173
	}
174

    
175
	/*
176
	 *   prevent user from running out of ram.
177
	 *   firefox and ie can be a bear on ram usage!
178
         */
179
	$counter++;
180
	if($counter > 100) {
181
		echo "Redirecting to <a href=\"status_queues.php\">Queue Status</a>.<p>";
182
		echo "<meta http-equiv=\"refresh\" content=\"1;url={$_SERVER['SCRIPT_NAME']}\">";
183
		mwexec("/usr/bin/killall pfctl");
184
		mwexec("/usr/bin/killall pfctl");
185
		exit;
186
	}
187
}
188

    
189
mwexec("/usr/bin/killall pfctl");
190
mwexec("/usr/bin/killall pfctl");
191

    
192
?>
(155-155/211)