Project

General

Profile

Download (8.43 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
	pfSense_BUILDER_BINARIES:	/sbin/pfctl
34
	pfSense_MODULE:	shaper
35
*/
36

    
37
##|+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
header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
45
header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT" );
46
header("Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1
47
header("Cache-Control: post-check=0, pre-check=0", FALSE );
48
header("Pragma: no-cache"); // HTTP/1.0
49

    
50
require("guiconfig.inc");
51

    
52
if (!file_exists("{$g['varrun_path']}/qstats.pid") || !isvalidpid("{$g['varrun_path']}/qstats.pid"))
53
	mwexec("/usr/local/sbin/qstats -p {$g['varrun_path']}/qstats.pid");
54

    
55
$fd = @fsockopen("unix://{$g['varrun_path']}/qstats");
56
if (!$fd) {
57
	log_error("Something wrong happened during comunication with stat gathering");
58
	header("Location: /status_queues.php");
59
	exit;
60
}
61
$stats = "";
62
while(!feof($fd))
63
	$stats .= fread($fd, 4096);
64
fclose($fd);
65

    
66
@file_put_contents("{$g['tmp_path']}/qstats", $stats);
67
$altqstats = @parse_xml_config("{$g['tmp_path']}/qstats", array("altqstats"));
68

    
69
if ($_REQUEST['getactivity']) {
70
        /* calculate total packets being moved through all queues. */
71
        $total_packets_s = 0;
72
        foreach($altqstats['queue'] as $q) {
73
		if (strstr($q['name'], "root_"))
74
			continue;
75
                $total_packets_s = $total_packets_s + intval($q['pkts']);
76
        }
77

    
78
	$finscript = "";
79
        foreach($altqstats['queue'] as $q) {
80
		if (strstr($q['name'], "root_"))
81
			continue;
82

    
83
                $packet_s = round(400 * (1 - $q['pkts']/ $total_packets_s), 0);
84

    
85
                $finscript .= "jQuery('#queue{$q['name']}{$q['interface']}widthb').width('{$packet_s}');";
86
                $finscript .= "jQuery('#queue{$q['name']}{$q['interface']}widtha').width('" . (400 - $packet_s) . "');";
87
                $finscript .= "jQuery('#queue{$q['name']}{$q['interface']}pps').val('{$q['measured']}/pps');";
88
                $finscript .= "jQuery('#queue{$q['name']}{$q['interface']}bps').val('{$q['measuredspeed']}');";
89
                $finscript .= "jQuery('#queue{$q['name']}{$q['interface']}borrows').val('{$q['borrows']} borrows');";
90
                $finscript .= "jQuery('#queue{$q['name']}{$q['interface']}suspends').val('{$q['suspends']} suspends');";
91
                $finscript .= "jQuery('#queue{$q['name']}{$q['interface']}drops').val('{$q['droppedpkts']} drops');";
92
        }
93
	header("Content-type: text/javascript");
94
	echo $finscript;
95
	exit;
96
}
97

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

    
101
?>
102

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

    
113
<form action="status_queues.php" method="post">
114
<script type="text/javascript">
115
        function getqueueactivity() {
116
                var url = "/status_queues.php";
117
                var pars = 'getactivity=yes';
118
                jQuery.ajax(
119
                        url,
120
                        {
121
                                type: 'post',
122
                                data: pars,
123
                                complete: activitycallback
124
                        });
125
        }
126
        function activitycallback(transport) {
127
                setTimeout('getqueueactivity()', 5100);
128
        }
129
        jQuery(document).ready(function(){
130
          setTimeout('getqueueactivity()', 150);
131
        });
132
</script>
133
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
134
                      <tr>
135
                        <td class="listhdr" colspan="1"><?=gettext("Queue"); ?></td>
136
			<td class="listhdr" colspan="6"><?=gettext("Statistics"); ?></td>
137
                      </tr>
138
                      <?php $i = 0; foreach ($altqstats['queue'] as $q): 
139
				if (strstr($q['name'], "root_"))
140
					continue;
141
			?>
142
		      <tr><td bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
143
                      <tr valign="top">
144
                        <td bgcolor="#DDDDDD">
145
                          <font color="#000000">&nbsp;&nbsp;&nbsp;<?echo "<a href=\"firewall_shaper.php?id={$q['name']}\">" . htmlspecialchars($q['name'] . " on " . convert_real_interface_to_friendly_descr($q['interface'])) . "</a>";?>&nbsp;&nbsp;&nbsp;</td>
146
			<td bgcolor="#DDDDDD">
147
			<nobr>
148
<?php
149
			$cpuUsage = 0;
150
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='10' width='4' border='0' align='absmiddle'>";
151
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='10' name='queue{$q['name']}{$q['interface']}widtha' id='queue{$q['name']}{$q['interface']}widtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
152
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='10' name='queue{$q['name']}{$q['interface']}widthb' id='queue{$q['name']}{$q['interface']}widthb' width='" . (400 - $cpuUsage) . "' border='0' align='absmiddle'>";
153
			echo "<nobr><img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='10' width='5' border='0' align='absmiddle'> ";
154
			echo "</nobr></td></tr>";
155
			echo "<tr><td bgcolor=\"#DDDDDD\" colspan=\"7\">";
156
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
157
			echo "<nobr>";
158
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$q['name']}{$q['interface']}pps' id='queue{$q['name']}{$q['interface']}pps' value='(" . gettext("Loading") . ")' align='left'>";
159
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$q['name']}{$q['interface']}bps' id='queue{$q['name']}{$q['interface']}bps' value='' align='right'>";
160
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$q['name']}{$q['interface']}borrows' id='queue{$q['name']}{$q['interface']}borrows' value='' align='right'>";
161
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$q['name']}{$q['interface']}suspends' id='queue{$q['name']}{$q['interface']}suspends' value='' align='right'>";
162
			echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$q['name']}{$q['interface']}drops' id='queue{$q['name']}{$q['interface']}drops' value='' align='right'>";
163
			echo "</nobr>";
164
?>
165

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