Project

General

Profile

Download (6.08 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 php");
35
	exit;
36
}
37

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

    
43
?>
44
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
45
<html>
46
<head>
47
<title><?=gentitle("Status: Traffic shaper: Queues");?></title>
48
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
49
<link href="gui.css" rel="stylesheet" type="text/css">
50
</head>
51

    
52
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
53
<?php include("fbegin.inc"); ?>
54
<p class="pgtitle">Status: Traffic shaper: Queues</p>
55
<form action="status_queues.php" method="post">
56
              <table border="0" cellpadding="0" cellspacing="0">
57
                      <tr>
58
                        <td class="listhdr">Queue Stats</td>
59
                      </tr>
60
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
61
                      <tr valign="top">
62
                        <td class="listbg">
63
                          <font color="#FFFFFF"><?=htmlspecialchars($queue['name']);?>
64
                          &nbsp;<br>
65
<?php
66
			$cpuUsage = 0;
67
			echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
68
			echo "<img src='bar_blue.gif' height='15' name='queue{$i}widtha' id='queue{$i}widtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
69
			echo "<img src='bar_gray.gif' height='15' name='queue{$i}widthb' id='queue{$i}widthb' width='" . (400 - $cpuUsage) . "' border='0' align='absmiddle'>";
70
			echo "<nobr><img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
71
			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'>";
72
			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'>";
73
			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'>";
74
			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'>";
75
			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>";
76
?>
77

    
78
			</td>
79
                      </tr>
80
                      <?php $i++; endforeach; $total_queues = $i; ?>
81
                    </table>
82
		    <p>
83
                    <strong><span class="red">Note:</span></strong><strong><br></strong>
84
		      Queue graphs take 5 seconds to sample data.
85
		    </p>
86
            </form>
87
<br><a href="status_queues.php?reset=true">Reset</a> queues if they do not load.
88
<?php include("fend.inc"); ?>
89
</body>
90
</html>
91

    
92
<?php
93

    
94
sleep(3);
95

    
96
$counter = 0;
97
While(!Connection_Aborted()) {
98

    
99
	$stats_array = gather_altq_queue_stats(true);
100

    
101
	/* calculate total packets being moved through all queues. */
102
	$total_packets_s = 0;
103
	foreach($stats_array as $stats_line) {
104
		$stat_line_split = split("\|", $stats_line);
105
		$total_packets_s = $total_packets_s + intval($stat_line_split[2]);
106
	}
107

    
108
	$i = 0;
109
	foreach($stats_array as $stats_line) {
110
		if($stat_line_split[2] == "" and $counter > 1) {
111
			mwexec("/usr/bin/killall -9 pfctl php");
112
			exit;
113
		}
114

    
115
		$stat_line_split = split("\|", $stats_line);
116
		$packet_sampled = intval($stat_line_split[2]);
117
		$speed = $stat_line_split[1];
118
		$borrows = intval($stat_line_split[3]);
119
		$suspends = intval($stat_line_split[4]);
120
		$drops = intval($stat_line_split[5]);
121

    
122
		echo "<script language='javascript'>\n";
123

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

    
126
		echo "document.queue{$i}widthb.style.width='{$packet_s}';\n";
127
		echo "document.queue{$i}widtha.style.width='" . (400 - $packet_s) . "';\n";
128
		$borrows_txt = "{$borrows} borrows";
129
		$suspends_txt = "{$suspends} suspends";
130
		$drops_txt = "${drops} drops";
131
		echo "document.forms[0].queue{$i}pps.value = '{$packet_sampled}/pps';\n";
132
		echo "document.forms[0].queue{$i}bps.value = '{$speed}';\n";
133
		echo "document.forms[0].queue{$i}borrows.value = '{$borrows_txt}';\n";
134
		echo "document.forms[0].queue{$i}suspends.value = '{$suspends_txt}';\n";
135
		echo "document.forms[0].queue{$i}drops.value = '{$drops_txt}';\n";
136
		echo "</script>\n";
137
		$i++;
138
	}
139

    
140
	/*
141
	 *   prevent user from running out of ram.
142
	 *   firefox and ie can be a bear on ram usage!
143
         */
144
	$counter++;
145
	if($counter > 40) {
146
		echo "Redirecting to <a href=\"status_queues.php\">Queue Status</a>.<p>";
147
		echo "<meta http-equiv=\"refresh\" content=\"1;url=status_queues.php\">";
148
		mwexec("/usr/bin/killall -9 pfctl");
149
		exit;
150
	}
151
}
152

    
153
mwexec("/usr/bin/killall -9 pfctl php");
154

    
155
?>
(91-91/115)