Project

General

Profile

Download (6.96 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 -9 pfctl pfctl");
36
	Header("Location: status_queues.php");
37
	exit;
38
}
39

    
40
if (!is_array($config['shaper']['queue'])) {
41
	$config['shaper']['queue'] = array();
42
}
43

    
44
$a_queues = array();
45

    
46
$pfctl_vsq = `/sbin/pfctl -vsq`;
47
$pfctl_vsq_array = split("\n", $pfctl_vsq);
48
foreach($pfctl_vsq_array as $pfctl) {
49
	if (preg_match_all("/queue\s+(\w+)\s+/",$pfctl,$match_array))
50
		if(stristr($match_array[1][0],"root_")==false)
51
			$a_queues[] = $match_array[1][0];	
52
}
53

    
54
?>
55
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
56
<html>
57
<head>
58
<title><?=gentitle("Status: Traffic shaper: Queues");?></title>
59
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
60
<link href="gui.css" rel="stylesheet" type="text/css">
61
</head>
62

    
63
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
64
<?php include("fbegin.inc"); ?>
65
<p class="pgtitle">Status: Traffic shaper: Queues</p>
66
<form action="status_queues.php" method="post">
67
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
68
                      <tr>
69
                        <td class="listhdr" colspan="1">Queue</td>
70
			<td class="listhdr" colspan="6">Statistics</td>
71
                      </tr>
72
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
73
		      <tr><td bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
74
                      <tr valign="top">
75
                        <td bgcolor="#DDDDDD">
76
                          <font color="#000000"><center>&nbsp;&nbsp;&nbsp;<?=htmlspecialchars($queue);?>&nbsp;&nbsp;&nbsp;</center></td>
77
			<td bgcolor="#DDDDDD">
78
			<nobr>
79
<?php
80
			$cpuUsage = 0;
81
			echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
82
			echo "<img src='bar_blue.gif' height='15' name='queue{$i}widtha' id='queue{$i}widtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
83
			echo "<img src='bar_gray.gif' height='15' name='queue{$i}widthb' id='queue{$i}widthb' width='" . (400 - $cpuUsage) . "' border='0' align='absmiddle'>";
84
			echo "<nobr><img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
85
			echo "</nobr></td></tr>";
86
			echo "<tr><td bgcolor=\"#DDDDDD\" colspan=\"7\">";
87
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
88
			echo "<nobr>";
89
			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'>";
90
			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'>";
91
			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'>";
92
			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'>";
93
			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'>";
94
			echo "</nobr>";
95
?>
96

    
97
			</td>
98
                      </tr>
99
		      <tr><td class="vncell" bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
100
                      <?php $i++; endforeach; $total_queues = $i; ?>
101
                    </table>
102
		    <p>
103
                    <strong><span class="red">Note:</span></strong><strong><br></strong>
104
		      Queue graphs take 5 seconds to sample data.
105
		    </p>
106
            </form>
107
<br><a href="status_queues.php?reset=true">Reset</a> queues if they do not load.
108
<?php include("fend.inc"); ?>
109
</body>
110
</html>
111

    
112
<?php
113

    
114
sleep(3);
115

    
116
$counter = 0;
117
While(!Connection_Aborted()) {
118

    
119
	$stats_array = gather_altq_queue_stats(true);
120

    
121
	/* calculate total packets being moved through all queues. */
122
	$total_packets_s = 0;
123
	foreach($stats_array as $stats_line) {
124
		$stat_line_split = split("\|", $stats_line);
125
		$total_packets_s = $total_packets_s + intval($stat_line_split[2]);
126
	}
127

    
128
	$i = 0;
129
	foreach($stats_array as $stats_line) {
130
		if($stat_line_split[2] == "" and $counter > 1) {
131
			mwexec("/usr/bin/killall -9 pfctl php");
132
			exit;
133
		}
134

    
135
		$stat_line_split = split("\|", $stats_line);
136
		$packet_sampled = intval($stat_line_split[2]);
137
		$speed = $stat_line_split[1];
138
		$borrows = intval($stat_line_split[3]);
139
		$suspends = intval($stat_line_split[4]);
140
		$drops = intval($stat_line_split[5]);
141

    
142
		echo "<script language='javascript'>\n";
143

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

    
146
		echo "document.queue{$i}widthb.style.width='{$packet_s}';\n";
147
		echo "document.queue{$i}widtha.style.width='" . (400 - $packet_s) . "';\n";
148
		$borrows_txt = "{$borrows} borrows";
149
		$suspends_txt = "{$suspends} suspends";
150
		$drops_txt = "${drops} drops";
151
		echo "document.forms[0].queue{$i}pps.value = '{$packet_sampled}/pps';\n";
152
		echo "document.forms[0].queue{$i}bps.value = '{$speed}';\n";
153
		echo "document.forms[0].queue{$i}borrows.value = '{$borrows_txt}';\n";
154
		echo "document.forms[0].queue{$i}suspends.value = '{$suspends_txt}';\n";
155
		echo "document.forms[0].queue{$i}drops.value = '{$drops_txt}';\n";
156
		echo "</script>\n";
157
		$i++;
158
	}
159

    
160
	/*
161
	 *   prevent user from running out of ram.
162
	 *   firefox and ie can be a bear on ram usage!
163
         */
164
	$counter++;
165
	if($counter > 20) {
166
		echo "Redirecting to <a href=\"status_queues.php\">Queue Status</a>.<p>";
167
		echo "<meta http-equiv=\"refresh\" content=\"1;url=status_queues.php\">";
168
		mwexec("/usr/bin/killall -9 pfctl");
169
		mwexec("/usr/bin/killall -9 pfctl php");
170
		exit;
171
	}
172
}
173

    
174
mwexec("/usr/bin/killall -9 pfctl pfctl");
175
mwexec("/usr/bin/killall -9 pfctl php");
176

    
177
?>
(92-92/117)