Project

General

Profile

Download (11.7 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 8dc950ac Scott Ullrich
        Part of the pfSense project
7 aa280d10 Bill Marquette
	Copyright (C) 2004, 2005 Scott Ullrich
8 73eeee93 Michele Di Maria
	Copyright (C) 2009 Ermal Luçi
9 aa280d10 Bill Marquette
	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 1d333258 Scott Ullrich
/*	
33
	pfSense_BUILDER_BINARIES:	/sbin/pfctl
34
	pfSense_MODULE:	shaper
35
*/
36 aa280d10 Bill Marquette
37 6b07c15a Matthew Grooms
##|+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 5f471c95 Ermal
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 aa280d10 Bill Marquette
require("guiconfig.inc");
51 21b94a54 Michele Di Maria
class QueueStats {
52
	public $queuename;
53 8e006931 Michele Di Maria
	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 21b94a54 Michele Di Maria
	/* 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 21b94a54 Michele Di Maria
if ($_REQUEST['getactivity']) {	
80
	$statistics = array();
81
	$bigger_packets = 0;
82
	/* build the queue stats. */
83
	foreach($altqstats['queue'] as $q) {
84
		statsQueues($q);
85
	}
86
	/* calculate the bigger amount of packets being moved through all queues. */
87
	foreach($statistics as $q) {
88
		if ($bigger_packets < $q->pps)
89 b06abfe3 Michele Di Maria
			$bigger_packets = $q->pps;
90 21b94a54 Michele Di Maria
	}
91 f2b8daad Ermal Lu?i
	$finscript = "";
92 21b94a54 Michele Di Maria
	foreach($statistics as $q) {
93 8e006931 Michele Di Maria
		$packet_s = round(150 * (1 - $q->pps / $bigger_packets), 0);
94 21b94a54 Michele Di Maria
		if ($packet_s < 0) {$packet_s = 0;}
95
		$finscript .= "jQuery('#queue{$q->queuename}widthb').width('{$packet_s}');";
96 8e006931 Michele Di Maria
		$finscript .= "jQuery('#queue{$q->queuename}widtha').width('" . (150 - $packet_s) . "');";
97 ff3003df Michele Di Maria
		$finscript .= "jQuery('#queue{$q->queuename}pps').val('" . number_format($q->pps,1) . "');";
98 b06abfe3 Michele Di Maria
		$finscript .= "jQuery('#queue{$q->queuename}bps').val('" . format_bits($q->bandwidth) . "');";
99 21b94a54 Michele Di Maria
		$finscript .= "jQuery('#queue{$q->queuename}borrows').val('{$q->borrows}');";
100
		$finscript .= "jQuery('#queue{$q->queuename}suspends').val('{$q->suspends}');";
101
		$finscript .= "jQuery('#queue{$q->queuename}drops').val('{$q->drops}');";
102 8e006931 Michele Di Maria
		$finscript .= "jQuery('#queue{$q->queuename}length').val('{$q->queuelength}');";
103 21b94a54 Michele Di Maria
	}
104 b06abfe3 Michele Di Maria
	unset($statistics, $altqstats);
105 f2b8daad Ermal Lu?i
	header("Content-type: text/javascript");
106
	echo $finscript;
107 c5d63426 Bill Marquette
	exit;
108
}
109 6deb0c03 Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("Traffic shaper"),gettext("Queues"));
110 d71fc5d3 jim-p
$shortcut_section = "trafficshaper";
111 4df96eff Scott Ullrich
include("head.inc");
112 aa280d10 Bill Marquette
?>
113
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
114
<?php include("fbegin.inc"); ?>
115 d1dd0241 Scott Ullrich
<?php
116 3a1e12cf jim-p
if(!is_array($config['shaper']['queue']) || count($config['shaper']['queue']) < 1) {
117 6deb0c03 Carlos Eduardo Ramos
	echo gettext("Traffic shaping is not configured.");
118 d1dd0241 Scott Ullrich
	include("fend.inc");
119 21b94a54 Michele Di Maria
	exit;}
120 d1dd0241 Scott Ullrich
?>
121 3a1e12cf jim-p
<?php if (!$error): ?>
122 aa280d10 Bill Marquette
<form action="status_queues.php" method="post">
123 f2b8daad Ermal Lu?i
<script type="text/javascript">
124 21b94a54 Michele Di Maria
	function getqueueactivity() {
125
		var url = "/status_queues.php";
126
		var pars = 'getactivity=yes';
127
		jQuery.ajax(
128
			url,
129
			{
130
				type: 'post',
131
				data: pars,
132
				complete: activitycallback
133
			});
134
	}
135
	function activitycallback(transport) {
136
		setTimeout('getqueueactivity()', 5100);
137
	}
138
	jQuery(document).ready(function(){
139
		setTimeout('getqueueactivity()', 150);
140
	});
141 f2b8daad Ermal Lu?i
</script>
142 3a1e12cf jim-p
<?php endif; ?>
143 21b94a54 Michele Di Maria
<table width="100%" border="1" cellpadding="0" cellspacing="0">
144 3a1e12cf jim-p
<?php if ($error): ?>
145 21b94a54 Michele Di Maria
	<tr><td><?php echo $error; ?></td></tr>
146 3a1e12cf jim-p
<?php else: ?>
147 21b94a54 Michele Di Maria
	<tr>
148
		<td class="listhdr"><?=gettext("Queue"); ?></td>
149
		<td class="listhdr"><?=gettext("Statistics"); ?></td>
150
		<td class="listhdr" width="1%"><?=gettext("PPS"); ?></td>
151
		<td class="listhdr" width="1%"><?=gettext("Bandwidth"); ?></td>
152
		<td class="listhdr" width="1%"><?=gettext("Borrows"); ?></td>
153
		<td class="listhdr" width="1%"><?=gettext("Suspends"); ?></td>
154
		<td class="listhdr" width="1%"><?=gettext("Drops"); ?></td>
155 8e006931 Michele Di Maria
		<td class="listhdr" width="1%"><?=gettext("Length"); ?></td>		
156 21b94a54 Michele Di Maria
	</tr>
157 6ba3121b Michele Di Maria
	<?php 
158
	$if_queue_list = get_configured_interface_list_by_realif(false, true);
159 ff3003df Michele Di Maria
	processQueues($altqstats, 0, "")?>
160 3a1e12cf jim-p
<?php endif; ?>
161 21b94a54 Michele Di Maria
</table>
162
<p>
163 84903059 Michele Di Maria
	<strong><span class="red"><?=gettext("Note"); ?>:</span></strong><br/>
164
	<?=gettext("Queue graphs take 5 seconds to sample data"); ?>.<br/>
165 21b94a54 Michele Di Maria
	<?=gettext("You can configure the Traffic Shaper"); ?> <a href="/firewall_shaper_wizards.php"><?=gettext("here"); ?></a>.
166
</p>
167 ff3003df Michele Di Maria
<script type="text/javascript">
168
	function StatsShowHide(classname) {
169
    var firstrow = jQuery("." + classname).first();
170
    if (firstrow.is(':visible')) {
171
        jQuery("." + classname).hide();}
172
    else {
173
        jQuery("." + classname).show();}
174
	}
175
</script>
176 84903059 Michele Di Maria
</form>
177 aa280d10 Bill Marquette
<?php include("fend.inc"); ?>
178
</body>
179
</html>
180 21b94a54 Michele Di Maria
<?php 
181 ff3003df Michele Di Maria
function processQueues($altqstats, $level, $parent_name){
182 21b94a54 Michele Di Maria
	global $g;
183 6ba3121b Michele Di Maria
	global $if_queue_list;
184 ff3003df Michele Di Maria
	$gray_value = 190 + $level * 10;
185
	if ($gray_value > 250) $gray_value = 255;
186
	$row_background = str_repeat(dechex($gray_value), 3);
187
	$parent_name = $parent_name . " queuerow" . $altqstats['name'] . $altqstats['interface'];
188 1679b68c Michele Di Maria
	$prev_if = $altqstats['interface'];
189 6ba3121b Michele Di Maria
	foreach ($altqstats['queue'] as $q) {
190
		$if_name = "";
191 1679b68c Michele Di Maria
		foreach ($if_queue_list as $oif => $real_name) {
192
			if ($oif == $q['interface']) {
193 6ba3121b Michele Di Maria
				$if_name = $real_name;
194
				break;
195
			}
196
		}
197 1679b68c Michele Di Maria
		if ($prev_if != $q['interface']) {
198
			echo "<tr><td colspan=\"8\" style=\"padding: 2px;\"><b>Interface ". htmlspecialchars(convert_real_interface_to_friendly_descr($q['interface'])) . "</b></td></tr>";
199
			$prev_if = $q['interface'];
200
		}
201 6ba3121b Michele Di Maria
		?>
202 ff3003df Michele Di Maria
		<tr class="<?php echo $parent_name?>">
203
			<td bgcolor="#<?php echo $row_background?>" style="padding-left: <?php echo $level * 20?>px;">
204 21b94a54 Michele Di Maria
				<font color="#000000">
205
					<?
206
					if (strstr($q['name'], "root_"))
207 84903059 Michele Di Maria
						echo "<a href=\"firewall_shaper.php?interface={$if_name}&amp;queue={$if_name}&amp;action=show\">Root queue</a>";
208 21b94a54 Michele Di Maria
					else
209 84903059 Michele Di Maria
						echo "<a href=\"firewall_shaper.php?interface={$if_name}&amp;queue={$q['name']}&amp;action=show\">" . htmlspecialchars($q['name']) . "</a>";
210 21b94a54 Michele Di Maria
					?>
211
				</font>
212 ff3003df Michele Di Maria
			</td>
213 21b94a54 Michele Di Maria
			<?php
214
			$cpuUsage = 0;
215 84903059 Michele Di Maria
			echo "<td nowrap=\"nowrap\" width=\"1%\" bgcolor=\"#{$row_background}\">";
216
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='10' width='4' border='0' align='middle' alt='' />";
217
			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']) . "' />";
218
			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']) . "' />";
219
			echo "<img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='10' width='5' border='0' align='middle' alt='' /> ";
220 ff3003df Michele Di Maria
			if (is_array($q['queue'])) {
221 8e006931 Michele Di Maria
				echo "<a href=\"#\" onclick=\"StatsShowHide('queuerow{$q['name']}{$q['interface']}');return false\">+/-</a> ";
222 ff3003df Michele Di Maria
			}
223 84903059 Michele Di Maria
			echo " </td>";
224
			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>";
225
			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>";
226
			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>";
227
			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>";
228
			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>";
229
			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>";			
230 21b94a54 Michele Di Maria
			?>
231
		</tr>
232 6ba3121b Michele Di Maria
		<?php
233 21b94a54 Michele Di Maria
		if (is_array($q['queue']))
234 ff3003df Michele Di Maria
			processQueues($q, $level + 1, $parent_name);
235 21b94a54 Michele Di Maria
	};
236
}
237
function statsQueues($xml){
238
	global $statistics;
239 b06abfe3 Michele Di Maria
240 21b94a54 Michele Di Maria
	$current = new QueueStats();
241
	$child = new QueueStats();
242
	$current->queuename = $xml['name'] . $xml['interface'];
243 8e006931 Michele Di Maria
	$current->queuelength = $xml['qlength'];		
244 ff3003df Michele Di Maria
	$current->pps = $xml['measured'];
245
	$current->bandwidth = $xml['measuredspeedint'];
246 21b94a54 Michele Di Maria
	$current->borrows = intval($xml['borrows']);
247
	$current->suspends = intval($xml['suspends']);
248 8e006931 Michele Di Maria
	$current->drops = intval($xml['droppedpkts']);
249 1679b68c Michele Di Maria
	if (is_array($xml['queue'])) {
250 21b94a54 Michele Di Maria
		foreach($xml['queue'] as $q) {
251
			$child = statsQueues($q);
252
			$current->pps += $child->pps;
253
			$current->bandwidth += $child->bandwidth;
254
			$current->borrows += $child->borrows;
255
			$current->suspends += $child->suspends;
256
			$current->drops += $child->drops;
257
		}
258
	}
259 a3eab908 Michele Di Maria
	unset($child);
260 21b94a54 Michele Di Maria
	$statistics[] = $current;
261
	return $current;
262
}
263 b06abfe3 Michele Di Maria
function format_bits($bits) {
264
	if ($bits >= 1000000000) {
265
		return sprintf("%.2f Gbps", $bits/1000000000);
266
	} else if ($bits >= 1000000) {
267
		return sprintf("%.2f Mbps", $bits/1000000);
268
	} else if ($bits >= 1000) {
269 31e41cf4 Michele Di Maria
		return sprintf("%.2f Kbps", $bits/1000);
270 b06abfe3 Michele Di Maria
	} else {
271 31e41cf4 Michele Di Maria
		return sprintf("%d bps", $bits);
272 b06abfe3 Michele Di Maria
	}
273
}
274 73eeee93 Michele Di Maria
?>