Project

General

Profile

« Previous | Next » 

Revision 9c1bbdef

Added by Stephen Beaver almost 10 years ago

Revision to teh file to fix header issues

View differences:

src/usr/local/www/status_queues.php
6 6
/* ====================================================================
7 7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8 8
 *	Copyright (c)  2004, 2005 Scott Ullrich
9
 *	Copyright (c)  2009 Ermal Luçi
9
 *
10 10
 *	Redistribution and use in source and binary forms, with or without modification,
11 11
 *	are permitted provided that the following conditions are met:
12 12
 *
......
65 65
##|*DESCR=Allow access to the 'Status: Traffic shaper: Queues' page.
66 66
##|*MATCH=status_queues.php*
67 67
##|-PRIV
68

  
69 68
/*
70 69
header("Last-Modified: " . gmdate("D, j M Y H:i:s") . " GMT");
71 70
header("Expires: " . gmdate("D, j M Y H:i:s", time()) . " GMT");
......
74 73
*/
75 74

  
76 75
require("guiconfig.inc");
77

  
78 76
class QueueStats {
79 77
	public $queuename;
80 78
	public $queuelength;
......
84 82
	public $suspends;
85 83
	public $drops;
86 84
}
87

  
88 85
if (!file_exists("{$g['varrun_path']}/qstats.pid") || !isvalidpid("{$g['varrun_path']}/qstats.pid")) {
89
	// Start in the background so we don't hang up the GUI
86
	/* Start in the background so we don't hang up the GUI */
90 87
	mwexec_bg("/usr/local/sbin/qstats -p {$g['varrun_path']}/qstats.pid");
91
	// Give it a moment to start up
88
	/* Give it a moment to start up */
92 89
	sleep(1);
93 90
}
94

  
95 91
$fd = @fsockopen("unix://{$g['varrun_path']}/qstats");
96

  
97 92
if (!$fd) {
98 93
	$error = "Something wrong happened during communication with stat gathering";
99 94
} else {
......
108 103
		$error = "No queue statistics could be read.";
109 104
	}
110 105
}
111

  
112 106
if ($_REQUEST['getactivity']) {
113 107
	$statistics = array();
114 108
	$bigger_stat = 0;
115 109
	$stat_type = $_REQUEST['stats'];
116
	// build the queue stats.
110
	/* build the queue stats. */
117 111
	foreach ($altqstats['queue'] as $q) {
118 112
		statsQueues($q);
119 113
	}
120
	// calculate the bigger amount of packets or bandwidth being moved through all queues.
114
	/* calculate the bigger amount of packets or bandwidth being moved through all queues. */
121 115
	if ($stat_type == "0") {
122 116
		foreach ($statistics as $q) {
123 117
			if ($bigger_stat < $q->pps) {
......
131 125
			}
132 126
		}
133 127
	}
134

  
135 128
	$finscript = "";
136 129
	foreach ($statistics as $q) {
137 130
		if ($stat_type == "0") {
......
142 135
		if ($packet_s < 0) {
143 136
			$packet_s = 0;
144 137
		}
145

  
146
		$finscript .= '<script src="/jquery/jquery-1.11.2.min.js"></script>';
147
		$finscript .= '<script>';
148 138
		$finscript .= "jQuery('#queue{$q->queuename}width').css('width','{$packet_s}%');";
149 139
		$finscript .= "jQuery('#queue{$q->queuename}pps').val('" . number_format($q->pps, 1) . "');";
150 140
		$finscript .= "jQuery('#queue{$q->queuename}bps').val('" . format_bits($q->bandwidth) . "');";
......
152 142
		$finscript .= "jQuery('#queue{$q->queuename}suspends').val('{$q->suspends}');";
153 143
		$finscript .= "jQuery('#queue{$q->queuename}drops').val('{$q->drops}');";
154 144
		$finscript .= "jQuery('#queue{$q->queuename}length').val('{$q->queuelength}');";
155
		$finscript .= '</script>';
156 145
	}
157

  
158 146
	unset($statistics, $altqstats);
159
//	header("Content-type: text/javascript");
147
	header("Content-type: text/javascript");
160 148
	echo $finscript;
161 149
	exit;
162 150
}
151
$pgtitle = array(gettext("Status"), gettext("Traffic shaper"), gettext("Queues"));
152
$shortcut_section = "trafficshaper";
153
include("head.inc");
154
?>
155
<body>
156
<script src="/jquery/jquery-1.11.2.min.js"></script>
157
<?php
158
if (!is_array($config['shaper']['queue']) || count($config['shaper']['queue']) < 1) {
159
	print_info_box(gettext("Traffic shaping is not configured."));
160
	include("foot.inc");
161
	exit;
162
}
163
?>
164
<?php if (!$error): ?>
165
<form action="status_queues.php" method="post">
166
<script type="text/javascript">
167
//<![CDATA[
168
	function getqueueactivity() {
169
		var url = "/status_queues.php";
170
		var pars = "getactivity=yes&stats=" + jQuery("#selStatistic").val();
171
		jQuery.ajax(
172
			url,
173
			{
174
				type: 'post',
175
				data: pars,
176
				complete: activitycallback
177
			});
178
	}
179
	function activitycallback(transport) {
180
		setTimeout('getqueueactivity()', 5100);
181
	}
182
	jQuery(document).ready(function() {
183
		setTimeout('getqueueactivity()', 150);
184
	});
185
//]]>
186
</script>
187
<?php endif;
188

  
189
if ($error):
190
	print_info_box($error);
191
else: ?>
192
	<div class="panel panel-default">
193
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Status Queues"); ?></h2></div>
194
		<div class="panel-body table-responsive">
195
			<table class="table table-striped table-hover">
196
				<thead>
197
					<tr>
198
						<th><?=gettext("Queue"); ?></th>
199
						<th><?=gettext("Statistics"); ?>
200
							<select id="selStatistic">
201
								<option value="0">PPS</option>
202
								<option value="1">Bandwidth</option>
203
							</select>
204
						</th>
205
						<th><?=gettext("PPS"); ?></th>
206
						<th><?=gettext("Bandwidth"); ?></th>
207
						<th><?=gettext("Borrows"); ?></th>
208
						<th><?=gettext("Suspends"); ?></th>
209
						<th><?=gettext("Drops"); ?></th>
210
						<th><?=gettext("Length"); ?></th>
211
					</tr>
212
				</thead>
213
				<tbody>
214
<?php
215
	$if_queue_list = get_configured_interface_list_by_realif(false, true);
216
	processQueues($altqstats, 0, "");
217
?>
218
<?php endif; ?>
219
				</tbody>
220
			</table>
221
		<br />
222
<?php
223
		print_info_box(gettext("Queue graphs take 5 seconds to sample data"));
224
?>
225
		</div>
226
	</div>
227
</br>
228

  
229
<?php
230

  
231

  
232

  
233
?>
234

  
235
<script type="text/javascript">
236
//<![CDATA[
237
	function StatsShowHide(classname) {
238
		var firstrow = jQuery("." + classname).first();
239
		if (firstrow.is(':visible')) {
240
			jQuery("." + classname).hide();
241
		} else {
242
			jQuery("." + classname).show();
243
		}
244
	}
245
//]]>
246
</script>
247
</form>
248
<?php
249

  
250
include("foot.inc");
163 251

  
164 252
function processQueues($altqstats, $level, $parent_name) {
165 253
	global $g;
......
171 259
	$row_background = str_repeat(dechex($gray_value), 3);
172 260
	$parent_name = $parent_name . " queuerow" . $altqstats['name'] . $altqstats['interface'];
173 261
	$prev_if = $altqstats['interface'];
174

  
175 262
	foreach ($altqstats['queue'] as $q) {
176 263
		$if_name = "";
177 264
		foreach ($if_queue_list as $oif => $real_name) {
......
180 267
				break;
181 268
			}
182 269
		}
183

  
184 270
		if ($prev_if != $q['interface']) {
185 271
			echo "<tr><td><b>Interface ". htmlspecialchars(convert_real_interface_to_friendly_descr($q['interface'])) . "</b></td></tr>";
186 272
			$prev_if = $q['interface'];
......
220 306
		if (is_array($q['queue'])) {
221 307
			processQueues($q, $level + 1, $parent_name);
222 308
		}
223
	}
309
	};
224 310
}
225 311

  
226 312
function statsQueues($xml) {
......
245 331
			$current->drops += $child->drops;
246 332
		}
247 333
	}
248

  
249 334
	unset($child);
250 335
	$statistics[] = $current;
251 336
	return $current;
252 337
}
253

  
254 338
function format_bits($bits) {
255 339
	if ($bits >= 1000000000) {
256 340
		return sprintf("%.2f Gbps", $bits/1000000000);
......
262 346
		return sprintf("%d bps", $bits);
263 347
	}
264 348
}
265

  
266
$pgtitle = array(gettext("Status"), gettext("Traffic shaper"), gettext("Queues"));
267
$shortcut_section = "trafficshaper";
268
include("head.inc");
269

  
270
/*
271
if (!is_array($config['shaper']['queue']) || count($config['shaper']['queue']) < 1) {
272
	print_info_box(gettext("Traffic shaping is not configured."));
273
	include("foot.inc");
274
	exit;
275
}
276
*/
277
if (!$error):
278
	print_info_box($error, 'danger');
279
else:
280 349
?>
281
<form action="status_queues.php" method="post">
282
	<div class="panel panel-default">
283
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Status Queues"); ?></h2></div>
284
		<div class="panel-body table-responsive">
285
			<table class="table table-striped table-hover">
286
				<thead>
287
					<tr>
288
						<th><?=gettext("Queue"); ?></th>
289
						<th><?=gettext("Statistics"); ?>
290
							<select id="selStatistic">
291
								<option value="0">PPS</option>
292
								<option value="1">Bandwidth</option>
293
							</select>
294
						</th>
295
						<th><?=gettext("PPS"); ?></th>
296
						<th><?=gettext("Bandwidth"); ?></th>
297
						<th><?=gettext("Borrows"); ?></th>
298
						<th><?=gettext("Suspends"); ?></th>
299
						<th><?=gettext("Drops"); ?></th>
300
						<th><?=gettext("Length"); ?></th>
301
					</tr>
302
				</thead>
303
				<tbody>
304
<?php
305
	$if_queue_list = get_configured_interface_list_by_realif(false, true);
306
	processQueues($altqstats, 0, "");
307
?>
308
				</tbody>
309
			</table>
310
		</div>
311
	</div>
312
</form>
313
<?php
314
	print_info_box(gettext("Queue graphs take 5 seconds to sample data"));
315
endif;
316

  
317
?>
318

  
319
<script type="text/javascript">
320
//<![CDATA[
321
events.push(function(){
322
	function StatsShowHide(classname) {
323
		var firstrow = jQuery("." + classname).first();
324
		if (firstrow.is(':visible')) {
325
			jQuery("." + classname).hide();
326
		} else {
327
			jQuery("." + classname).show();
328
		}
329
	}
330

  
331
	function getqueueactivity() {
332
		var url = "/status_queues.php";
333
		var pars = "getactivity=yes&stats=" + jQuery("#selStatistic").val();
334

  
335
		jQuery.ajax(
336
			url,
337
			{
338
				type: 'post',
339
				data: pars,
340
				complete: activitycallback
341
			}
342
		);
343
	}
344

  
345
	function activitycallback(transport) {
346
		setTimeout(function(){getqueueactivity()}, 5100);
347
	}
348

  
349
	setTimeout(function(){getqueueactivity()}, 150);
350
});
351

  
352
//]]>
353
</script>
354

  
355
<?php
356

  
357
include("foot.inc");
358

  

Also available in: Unified diff