Project

General

Profile

Download (7.7 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	status_queues.php
6
        Part of the pfSense project
7
	Copyright (C) 2004, 2005 Scott Ullrich
8
	Copyright (C) 2009 Ermal Lu?i
9
	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
##|+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
require("guiconfig.inc");
42

    
43
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
	exit;
85
}
86

    
87
$a_queues = array();
88

    
89
exec("/sbin/pfctl -vsq", $pfctl_vsq_array);
90
foreach($pfctl_vsq_array as $pfctl) {
91
	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
               $a_queues[] = $match_array[1][0] . " on " .
95
				convert_real_interface_to_friendly_descr($match_array[3][0]);
96
	}
97
}
98

    
99
$pgtitle = array("Status","Traffic shaper","Queues");
100
include("head.inc");
101

    
102
?>
103

    
104
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
105
<?php include("fbegin.inc"); ?>
106
<?php
107
if(!is_array($config['shaper']['queue']) && count($config['shaper']['queue']) < 1) {
108
	echo "Traffic shaping is not configured.";
109
	include("fend.inc");
110
	exit;	
111
}
112
?>
113

    
114
<form action="status_queues.php" method="post">
115
<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
        document.observe('dom:loaded', function(){
131
          setTimeout('getqueueactivity()', 150);
132
        });
133
</script>
134
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
135
                      <tr>
136
                        <td class="listhdr" colspan="1">Queue</td>
137
			<td class="listhdr" colspan="6">Statistics</td>
138
                      </tr>
139
                      <?php $i = 0; foreach ($a_queues as $queue): ?>
140
		      <tr><td bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
141
                      <tr valign="top">
142
                        <td bgcolor="#DDDDDD">
143
                          <font color="#000000">&nbsp;&nbsp;&nbsp;<?echo "<a href=\"firewall_shaper.php?id={$queue}\">" . htmlspecialchars($queue) . "</a>";?>&nbsp;&nbsp;&nbsp;</td>
144
			<td bgcolor="#DDDDDD">
145
			<nobr>
146
<?php
147
			$cpuUsage = 0;
148
			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
			echo "</nobr></td></tr>";
153
			echo "<tr><td bgcolor=\"#DDDDDD\" colspan=\"7\">";
154
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
155
			echo "<nobr>";
156
			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
			echo "</nobr>";
162
?>
163

    
164
			</td>
165
                      </tr>
166
		      <tr><td class="vncell" bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
167
                      <?php $i++; endforeach; $total_queues = $i; ?>
168
                    </table>
169
		    <p>
170
                    <strong><span class="red">Note:</span></strong><strong><br></strong>
171
		      Queue graphs take 5 seconds to sample data.<br>
172
                      You can configure the Traffic Shaper <a href="firewall_shaper.php?reset=true">here</a>.
173
		    </p>
174
            </form>
175
<?php include("fend.inc"); ?>
176
</body>
177
</html>
(149-149/206)