Project

General

Profile

Download (7.7 KB) Statistics
| Branch: | Tag: | Revision:
1 b5b351be Scott Ullrich
#!/usr/local/bin/php
2 aa280d10 Bill Marquette
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 aa280d10 Bill Marquette
/*
5
	status_queues.php
6 8dc950ac Scott Ullrich
        Part of the pfSense project
7 aa280d10 Bill Marquette
	Copyright (C) 2004, 2005 Scott Ullrich
8 78225e5b Ermal Lu?i
	Copyright (C) 2009 Ermal Lu?i
9 aa280d10 Bill Marquette
	All rights reserved.
10
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33 6b07c15a Matthew Grooms
##|+PRIV
34
##|*IDENT=page-status-trafficshaper-queues
35
##|*NAME=Status: Traffic shaper: Queues page
36
##|*DESCR=Allow access to the 'Status: Traffic shaper: Queues' page.
37
##|*MATCH=status_queues.php*
38
##|-PRIV
39
40
41 aa280d10 Bill Marquette
require("guiconfig.inc");
42
43 f2b8daad Ermal Lu?i
if ($_REQUEST['getactivity']) {
44
	$stats_array = gather_altq_queue_stats(true);
45
46
        /* calculate total packets being moved through all queues. */
47
        $total_packets_s = 0;
48
        foreach($stats_array as $stats_line) {
49
                $stat_line_split = split("\|", $stats_line);
50
                $total_packets_s = $total_packets_s + intval($stat_line_split[2]);
51
        }
52
53
        $i = 0;
54
	$finscript = "";
55
        foreach($stats_array as $stats_line) {
56
                if($stat_line_split[2] == "" and $counter > 1) {
57
                        continue;
58
                }
59
60
                $stat_line_split = split("\|", $stats_line);
61
                $packet_sampled = intval($stat_line_split[2]);
62
                $speed = $stat_line_split[1];
63
                $borrows = intval($stat_line_split[3]);
64
                $suspends = intval($stat_line_split[4]);
65
                $drops = intval($stat_line_split[5]);
66
67
68
                $packet_s = round(400 * (1 - $packet_sampled / $total_packets_s), 0);
69
70
                $finscript .= "$('queue{$i}widthb').width='{$packet_s}';";
71
                $finscript .= "$('queue{$i}widtha').width='" . (400 - $packet_s) . "';";
72
                $borrows_txt = "{$borrows} borrows";
73
                $suspends_txt = "{$suspends} suspends";
74
                $drops_txt = "${drops} drops";
75
                $finscript .= "$('queue{$i}pps').value = '{$packet_sampled}/pps';";
76
                $finscript .= "$('queue{$i}bps').value = '{$speed}';";
77
                $finscript .= "$('queue{$i}borrows').value = '{$borrows_txt}';";
78
                $finscript .= "$('queue{$i}suspends').value = '{$suspends_txt}';";
79
                $finscript .= "$('queue{$i}drops').value = '{$drops_txt}';";
80
                $i++;
81
        }
82
	header("Content-type: text/javascript");
83
	echo $finscript;
84 c5d63426 Bill Marquette
	exit;
85
}
86
87 4fc85b5d Scott Ullrich
$a_queues = array();
88
89 f2b8daad Ermal Lu?i
exec("/sbin/pfctl -vsq", $pfctl_vsq_array);
90 4fc85b5d Scott Ullrich
foreach($pfctl_vsq_array as $pfctl) {
91 05025c6e Ermal Luçi
	if (preg_match_all("/queue\s+(\w+)\s+(\w+)\s+(\w+)\s+/",$pfctl,$match_array)) {
92
		if (stristr($match_array[1][0],"root_"))
93
			continue;
94 78152bbd Ermal Luçi
               $a_queues[] = $match_array[1][0] . " on " .
95
				convert_real_interface_to_friendly_descr($match_array[3][0]);
96 05025c6e Ermal Luçi
	}
97 4fc85b5d Scott Ullrich
}
98 ad8d82ad Scott Ullrich
99 d88c6a9f Scott Ullrich
$pgtitle = array("Status","Traffic shaper","Queues");
100 4df96eff Scott Ullrich
include("head.inc");
101
102 aa280d10 Bill Marquette
?>
103
104
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
105
<?php include("fbegin.inc"); ?>
106 d1dd0241 Scott Ullrich
<?php
107 f24f9829 Ermal Luçi
if(!is_array($config['shaper']['queue']) && count($config['shaper']['queue']) < 1) {
108
	echo "Traffic shaping is not configured.";
109 d1dd0241 Scott Ullrich
	include("fend.inc");
110
	exit;	
111
}
112
?>
113
114 aa280d10 Bill Marquette
<form action="status_queues.php" method="post">
115 f2b8daad Ermal Lu?i
<script type="text/javascript">
116
        function getqueueactivity() {
117
                var url = "/status_queues.php";
118
                var pars = 'getactivity=yes';
119
                var myAjax = new Ajax.Request(
120
                        url,
121
                        {
122
                                method: 'post',
123
                                parameters: pars,
124
                                onComplete: activitycallback
125
                        });
126
        }
127
        function activitycallback(transport) {
128
                setTimeout('getqueueactivity()', 5100);
129
        }
130 a3f1c10d Bill Marquette
        document.observe('dom:loaded', function(){
131
          setTimeout('getqueueactivity()', 150);
132
        });
133 f2b8daad Ermal Lu?i
</script>
134 8dc950ac Scott Ullrich
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
135 aa280d10 Bill Marquette
                      <tr>
136 8dc950ac Scott Ullrich
                        <td class="listhdr" colspan="1">Queue</td>
137
			<td class="listhdr" colspan="6">Statistics</td>
138 aa280d10 Bill Marquette
                      </tr>
139
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
140 8dc950ac Scott Ullrich
		      <tr><td bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
141 aa280d10 Bill Marquette
                      <tr valign="top">
142 8dc950ac Scott Ullrich
                        <td bgcolor="#DDDDDD">
143 197bfe96 Ermal Luçi
                          <font color="#000000">&nbsp;&nbsp;&nbsp;<?echo "<a href=\"firewall_shaper.php?id={$queue}\">" . htmlspecialchars($queue) . "</a>";?>&nbsp;&nbsp;&nbsp;</td>
144 8dc950ac Scott Ullrich
			<td bgcolor="#DDDDDD">
145
			<nobr>
146 aa280d10 Bill Marquette
<?php
147
			$cpuUsage = 0;
148 f2b8daad Ermal Lu?i
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='10' width='4' border='0' align='absmiddle'>";
149
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='10' name='queue{$i}widtha' id='queue{$i}widtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
150
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='10' name='queue{$i}widthb' id='queue{$i}widthb' width='" . (400 - $cpuUsage) . "' border='0' align='absmiddle'>";
151
			echo "<nobr><img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='10' width='5' border='0' align='absmiddle'> ";
152 8dc950ac Scott Ullrich
			echo "</nobr></td></tr>";
153
			echo "<tr><td bgcolor=\"#DDDDDD\" colspan=\"7\">";
154 5f046df6 Scott Ullrich
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
155 8dc950ac Scott Ullrich
			echo "<nobr>";
156 a3f1c10d Bill Marquette
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}pps' id='queue{$i}pps' value='(Loading)' align='left'>";
157
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}bps' id='queue{$i}bps' value='' align='right'>";
158
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}borrows' id='queue{$i}borrows' value='' align='right'>";
159
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}suspends' id='queue{$i}suspends' value='' align='right'>";
160
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}drops' id='queue{$i}drops' value='' align='right'>";
161 8dc950ac Scott Ullrich
			echo "</nobr>";
162 aa280d10 Bill Marquette
?>
163
164
			</td>
165
                      </tr>
166 8dc950ac Scott Ullrich
		      <tr><td class="vncell" bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
167 aa280d10 Bill Marquette
                      <?php $i++; endforeach; $total_queues = $i; ?>
168
                    </table>
169
		    <p>
170
                    <strong><span class="red">Note:</span></strong><strong><br></strong>
171 c55a8ab9 Holger Bauer
		      Queue graphs take 5 seconds to sample data.<br>
172 af32f939 Scott Ullrich
                      You can configure the Traffic Shaper <a href="firewall_shaper.php?reset=true">here</a>.
173 aa280d10 Bill Marquette
		    </p>
174
            </form>
175
<?php include("fend.inc"); ?>
176
</body>
177
</html>