Project

General

Profile

Download (7.92 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 1d333258 Scott Ullrich
/*	
33
	pfSense_BUILDER_BINARIES:	/sbin/pfctl
34
	pfSense_MODULE:	shaper
35
*/
36 aa280d10 Bill Marquette
37 6b07c15a Matthew Grooms
##|+PRIV
38
##|*IDENT=page-status-trafficshaper-queues
39
##|*NAME=Status: Traffic shaper: Queues page
40
##|*DESCR=Allow access to the 'Status: Traffic shaper: Queues' page.
41
##|*MATCH=status_queues.php*
42
##|-PRIV
43
44 aa280d10 Bill Marquette
require("guiconfig.inc");
45
46 f2b8daad Ermal Lu?i
if ($_REQUEST['getactivity']) {
47
	$stats_array = gather_altq_queue_stats(true);
48
49
        /* calculate total packets being moved through all queues. */
50
        $total_packets_s = 0;
51
        foreach($stats_array as $stats_line) {
52
                $stat_line_split = split("\|", $stats_line);
53
                $total_packets_s = $total_packets_s + intval($stat_line_split[2]);
54
        }
55
56
        $i = 0;
57
	$finscript = "";
58
        foreach($stats_array as $stats_line) {
59
                if($stat_line_split[2] == "" and $counter > 1) {
60
                        continue;
61
                }
62
63
                $stat_line_split = split("\|", $stats_line);
64
                $packet_sampled = intval($stat_line_split[2]);
65
                $speed = $stat_line_split[1];
66
                $borrows = intval($stat_line_split[3]);
67
                $suspends = intval($stat_line_split[4]);
68
                $drops = intval($stat_line_split[5]);
69
70
71
                $packet_s = round(400 * (1 - $packet_sampled / $total_packets_s), 0);
72
73
                $finscript .= "$('queue{$i}widthb').width='{$packet_s}';";
74
                $finscript .= "$('queue{$i}widtha').width='" . (400 - $packet_s) . "';";
75
                $borrows_txt = "{$borrows} borrows";
76
                $suspends_txt = "{$suspends} suspends";
77
                $drops_txt = "${drops} drops";
78
                $finscript .= "$('queue{$i}pps').value = '{$packet_sampled}/pps';";
79
                $finscript .= "$('queue{$i}bps').value = '{$speed}';";
80
                $finscript .= "$('queue{$i}borrows').value = '{$borrows_txt}';";
81
                $finscript .= "$('queue{$i}suspends').value = '{$suspends_txt}';";
82
                $finscript .= "$('queue{$i}drops').value = '{$drops_txt}';";
83
                $i++;
84
        }
85
	header("Content-type: text/javascript");
86
	echo $finscript;
87 c5d63426 Bill Marquette
	exit;
88
}
89
90 4fc85b5d Scott Ullrich
$a_queues = array();
91
92 f2b8daad Ermal Lu?i
exec("/sbin/pfctl -vsq", $pfctl_vsq_array);
93 4fc85b5d Scott Ullrich
foreach($pfctl_vsq_array as $pfctl) {
94 05025c6e Ermal Luçi
	if (preg_match_all("/queue\s+(\w+)\s+(\w+)\s+(\w+)\s+/",$pfctl,$match_array)) {
95
		if (stristr($match_array[1][0],"root_"))
96
			continue;
97 78152bbd Ermal Luçi
               $a_queues[] = $match_array[1][0] . " on " .
98
				convert_real_interface_to_friendly_descr($match_array[3][0]);
99 05025c6e Ermal Luçi
	}
100 4fc85b5d Scott Ullrich
}
101 ad8d82ad Scott Ullrich
102 6deb0c03 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("Traffic shaper"),gettext("Queues"));
103 4df96eff Scott Ullrich
include("head.inc");
104
105 aa280d10 Bill Marquette
?>
106
107
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
108
<?php include("fbegin.inc"); ?>
109 d1dd0241 Scott Ullrich
<?php
110 f24f9829 Ermal Luçi
if(!is_array($config['shaper']['queue']) && count($config['shaper']['queue']) < 1) {
111 6deb0c03 Carlos Eduardo Ramos
	echo gettext("Traffic shaping is not configured.");
112 d1dd0241 Scott Ullrich
	include("fend.inc");
113
	exit;	
114
}
115
?>
116
117 aa280d10 Bill Marquette
<form action="status_queues.php" method="post">
118 f2b8daad Ermal Lu?i
<script type="text/javascript">
119
        function getqueueactivity() {
120
                var url = "/status_queues.php";
121
                var pars = 'getactivity=yes';
122
                var myAjax = new Ajax.Request(
123
                        url,
124
                        {
125
                                method: 'post',
126
                                parameters: pars,
127
                                onComplete: activitycallback
128
                        });
129
        }
130
        function activitycallback(transport) {
131
                setTimeout('getqueueactivity()', 5100);
132
        }
133 a3f1c10d Bill Marquette
        document.observe('dom:loaded', function(){
134
          setTimeout('getqueueactivity()', 150);
135
        });
136 f2b8daad Ermal Lu?i
</script>
137 8dc950ac Scott Ullrich
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
138 aa280d10 Bill Marquette
                      <tr>
139 6deb0c03 Carlos Eduardo Ramos
                        <td class="listhdr" colspan="1"><?=gettext("Queue"); ?></td>
140
			<td class="listhdr" colspan="6"><?=gettext("Statistics"); ?></td>
141 aa280d10 Bill Marquette
                      </tr>
142
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
143 8dc950ac Scott Ullrich
		      <tr><td bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
144 aa280d10 Bill Marquette
                      <tr valign="top">
145 8dc950ac Scott Ullrich
                        <td bgcolor="#DDDDDD">
146 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>
147 8dc950ac Scott Ullrich
			<td bgcolor="#DDDDDD">
148
			<nobr>
149 aa280d10 Bill Marquette
<?php
150
			$cpuUsage = 0;
151 f2b8daad Ermal Lu?i
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='10' width='4' border='0' align='absmiddle'>";
152
			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'>";
153
			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'>";
154
			echo "<nobr><img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='10' width='5' border='0' align='absmiddle'> ";
155 8dc950ac Scott Ullrich
			echo "</nobr></td></tr>";
156
			echo "<tr><td bgcolor=\"#DDDDDD\" colspan=\"7\">";
157 5f046df6 Scott Ullrich
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
158 8dc950ac Scott Ullrich
			echo "<nobr>";
159 6deb0c03 Carlos Eduardo Ramos
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}pps' id='queue{$i}pps' value='(" . gettext("Loading") . ")' align='left'>";
160 a3f1c10d Bill Marquette
			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'>";
161
			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'>";
162
			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'>";
163
			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'>";
164 8dc950ac Scott Ullrich
			echo "</nobr>";
165 aa280d10 Bill Marquette
?>
166
167
			</td>
168
                      </tr>
169 8dc950ac Scott Ullrich
		      <tr><td class="vncell" bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
170 aa280d10 Bill Marquette
                      <?php $i++; endforeach; $total_queues = $i; ?>
171
                    </table>
172
		    <p>
173 6deb0c03 Carlos Eduardo Ramos
                    <strong><span class="red"><?=gettext("Note"); ?>:</span></strong><strong><br></strong>
174
		      <?=gettext("Queue graphs take 5 seconds to sample data"); ?>.<br>
175
                      <?=gettext("You can configure the Traffic Shaper"); ?> <a href="/firewall_shaper_wizards.php"><?=gettext("here"); ?></a>.
176 aa280d10 Bill Marquette
		    </p>
177
            </form>
178
<?php include("fend.inc"); ?>
179
</body>
180
</html>