Project

General

Profile

Download (8.74 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
$shortcut_section = "trafficshaper";
103
include("head.inc");
104

    
105
?>
106

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

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