Project

General

Profile

Download (7.42 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
require("guiconfig.inc");
33

    
34
if($_GET['reset'] <> "") {
35
	mwexec("killall pfctl");
36
	Header("Location: status_queues.php");
37
	exit;
38
}
39

    
40
$a_queues = array();
41

    
42
$pfctl_vsq = `/sbin/pfctl -vsq`;
43
$pfctl_vsq_array = split("\n", $pfctl_vsq);
44
$if = "";
45
foreach($pfctl_vsq_array as $pfctl) {
46
	if (preg_match_all("/queue\s+(\w+)\s+/",$pfctl,$match_array))
47
		if(stristr($match_array[1][0],"root_")==false)
48
			$a_queues[] = $match_array[1][0] . " on {$if}" ;	
49
		else {
50
			$if = preg_replace("(root_)", "", $match_array[1][0]);
51
			foreach ($config['interfaces'] as $ifkey => $ifdesc) {
52
				if ($ifdesc['if'] == $if) {
53
					if ($ifdesc['descr'] != "") {
54
						$if = htmlspecialchars($ifdesc['descr']);
55
					} else {
56
						$if = strtoupper($ifkey);
57
					}
58
					break;
59
				}
60
			}
61
		}
62
}
63

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

    
67
?>
68

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

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

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

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

    
127
<?php
128

    
129
ob_flush();
130

    
131
sleep(3);
132

    
133
$counter = 0;
134
While(!Connection_Aborted()) {
135

    
136
	$stats_array = gather_altq_queue_stats(true);
137

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

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

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

    
159
		echo "<script language='javascript'>\n";
160

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

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

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

    
191
mwexec("/usr/bin/killall pfctl");
192
mwexec("/usr/bin/killall pfctl");
193

    
194
?>
(137-137/196)