Project

General

Profile

Download (12.2 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 ce77a9c4 Phil Davis
	Part of the pfSense project
7 dd447bde Jim Thompson
	Copyright (C) 2004, 2005 Scott Ullrich
8 29aef6c4 Jim Thompson
	Copyright (C) 2009 Ermal Luçi
9 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
10 aa280d10 Bill Marquette
	All rights reserved.
11
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33 2c5fda82 Jose Luis Duran
/*
34 1d333258 Scott Ullrich
	pfSense_BUILDER_BINARIES:	/sbin/pfctl
35
	pfSense_MODULE:	shaper
36
*/
37 aa280d10 Bill Marquette
38 6b07c15a Matthew Grooms
##|+PRIV
39
##|*IDENT=page-status-trafficshaper-queues
40
##|*NAME=Status: Traffic shaper: Queues page
41
##|*DESCR=Allow access to the 'Status: Traffic shaper: Queues' page.
42
##|*MATCH=status_queues.php*
43
##|-PRIV
44
45 5f471c95 Ermal
header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT" );
46
header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT" );
47 2ebbb0bc Jose Luis Duran
header("Cache-Control: no-cache, no-store, must-revalidate" ); // HTTP/1.1
48 5f471c95 Ermal
header("Pragma: no-cache"); // HTTP/1.0
49
50 aa280d10 Bill Marquette
require("guiconfig.inc");
51 21b94a54 Michele Di Maria
class QueueStats {
52
	public $queuename;
53 2c5fda82 Jose Luis Duran
	public $queuelength;
54 6ba3121b Michele Di Maria
	public $pps;
55
	public $bandwidth;
56 21b94a54 Michele Di Maria
	public $borrows;
57
	public $suspends;
58
	public $drops;
59
}
60 3a1e12cf jim-p
if (!file_exists("{$g['varrun_path']}/qstats.pid") || !isvalidpid("{$g['varrun_path']}/qstats.pid")) {
61 2c5fda82 Jose Luis Duran
	/* Start in the background so we don't hang up the GUI */
62 a3eab908 Michele Di Maria
	mwexec_bg("/usr/local/sbin/qstats -p {$g['varrun_path']}/qstats.pid");
63 3a1e12cf jim-p
	/* Give it a moment to start up */
64
	sleep(1);
65
}
66 5f471c95 Ermal
$fd = @fsockopen("unix://{$g['varrun_path']}/qstats");
67 21b94a54 Michele Di Maria
 if (!$fd) {
68 3a1e12cf jim-p
	$error = "Something wrong happened during comunication with stat gathering";
69
} else {
70
	$stats = "";
71
	while(!feof($fd))
72
		$stats .= fread($fd, 4096);
73
	fclose($fd);
74
	@file_put_contents("{$g['tmp_path']}/qstats", $stats);
75
	$altqstats = @parse_xml_config("{$g['tmp_path']}/qstats", array("altqstats"));
76
	if ($altqstats == -1)
77
		$error = "No queue statistics could be read.";
78 5f471c95 Ermal
}
79 2c5fda82 Jose Luis Duran
if ($_REQUEST['getactivity']) {
80 21b94a54 Michele Di Maria
	$statistics = array();
81 87428ee8 Michele Di Maria
	$bigger_stat = 0;
82
	$stat_type = $_REQUEST['stats'];
83 21b94a54 Michele Di Maria
	/* build the queue stats. */
84
	foreach($altqstats['queue'] as $q) {
85
		statsQueues($q);
86
	}
87 87428ee8 Michele Di Maria
	/* calculate the bigger amount of packets or bandwidth being moved through all queues. */
88
	if ($stat_type == "0")
89
	{
90
		foreach($statistics as $q) {
91
			if ($bigger_stat < $q->pps)
92
				$bigger_stat = $q->pps;
93
		}
94 21b94a54 Michele Di Maria
	}
95 87428ee8 Michele Di Maria
	else
96
	{
97
		foreach($statistics as $q) {
98
			if ($bigger_stat < $q->bandwidth)
99
				$bigger_stat = $q->bandwidth;
100
		}
101 2c5fda82 Jose Luis Duran
	}
102 f2b8daad Ermal Lu?i
	$finscript = "";
103 21b94a54 Michele Di Maria
	foreach($statistics as $q) {
104 87428ee8 Michele Di Maria
		if ($stat_type == "0")
105
			$packet_s = round(150 * (1 - $q->pps / $bigger_stat), 0);
106
		else
107
			$packet_s = round(150 * (1 - $q->bandwidth / $bigger_stat), 0);
108 21b94a54 Michele Di Maria
		if ($packet_s < 0) {$packet_s = 0;}
109
		$finscript .= "jQuery('#queue{$q->queuename}widthb').width('{$packet_s}');";
110 8e006931 Michele Di Maria
		$finscript .= "jQuery('#queue{$q->queuename}widtha').width('" . (150 - $packet_s) . "');";
111 ff3003df Michele Di Maria
		$finscript .= "jQuery('#queue{$q->queuename}pps').val('" . number_format($q->pps,1) . "');";
112 b06abfe3 Michele Di Maria
		$finscript .= "jQuery('#queue{$q->queuename}bps').val('" . format_bits($q->bandwidth) . "');";
113 21b94a54 Michele Di Maria
		$finscript .= "jQuery('#queue{$q->queuename}borrows').val('{$q->borrows}');";
114
		$finscript .= "jQuery('#queue{$q->queuename}suspends').val('{$q->suspends}');";
115
		$finscript .= "jQuery('#queue{$q->queuename}drops').val('{$q->drops}');";
116 8e006931 Michele Di Maria
		$finscript .= "jQuery('#queue{$q->queuename}length').val('{$q->queuelength}');";
117 21b94a54 Michele Di Maria
	}
118 b06abfe3 Michele Di Maria
	unset($statistics, $altqstats);
119 f2b8daad Ermal Lu?i
	header("Content-type: text/javascript");
120
	echo $finscript;
121 c5d63426 Bill Marquette
	exit;
122
}
123 6deb0c03 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("Traffic shaper"),gettext("Queues"));
124 d71fc5d3 jim-p
$shortcut_section = "trafficshaper";
125 4df96eff Scott Ullrich
include("head.inc");
126 aa280d10 Bill Marquette
?>
127
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
128
<?php include("fbegin.inc"); ?>
129 d1dd0241 Scott Ullrich
<?php
130 3a1e12cf jim-p
if(!is_array($config['shaper']['queue']) || count($config['shaper']['queue']) < 1) {
131 6deb0c03 Carlos Eduardo Ramos
	echo gettext("Traffic shaping is not configured.");
132 d1dd0241 Scott Ullrich
	include("fend.inc");
133 580a6561 Colin Fleming
	echo "</body></html>";
134 21b94a54 Michele Di Maria
	exit;}
135 d1dd0241 Scott Ullrich
?>
136 3a1e12cf jim-p
<?php if (!$error): ?>
137 aa280d10 Bill Marquette
<form action="status_queues.php" method="post">
138 f2b8daad Ermal Lu?i
<script type="text/javascript">
139 d456b043 Colin Fleming
//<![CDATA[
140 21b94a54 Michele Di Maria
	function getqueueactivity() {
141
		var url = "/status_queues.php";
142 87428ee8 Michele Di Maria
		var pars = "getactivity=yes&stats=" + jQuery("#selStatistic").val();
143 21b94a54 Michele Di Maria
		jQuery.ajax(
144
			url,
145
			{
146
				type: 'post',
147
				data: pars,
148
				complete: activitycallback
149
			});
150
	}
151
	function activitycallback(transport) {
152
		setTimeout('getqueueactivity()', 5100);
153
	}
154
	jQuery(document).ready(function(){
155
		setTimeout('getqueueactivity()', 150);
156
	});
157 d456b043 Colin Fleming
//]]>
158 f2b8daad Ermal Lu?i
</script>
159 3a1e12cf jim-p
<?php endif; ?>
160 d456b043 Colin Fleming
<table width="100%" border="1" cellpadding="0" cellspacing="0" summary="status queues">
161 3a1e12cf jim-p
<?php if ($error): ?>
162 21b94a54 Michele Di Maria
	<tr><td><?php echo $error; ?></td></tr>
163 3a1e12cf jim-p
<?php else: ?>
164 21b94a54 Michele Di Maria
	<tr>
165
		<td class="listhdr"><?=gettext("Queue"); ?></td>
166 87428ee8 Michele Di Maria
		<td class="listhdr">
167
			<?=gettext("Statistics"); ?>
168
			<select id="selStatistic">
169
				<option value="0">PPS</option>
170
				<option value="1">Bandwidth</option>
171
			</select>
172
		</td>
173 21b94a54 Michele Di Maria
		<td class="listhdr" width="1%"><?=gettext("PPS"); ?></td>
174
		<td class="listhdr" width="1%"><?=gettext("Bandwidth"); ?></td>
175
		<td class="listhdr" width="1%"><?=gettext("Borrows"); ?></td>
176
		<td class="listhdr" width="1%"><?=gettext("Suspends"); ?></td>
177
		<td class="listhdr" width="1%"><?=gettext("Drops"); ?></td>
178 2c5fda82 Jose Luis Duran
		<td class="listhdr" width="1%"><?=gettext("Length"); ?></td>
179 21b94a54 Michele Di Maria
	</tr>
180 2c5fda82 Jose Luis Duran
	<?php
181 6ba3121b Michele Di Maria
	$if_queue_list = get_configured_interface_list_by_realif(false, true);
182 ff3003df Michele Di Maria
	processQueues($altqstats, 0, "")?>
183 3a1e12cf jim-p
<?php endif; ?>
184 21b94a54 Michele Di Maria
</table>
185
<p>
186 8cd558b6 ayvis
	<strong><span class="red"><?=gettext("Note"); ?>:</span></strong><br />
187
	<?=gettext("Queue graphs take 5 seconds to sample data"); ?>.<br />
188 21b94a54 Michele Di Maria
	<?=gettext("You can configure the Traffic Shaper"); ?> <a href="/firewall_shaper_wizards.php"><?=gettext("here"); ?></a>.
189
</p>
190 ff3003df Michele Di Maria
<script type="text/javascript">
191 d456b043 Colin Fleming
//<![CDATA[
192 ff3003df Michele Di Maria
	function StatsShowHide(classname) {
193
    var firstrow = jQuery("." + classname).first();
194
    if (firstrow.is(':visible')) {
195
        jQuery("." + classname).hide();}
196
    else {
197
        jQuery("." + classname).show();}
198
	}
199 d456b043 Colin Fleming
//]]>
200 ff3003df Michele Di Maria
</script>
201 84903059 Michele Di Maria
</form>
202 aa280d10 Bill Marquette
<?php include("fend.inc"); ?>
203
</body>
204
</html>
205 2c5fda82 Jose Luis Duran
<?php
206 ff3003df Michele Di Maria
function processQueues($altqstats, $level, $parent_name){
207 21b94a54 Michele Di Maria
	global $g;
208 6ba3121b Michele Di Maria
	global $if_queue_list;
209 ff3003df Michele Di Maria
	$gray_value = 190 + $level * 10;
210
	if ($gray_value > 250) $gray_value = 255;
211
	$row_background = str_repeat(dechex($gray_value), 3);
212
	$parent_name = $parent_name . " queuerow" . $altqstats['name'] . $altqstats['interface'];
213 1679b68c Michele Di Maria
	$prev_if = $altqstats['interface'];
214 6ba3121b Michele Di Maria
	foreach ($altqstats['queue'] as $q) {
215
		$if_name = "";
216 1679b68c Michele Di Maria
		foreach ($if_queue_list as $oif => $real_name) {
217
			if ($oif == $q['interface']) {
218 6ba3121b Michele Di Maria
				$if_name = $real_name;
219
				break;
220
			}
221
		}
222 1679b68c Michele Di Maria
		if ($prev_if != $q['interface']) {
223
			echo "<tr><td colspan=\"8\" style=\"padding: 2px;\"><b>Interface ". htmlspecialchars(convert_real_interface_to_friendly_descr($q['interface'])) . "</b></td></tr>";
224
			$prev_if = $q['interface'];
225
		}
226 6ba3121b Michele Di Maria
		?>
227 ff3003df Michele Di Maria
		<tr class="<?php echo $parent_name?>">
228
			<td bgcolor="#<?php echo $row_background?>" style="padding-left: <?php echo $level * 20?>px;">
229 21b94a54 Michele Di Maria
				<font color="#000000">
230
					<?
231
					if (strstr($q['name'], "root_"))
232 84903059 Michele Di Maria
						echo "<a href=\"firewall_shaper.php?interface={$if_name}&amp;queue={$if_name}&amp;action=show\">Root queue</a>";
233 21b94a54 Michele Di Maria
					else
234 84903059 Michele Di Maria
						echo "<a href=\"firewall_shaper.php?interface={$if_name}&amp;queue={$q['name']}&amp;action=show\">" . htmlspecialchars($q['name']) . "</a>";
235 21b94a54 Michele Di Maria
					?>
236
				</font>
237 ff3003df Michele Di Maria
			</td>
238 21b94a54 Michele Di Maria
			<?php
239
			$cpuUsage = 0;
240 d456b043 Colin Fleming
			echo "<td class=\"nowrap\" width=\"1%\" bgcolor=\"#{$row_background}\">";
241 84903059 Michele Di Maria
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='10' width='4' border='0' align='middle' alt='' />";
242
			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='middle' alt='" . htmlspecialchars($q['name']) . "' />";
243
			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='" . (150 - $cpuUsage) . "' border='0' align='middle' alt='" . htmlspecialchars($q['name']) . "' />";
244
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='10' width='5' border='0' align='middle' alt='' /> ";
245 ff3003df Michele Di Maria
			if (is_array($q['queue'])) {
246 8e006931 Michele Di Maria
				echo "<a href=\"#\" onclick=\"StatsShowHide('queuerow{$q['name']}{$q['interface']}');return false\">+/-</a> ";
247 ff3003df Michele Di Maria
			}
248 84903059 Michele Di Maria
			echo " </td>";
249
			echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:70px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}pps' id='queue{$q['name']}{$q['interface']}pps' value='(" . gettext("Loading") . ")' align='left' /></td>";
250
			echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:80px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}bps' id='queue{$q['name']}{$q['interface']}bps' value='' align='right' /></td>";
251
			echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:70px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}borrows' id='queue{$q['name']}{$q['interface']}borrows' value='' align='right' /></td>";
252
			echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:70px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}suspends' id='queue{$q['name']}{$q['interface']}suspends' value='' align='right' /></td>";
253
			echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:70px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}drops' id='queue{$q['name']}{$q['interface']}drops' value='' align='right' /></td>";
254 2c5fda82 Jose Luis Duran
			echo "<td width=\"1%\" bgcolor=\"#{$row_background}\"><input style='border: 0px solid white; background-color:#{$row_background}; color:#000000;width:70px;text-align:right;' size='10' name='queue{$q['name']}{$q['interface']}length' id='queue{$q['name']}{$q['interface']}length' value='' align='right' /></td>";
255 21b94a54 Michele Di Maria
			?>
256
		</tr>
257 6ba3121b Michele Di Maria
		<?php
258 21b94a54 Michele Di Maria
		if (is_array($q['queue']))
259 ff3003df Michele Di Maria
			processQueues($q, $level + 1, $parent_name);
260 21b94a54 Michele Di Maria
	};
261
}
262
function statsQueues($xml){
263
	global $statistics;
264 b06abfe3 Michele Di Maria
265 21b94a54 Michele Di Maria
	$current = new QueueStats();
266
	$child = new QueueStats();
267
	$current->queuename = $xml['name'] . $xml['interface'];
268 2c5fda82 Jose Luis Duran
	$current->queuelength = $xml['qlength'];
269 ff3003df Michele Di Maria
	$current->pps = $xml['measured'];
270
	$current->bandwidth = $xml['measuredspeedint'];
271 21b94a54 Michele Di Maria
	$current->borrows = intval($xml['borrows']);
272
	$current->suspends = intval($xml['suspends']);
273 8e006931 Michele Di Maria
	$current->drops = intval($xml['droppedpkts']);
274 1679b68c Michele Di Maria
	if (is_array($xml['queue'])) {
275 21b94a54 Michele Di Maria
		foreach($xml['queue'] as $q) {
276
			$child = statsQueues($q);
277
			$current->pps += $child->pps;
278
			$current->bandwidth += $child->bandwidth;
279
			$current->borrows += $child->borrows;
280
			$current->suspends += $child->suspends;
281
			$current->drops += $child->drops;
282
		}
283
	}
284 a3eab908 Michele Di Maria
	unset($child);
285 21b94a54 Michele Di Maria
	$statistics[] = $current;
286
	return $current;
287
}
288 b06abfe3 Michele Di Maria
function format_bits($bits) {
289
	if ($bits >= 1000000000) {
290
		return sprintf("%.2f Gbps", $bits/1000000000);
291
	} else if ($bits >= 1000000) {
292
		return sprintf("%.2f Mbps", $bits/1000000);
293
	} else if ($bits >= 1000) {
294 31e41cf4 Michele Di Maria
		return sprintf("%.2f Kbps", $bits/1000);
295 b06abfe3 Michele Di Maria
	} else {
296 31e41cf4 Michele Di Maria
		return sprintf("%d bps", $bits);
297 b06abfe3 Michele Di Maria
	}
298
}
299 73eeee93 Michele Di Maria
?>