Project

General

Profile

Download (8.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
	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
	/* Start in the background so we don't hang up the GUI */
54
	mwexec_bg("/usr/local/sbin/qstats -p {$g['varrun_path']}/qstats.pid");
55
	/* Give it a moment to start up */
56
	sleep(1);
57
}
58

    
59
$fd = @fsockopen("unix://{$g['varrun_path']}/qstats");
60
if (!$fd) {
61
	$error = "Something wrong happened during comunication with stat gathering";
62
} else {
63
	$stats = "";
64
	while(!feof($fd))
65
		$stats .= fread($fd, 4096);
66
	fclose($fd);
67
	@file_put_contents("{$g['tmp_path']}/qstats", $stats);
68
	$altqstats = @parse_xml_config("{$g['tmp_path']}/qstats", array("altqstats"));
69
	if ($altqstats == -1)
70
		$error = "No queue statistics could be read.";
71
}
72
if ($_REQUEST['getactivity']) {
73
        /* calculate total packets being moved through all queues. */
74
        $total_packets_s = 0;
75
        foreach($altqstats['queue'] as $q) {
76
		if (strstr($q['name'], "root_"))
77
			continue;
78
                $total_packets_s = $total_packets_s + intval($q['pkts']);
79
        }
80

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

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

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

    
101
$pgtitle = array(gettext("Status"),gettext("Traffic shaper"),gettext("Queues"));
102
include("head.inc");
103

    
104
?>
105

    
106
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
107
<?php include("fbegin.inc"); ?>
108
<?php
109
if(!is_array($config['shaper']['queue']) || count($config['shaper']['queue']) < 1) {
110
	echo gettext("Traffic shaping is not configured.");
111
	include("fend.inc");
112
	exit;	
113
}
114
?>
115
<?php if (!$error): ?>
116
<form action="status_queues.php" method="post">
117
<script type="text/javascript">
118
        function getqueueactivity() {
119
                var url = "/status_queues.php";
120
                var pars = 'getactivity=yes';
121
                jQuery.ajax(
122
                        url,
123
                        {
124
                                type: 'post',
125
                                data: pars,
126
                                complete: activitycallback
127
                        });
128
        }
129
        function activitycallback(transport) {
130
                setTimeout('getqueueactivity()', 5100);
131
        }
132
        jQuery(document).ready(function(){
133
          setTimeout('getqueueactivity()', 150);
134
        });
135
</script>
136
<?php endif; ?>
137
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
138
<?php if ($error): ?>
139
		<tr><td><?php echo $error; ?></td></tr>
140
<?php else: ?>
141
                      <tr>
142
                        <td class="listhdr" colspan="1"><?=gettext("Queue"); ?></td>
143
			<td class="listhdr" colspan="6"><?=gettext("Statistics"); ?></td>
144
                      </tr>
145
                      <?php $i = 0; foreach ($altqstats['queue'] as $q): 
146
				if (strstr($q['name'], "root_"))
147
					continue;
148
			?>
149
		      <tr><td bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
150
                      <tr valign="top">
151
                        <td bgcolor="#DDDDDD">
152
                          <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>
153
			<td bgcolor="#DDDDDD">
154
			<nobr>
155
<?php
156
			$cpuUsage = 0;
157
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='10' width='4' border='0' align='absmiddle'>";
158
			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'>";
159
			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'>";
160
			echo "<nobr><img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='10' width='5' border='0' align='absmiddle'> ";
161
			echo "</nobr></td></tr>";
162
			echo "<tr><td bgcolor=\"#DDDDDD\" colspan=\"7\">";
163
			echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
164
			echo "<nobr>";
165
			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'>";
166
			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'>";
167
			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'>";
168
			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'>";
169
			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'>";
170
			echo "</nobr>";
171
?>
172

    
173
			</td>
174
                      </tr>
175
		      <tr><td class="vncell" bgcolor="#DDDDDD" colspan="7">&nbsp;</td></tr>
176
                      <?php $i++; endforeach; $total_queues = $i; ?>
177
<?php endif; ?>
178
                    </table>
179
		    <p>
180
                    <strong><span class="red"><?=gettext("Note"); ?>:</span></strong><strong><br></strong>
181
		      <?=gettext("Queue graphs take 5 seconds to sample data"); ?>.<br>
182
                      <?=gettext("You can configure the Traffic Shaper"); ?> <a href="/firewall_shaper_wizards.php"><?=gettext("here"); ?></a>.
183
		    </p>
184
<?php include("fend.inc"); ?>
185
</body>
186
</html>
(188-188/247)