Project

General

Profile

Download (11.5 KB) Statistics
| Branch: | Tag: | Revision:
1 aa280d10 Bill Marquette
<?php
2
/*
3
	status_queues.php
4
*/
5 39881492 Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 9c1bbdef Stephen Beaver
 *
8 39881492 Stephen Beaver
 *	Redistribution and use in source and binary forms, with or without modification,
9
 *	are permitted provided that the following conditions are met:
10
 *
11
 *	1. Redistributions of source code must retain the above copyright notice,
12
 *		this list of conditions and the following disclaimer.
13
 *
14
 *	2. Redistributions in binary form must reproduce the above copyright
15
 *		notice, this list of conditions and the following disclaimer in
16
 *		the documentation and/or other materials provided with the
17
 *		distribution.
18
 *
19
 *	3. All advertising materials mentioning features or use of this software
20
 *		must display the following acknowledgment:
21
 *		"This product includes software developed by the pfSense Project
22
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
23
 *
24
 *	4. The names "pfSense" and "pfSense Project" must not be used to
25
 *		 endorse or promote products derived from this software without
26
 *		 prior written permission. For written permission, please contact
27
 *		 coreteam@pfsense.org.
28
 *
29
 *	5. Products derived from this software may not be called "pfSense"
30
 *		nor may "pfSense" appear in their names without prior written
31
 *		permission of the Electric Sheep Fencing, LLC.
32
 *
33
 *	6. Redistributions of any form whatsoever must retain the following
34
 *		acknowledgment:
35
 *
36
 *	"This product includes software developed by the pfSense Project
37
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
38
 *
39
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
40
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
43
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
51
 *
52
 *	====================================================================
53
 *
54
 */
55 aa280d10 Bill Marquette
56 6b07c15a Matthew Grooms
##|+PRIV
57
##|*IDENT=page-status-trafficshaper-queues
58 5230f468 jim-p
##|*NAME=Status: Traffic shaper: Queues
59 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Status: Traffic shaper: Queues' page.
60
##|*MATCH=status_queues.php*
61
##|-PRIV
62 39881492 Stephen Beaver
/*
63 42b0c921 Phil Davis
header("Last-Modified: " . gmdate("D, j M Y H:i:s") . " GMT");
64
header("Expires: " . gmdate("D, j M Y H:i:s", time()) . " GMT");
65
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP/1.1
66 5f471c95 Ermal
header("Pragma: no-cache"); // HTTP/1.0
67 39881492 Stephen Beaver
*/
68 5f471c95 Ermal
69 aa280d10 Bill Marquette
require("guiconfig.inc");
70 21b94a54 Michele Di Maria
class QueueStats {
71
	public $queuename;
72 2c5fda82 Jose Luis Duran
	public $queuelength;
73 6ba3121b Michele Di Maria
	public $pps;
74
	public $bandwidth;
75 21b94a54 Michele Di Maria
	public $borrows;
76
	public $suspends;
77
	public $drops;
78
}
79 3a1e12cf jim-p
if (!file_exists("{$g['varrun_path']}/qstats.pid") || !isvalidpid("{$g['varrun_path']}/qstats.pid")) {
80 9c1bbdef Stephen Beaver
	/* Start in the background so we don't hang up the GUI */
81 a3eab908 Michele Di Maria
	mwexec_bg("/usr/local/sbin/qstats -p {$g['varrun_path']}/qstats.pid");
82 9c1bbdef Stephen Beaver
	/* Give it a moment to start up */
83 3a1e12cf jim-p
	sleep(1);
84
}
85 5f471c95 Ermal
$fd = @fsockopen("unix://{$g['varrun_path']}/qstats");
86 42b0c921 Phil Davis
if (!$fd) {
87 8545adde k-paulius
	$error = gettext("Something wrong happened during communication with stat gathering.");
88 3a1e12cf jim-p
} else {
89
	$stats = "";
90 6c07db48 Phil Davis
	while (!feof($fd)) {
91 3a1e12cf jim-p
		$stats .= fread($fd, 4096);
92 42b0c921 Phil Davis
	}
93 3a1e12cf jim-p
	fclose($fd);
94
	@file_put_contents("{$g['tmp_path']}/qstats", $stats);
95
	$altqstats = @parse_xml_config("{$g['tmp_path']}/qstats", array("altqstats"));
96 42b0c921 Phil Davis
	if ($altqstats == -1) {
97 3bd74348 bruno
		$error = gettext("No queue statistics could be read.");
98 42b0c921 Phil Davis
	}
99 5f471c95 Ermal
}
100 2c5fda82 Jose Luis Duran
if ($_REQUEST['getactivity']) {
101 21b94a54 Michele Di Maria
	$statistics = array();
102 87428ee8 Michele Di Maria
	$bigger_stat = 0;
103
	$stat_type = $_REQUEST['stats'];
104 9c1bbdef Stephen Beaver
	/* build the queue stats. */
105 42b0c921 Phil Davis
	foreach ($altqstats['queue'] as $q) {
106 21b94a54 Michele Di Maria
		statsQueues($q);
107
	}
108 9c1bbdef Stephen Beaver
	/* calculate the bigger amount of packets or bandwidth being moved through all queues. */
109 6c07db48 Phil Davis
	if ($stat_type == "0") {
110 42b0c921 Phil Davis
		foreach ($statistics as $q) {
111
			if ($bigger_stat < $q->pps) {
112 87428ee8 Michele Di Maria
				$bigger_stat = $q->pps;
113 42b0c921 Phil Davis
			}
114 87428ee8 Michele Di Maria
		}
115 6c07db48 Phil Davis
	} else {
116 42b0c921 Phil Davis
		foreach ($statistics as $q) {
117
			if ($bigger_stat < $q->bandwidth) {
118 87428ee8 Michele Di Maria
				$bigger_stat = $q->bandwidth;
119 42b0c921 Phil Davis
			}
120 87428ee8 Michele Di Maria
		}
121 2c5fda82 Jose Luis Duran
	}
122 f2b8daad Ermal Lu?i
	$finscript = "";
123 42b0c921 Phil Davis
	foreach ($statistics as $q) {
124 17be206e Chris Buechler
		if ($stat_type == "0" && $bigger_stat != "0") {
125 9f605c1c Hari
			$packet_s = round(100 * ($q->pps / $bigger_stat), 0);
126 17be206e Chris Buechler
		} else if ($bigger_stat != "0") {
127 9f605c1c Hari
			$packet_s = round(100 * ($q->bandwidth / $bigger_stat), 0);
128 55a9ca07 Chris Buechler
		} else {
129 42b0c921 Phil Davis
			$packet_s = 0;
130
		}
131 3f98044a Francisco Cavalcante
		$finscript .= "$('#queue{$q->queuename}width').css('width','{$packet_s}%');";
132
		$finscript .= "$('#queue{$q->queuename}pps').val('" . number_format($q->pps, 1) . "');";
133
		$finscript .= "$('#queue{$q->queuename}bps').val('" . format_bits($q->bandwidth) . "');";
134
		$finscript .= "$('#queue{$q->queuename}borrows').val('{$q->borrows}');";
135
		$finscript .= "$('#queue{$q->queuename}suspends').val('{$q->suspends}');";
136
		$finscript .= "$('#queue{$q->queuename}drops').val('{$q->drops}');";
137
		$finscript .= "$('#queue{$q->queuename}length').val('{$q->queuelength}');";
138 21b94a54 Michele Di Maria
	}
139 b06abfe3 Michele Di Maria
	unset($statistics, $altqstats);
140 9c1bbdef Stephen Beaver
	header("Content-type: text/javascript");
141 f2b8daad Ermal Lu?i
	echo $finscript;
142 c5d63426 Bill Marquette
	exit;
143
}
144 f4741421 k-paulius
$pgtitle = array(gettext("Status"), gettext("Queues"));
145 9c1bbdef Stephen Beaver
$shortcut_section = "trafficshaper";
146
include("head.inc");
147 625c4a8b Stephen Beaver
148 9c1bbdef Stephen Beaver
if (!is_array($config['shaper']['queue']) || count($config['shaper']['queue']) < 1) {
149
	print_info_box(gettext("Traffic shaping is not configured."));
150
	include("foot.inc");
151
	exit;
152
}
153 625c4a8b Stephen Beaver
154
if (!$error): ?>
155 9c1bbdef Stephen Beaver
<form action="status_queues.php" method="post">
156
<script type="text/javascript">
157
//<![CDATA[
158 625c4a8b Stephen Beaver
events.push(function() {
159
160 9c1bbdef Stephen Beaver
	function getqueueactivity() {
161
		var url = "/status_queues.php";
162 3f98044a Francisco Cavalcante
		var pars = "getactivity=yes&stats=" + $("#selStatistic").val();
163
		$.ajax(
164 9c1bbdef Stephen Beaver
			url,
165
			{
166
				type: 'post',
167
				data: pars,
168
				complete: activitycallback
169
			});
170
	}
171 625c4a8b Stephen Beaver
172 9c1bbdef Stephen Beaver
	function activitycallback(transport) {
173 625c4a8b Stephen Beaver
		setTimeout(getqueueactivity, 5100);
174 9c1bbdef Stephen Beaver
	}
175 625c4a8b Stephen Beaver
176 3f98044a Francisco Cavalcante
	$(document).ready(function() {
177 625c4a8b Stephen Beaver
		setTimeout(getqueueactivity, 150);
178 9c1bbdef Stephen Beaver
	});
179 625c4a8b Stephen Beaver
});
180 9c1bbdef Stephen Beaver
//]]>
181
</script>
182
<?php endif;
183
184
if ($error):
185
	print_info_box($error);
186
else: ?>
187
	<div class="panel panel-default">
188
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Status Queues"); ?></h2></div>
189
		<div class="panel-body table-responsive">
190
			<table class="table table-striped table-hover">
191
				<thead>
192
					<tr>
193
						<th><?=gettext("Queue"); ?></th>
194
						<th><?=gettext("Statistics"); ?>
195 e9feb2d4 Stephen Beaver
							<select id="selStatistic" class="form-control">
196 3bd74348 bruno
								<option value="0"><?=gettext("PPS");?></option>
197
								<option value="1"><?=gettext("Bandwidth");?></option>
198 9c1bbdef Stephen Beaver
							</select>
199
						</th>
200
						<th><?=gettext("PPS"); ?></th>
201
						<th><?=gettext("Bandwidth"); ?></th>
202
						<th><?=gettext("Borrows"); ?></th>
203
						<th><?=gettext("Suspends"); ?></th>
204
						<th><?=gettext("Drops"); ?></th>
205
						<th><?=gettext("Length"); ?></th>
206
					</tr>
207
				</thead>
208
				<tbody>
209
<?php
210
	$if_queue_list = get_configured_interface_list_by_realif(false, true);
211
	processQueues($altqstats, 0, "");
212
?>
213
<?php endif; ?>
214
				</tbody>
215
			</table>
216 f78bbe16 Phil Davis
			<br />
217 c95dabdd Stephen Beaver
			<div class="infoblock blockopen">
218 9c1bbdef Stephen Beaver
<?php
219 8545adde k-paulius
	print_info_box(gettext("Queue graphs take 5 seconds to sample data."), 'info', false);
220 9c1bbdef Stephen Beaver
?>
221 f78bbe16 Phil Davis
			</div>
222 9c1bbdef Stephen Beaver
		</div>
223
	</div>
224 9cad1b8e Colin Fleming
<br/>
225 9c1bbdef Stephen Beaver
226
<script type="text/javascript">
227
//<![CDATA[
228
	function StatsShowHide(classname) {
229 3f98044a Francisco Cavalcante
		var firstrow = $("." + classname).first();
230 9c1bbdef Stephen Beaver
		if (firstrow.is(':visible')) {
231 3f98044a Francisco Cavalcante
			$("." + classname).hide();
232 9c1bbdef Stephen Beaver
		} else {
233 3f98044a Francisco Cavalcante
			$("." + classname).show();
234 9c1bbdef Stephen Beaver
		}
235
	}
236
//]]>
237
</script>
238
</form>
239
<?php
240
241
include("foot.inc");
242 9f605c1c Hari
243 42b0c921 Phil Davis
function processQueues($altqstats, $level, $parent_name) {
244 21b94a54 Michele Di Maria
	global $g;
245 6ba3121b Michele Di Maria
	global $if_queue_list;
246 ebfbb1b3 Stephen Beaver
247 ff3003df Michele Di Maria
	$parent_name = $parent_name . " queuerow" . $altqstats['name'] . $altqstats['interface'];
248 1679b68c Michele Di Maria
	$prev_if = $altqstats['interface'];
249 6ba3121b Michele Di Maria
	foreach ($altqstats['queue'] as $q) {
250
		$if_name = "";
251 1679b68c Michele Di Maria
		foreach ($if_queue_list as $oif => $real_name) {
252
			if ($oif == $q['interface']) {
253 6ba3121b Michele Di Maria
				$if_name = $real_name;
254
				break;
255
			}
256
		}
257 1679b68c Michele Di Maria
		if ($prev_if != $q['interface']) {
258 9cad1b8e Colin Fleming
			echo "<tr><td colspan=\"8\"><b>Interface " . htmlspecialchars(convert_real_interface_to_friendly_descr($q['interface'])) . "</b></td></tr>\n";
259 1679b68c Michele Di Maria
			$prev_if = $q['interface'];
260
		}
261 42b0c921 Phil Davis
?>
262 5c0ab3cd NewEraCracker
		<tr class="<?=$parent_name;?>">
263 ebfbb1b3 Stephen Beaver
			<td class="<?=$row_class?>" style="padding-left:<?=$level * 20?>px;">
264 9cad1b8e Colin Fleming
				<?php
265
				if (is_array($q['queue'])) {
266
					echo "<a href=\"#\" onclick=\"StatsShowHide('queuerow{$q['name']}{$q['interface']}');return false\">+/-</a>";
267
				}
268
				if (strstr($q['name'], "root_")) {
269
					echo "<a href=\"firewall_shaper.php?interface={$if_name}&amp;queue={$if_name}&amp;action=show\">Root queue</a>";
270
				} else {
271
					echo "<a href=\"firewall_shaper.php?interface={$if_name}&amp;queue={$q['name']}&amp;action=show\">" . htmlspecialchars($q['name']) . "</a>";
272
				}
273
				?>
274 ff3003df Michele Di Maria
			</td>
275 42b0c921 Phil Davis
<?php
276
		$cpuUsage = 0;
277 6c961924 Stephen Beaver
		print('<td>');
278 ebfbb1b3 Stephen Beaver
		print('<div class="progress" style="height: 7px;width: 170px;">');
279
		print('		<div class="progress-bar" role="progressbar" id="queue' . $q['name'] . $q['interface'] . 'width" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width: ' . $cpuUsage*100 . '%;\"></div>');
280
		print('	  </div>');
281
		print('</td>');
282 6c961924 Stephen Beaver
		print('<td><input readonly style="border:0;width:70px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'pps"      id="queue' . $q['name'] . $q['interface'] . 'pps"      value="(' . gettext("Loading") . ')" /></td>');
283
		print('<td><input readonly style="border:0;width:80px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'bps"      id="queue' . $q['name'] . $q['interface'] . 'bps"      value="" /></td>');
284
		print('<td><input readonly style="border:0;width:70px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'borrows"  id="queue' . $q['name'] . $q['interface'] . 'borrows"  value="" /></td>');
285
		print('<td><input readonly style="border:0;width:70px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'suspends" id="queue' . $q['name'] . $q['interface'] . 'suspends" value="" /></td>');
286
		print('<td><input readonly style="border:0;width:70px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'drops"    id="queue' . $q['name'] . $q['interface'] . 'drops"    value="" /></td>');
287
		print('<td><input readonly style="border:0;width:70px;text-align:right;" name="queue' . $q['name'] . $q['interface'] . 'length"   id="queue' . $q['name'] . $q['interface'] . 'length"   value="" /></td>');
288 42b0c921 Phil Davis
?>
289 21b94a54 Michele Di Maria
		</tr>
290 42b0c921 Phil Davis
<?php
291
		if (is_array($q['queue'])) {
292 ff3003df Michele Di Maria
			processQueues($q, $level + 1, $parent_name);
293 42b0c921 Phil Davis
		}
294 9c1bbdef Stephen Beaver
	};
295 21b94a54 Michele Di Maria
}
296 39881492 Stephen Beaver
297 42b0c921 Phil Davis
function statsQueues($xml) {
298 21b94a54 Michele Di Maria
	global $statistics;
299 b06abfe3 Michele Di Maria
300 21b94a54 Michele Di Maria
	$current = new QueueStats();
301
	$child = new QueueStats();
302
	$current->queuename = $xml['name'] . $xml['interface'];
303 2c5fda82 Jose Luis Duran
	$current->queuelength = $xml['qlength'];
304 ff3003df Michele Di Maria
	$current->pps = $xml['measured'];
305
	$current->bandwidth = $xml['measuredspeedint'];
306 21b94a54 Michele Di Maria
	$current->borrows = intval($xml['borrows']);
307
	$current->suspends = intval($xml['suspends']);
308 8e006931 Michele Di Maria
	$current->drops = intval($xml['droppedpkts']);
309 1679b68c Michele Di Maria
	if (is_array($xml['queue'])) {
310 42b0c921 Phil Davis
		foreach ($xml['queue'] as $q) {
311 21b94a54 Michele Di Maria
			$child = statsQueues($q);
312
			$current->pps += $child->pps;
313
			$current->bandwidth += $child->bandwidth;
314
			$current->borrows += $child->borrows;
315
			$current->suspends += $child->suspends;
316
			$current->drops += $child->drops;
317
		}
318
	}
319 a3eab908 Michele Di Maria
	unset($child);
320 21b94a54 Michele Di Maria
	$statistics[] = $current;
321
	return $current;
322
}
323 b06abfe3 Michele Di Maria
function format_bits($bits) {
324
	if ($bits >= 1000000000) {
325
		return sprintf("%.2f Gbps", $bits/1000000000);
326
	} else if ($bits >= 1000000) {
327
		return sprintf("%.2f Mbps", $bits/1000000);
328
	} else if ($bits >= 1000) {
329 31e41cf4 Michele Di Maria
		return sprintf("%.2f Kbps", $bits/1000);
330 b06abfe3 Michele Di Maria
	} else {
331 31e41cf4 Michele Di Maria
		return sprintf("%d bps", $bits);
332 b06abfe3 Michele Di Maria
	}
333
}
334 39881492 Stephen Beaver
?>