Project

General

Profile

Download (6.35 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
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
if($_GET['reset'] <> "") {
34
	mwexec("killall -9 pfctl pfctl");
35
	Header("Location: status_queues.php");
36
	exit;
37
}
38

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

    
43
$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

    
53
?>
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
              <table border="0" cellpadding="0" cellspacing="0">
67
                      <tr>
68
                        <td class="listhdr">Queue Stats</td>
69
                      </tr>
70
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
71
                      <tr valign="top">
72
                        <td class="listbg">
73
                          <font color="#FFFFFF"><?=htmlspecialchars($queue);?>
74
                          &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
			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
?>
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
		      Queue graphs take 5 seconds to sample data.
95
		    </p>
96
            </form>
97
<br><a href="status_queues.php?reset=true">Reset</a> queues if they do not load.
98
<?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
		$suspends = intval($stat_line_split[4]);
130
		$drops = intval($stat_line_split[5]);
131

    
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
		$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
		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
?>
(92-92/117)