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