Project

General

Profile

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