Project

General

Profile

Download (31.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
  Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>
5
  All rights reserved.
6

    
7
  Redistribution and use in source and binary forms, with or without
8
  modification, are permitted provided that the following conditions are met:
9

    
10
1. Redistributions of source code must retain the above copyright notice,
11
  this list of conditions and the following disclaimer.
12

    
13
  2. Redistributions in binary form must reproduce the above copyright
14
  notice, this list of conditions and the following disclaimer in the
15
  documentation and/or other materials provided with the distribution.
16

    
17
  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
  AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
  POSSIBILITY OF SUCH DAMAGE.
27

    
28
  */
29

    
30
/*
31
	pfSense_BUILDER_BINARIES:	/bin/rm	/usr/bin/nice	/usr/local/bin/rrdtool	/bin/cd
32
	pfSense_MODULE:	rrd
33
*/
34

    
35
/* include all configuration functions */
36

    
37
function dump_rrd_to_xml($rrddatabase, $xmldumpfile) {
38
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
39
	if(file_exists($xmldumpfile))
40
		mwexec("rm {$xmldumpfile}");
41

    
42
	exec("$rrdtool dump {$rrddatabase} {$xmldumpfile} 2>&1", $dumpout, $dumpret);
43
	if ($dumpret <> 0) {
44
		$dumpout = implode(" ", $dumpout);
45
		log_error(sprintf(gettext('RRD dump failed exited with %1$s, the error is: %2$s'), $dumpret, $dumpout));
46
	}
47
	return($dumpret);
48
}
49

    
50
function restore_rrd() {
51
	global $g, $config;
52

    
53
	$rrddbpath = "/var/db/rrd/";
54
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
55

    
56
	$rrdrestore = "";
57
	$rrdreturn = "";
58
	if (file_exists("{$g['cf_conf_path']}/rrd.tgz")) {
59
		foreach (glob("{$rrddbpath}/*.xml") as $xml_file) {
60
			@unlink($xml_file);
61
		}
62
		$_gb = exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/rrd.tgz 2>&1", $rrdrestore, $rrdreturn);
63
		$rrdrestore = implode(" ", $rrdrestore);
64
		if($rrdreturn != 0) {
65
			log_error("RRD restore failed exited with $rrdreturn, the error is: $rrdrestore\n");
66
		}
67
		unset($rrdrestore);
68
		foreach (glob("{$rrddbpath}/*.xml") as $xml_file) {
69
			$rrd_file = preg_replace('/\.xml$/', ".rrd", $xml_file);
70
			if (file_exists("{$rrd_file}")) {
71
				@unlink($rrd_file);
72
			}
73
			$output = array();
74
			$status = null;
75
			$_gb = exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
76
			if ($status) {
77
				log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}.");
78
				continue;
79
			}
80
			unset($output);
81
			@unlink($xml_file);
82
		}
83
		/* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */
84
		if (($g['platform'] == "pfSense") && !isset($config['system']['use_mfs_tmpvar'])) {
85
			unlink_if_exists("{$g['cf_conf_path']}/rrd.tgz");
86
		}
87
		return true;
88
	}
89
	return false;
90
}
91

    
92
function create_new_rrd($rrdcreatecmd) {
93
	$rrdcreateoutput = array();
94
	$rrdcreatereturn = 0;
95
	$_gb = exec("$rrdcreatecmd 2>&1", $rrdcreateoutput, $rrdcreatereturn);
96
	if ($rrdcreatereturn <> 0) {
97
		$rrdcreateoutput = implode(" ", $rrdcreateoutput);
98
		log_error(sprintf(gettext('RRD create failed exited with %1$s, the error is: %2$s'), $rrdcreatereturn, $rrdcreateoutput));
99
	}
100
	unset($rrdcreateoutput);
101
	return $rrdcreatereturn;
102
}
103

    
104
function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
105
	if(!file_exists("/tmp/rrd_notice_sent.txt")) {
106
		$_gb = exec("echo 'Converting RRD configuration to new format.  This might take a bit...' | wall");
107
		@touch("/tmp/rrd_notice_sent.txt");
108
	}
109
	$numrraold = count($rrdoldxml['rra']);
110
	$numrranew = count($rrdnewxml['rra']);
111
	$numdsold = count($rrdoldxml['ds']);
112
	$numdsnew = count($rrdnewxml['ds']);
113
	log_error(sprintf(gettext('Import RRD has %1$s DS values and %2$s RRA databases, new format RRD has %3$s DS values and %4$s RRA databases'), $numdsold, $numrraold, $numdsnew ,$numrranew));
114

    
115
	/* add data sources not found in the old array from the new array */
116
	$i = 0;
117
	foreach($rrdnewxml['ds'] as $ds) {
118
		if(!is_array($rrdoldxml['ds'][$i])) {
119
			$rrdoldxml['ds'][$i] = $rrdnewxml['ds'][$i];
120
			/* set unknown values to 0 */
121
			$rrdoldxml['ds'][$i]['last_ds'] = " 0.0000000000e+00 ";
122
			$rrdoldxml['ds'][$i]['value'] = " 0.0000000000e+00 ";
123
			$rrdoldxml['ds'][$i]['unknown_sec'] = "0";
124
		}
125
		$i++;
126
	}
127

    
128
	$i = 0;
129
	$rracountold = count($rrdoldxml['rra']);
130
	$rracountnew = count($rrdnewxml['rra']);
131
	/* process each RRA, which contain a database */
132
	foreach($rrdnewxml['rra'] as $rra) {
133
		if(!is_array($rrdoldxml['rra'][$i])) {
134
			$rrdoldxml['rra'][$i] = $rrdnewxml['rra'][$i];
135
		}
136

    
137
		$d = 0;
138
		/* process cdp_prep */
139
		$cdp_prep = $rra['cdp_prep'];
140
		foreach($cdp_prep['ds'] as $ds) {
141
			if(!is_array($rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d])) {
142
				$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d] = $rrdnewxml['rra'][$i]['cdp_prep']['ds'][$d];
143
				$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['primary_value'] = " 0.0000000000e+00 ";
144
				$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['secondary_value'] = " 0.0000000000e+00 ";
145
				$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['value'] = " 0.0000000000e+00 ";
146
				$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['unknown_datapoints'] = "0";
147
			}
148
			$d++;
149
		}
150

    
151
		/* process database */
152
		$rows = $rra['database'];
153
		$k = 0;
154
		$rowcountold = count($rrdoldxml['rra'][$i]['database']['row']);
155
		$rowcountnew = count($rrdnewxml['rra'][$i]['database']['row']);
156
		$rowcountdiff = $rowcountnew - $rowcountold;
157
		/* save old rows for a bit before we put the required empty rows before it */
158
		$rowsdata = $rows;
159
		$rowsempty = array();
160
		$r = 0;
161
		while($r < $rowcountdiff) {
162
			$rowsempty[] = $rrdnewxml['rra'][$i]['database']['row'][$r];
163
			$r++;
164
		}
165
		$rows = $rowsempty + $rowsdata;
166
		/* now foreach the rows in the database */
167
		foreach($rows['row'] as $row) {
168
			if(!is_array($rrdoldxml['rra'][$i]['database']['row'][$k])) {
169
				$rrdoldxml['rra'][$i]['database']['row'][$k] = $rrdnewxml['rra'][$i]['database']['row'][$k];
170
			}
171
			$m = 0;
172
			$vcountold = count($rrdoldxml['rra'][$i]['database']['row'][$k]['v']);
173
			$vcountnew = count($rrdnewxml['rra'][$i]['database']['row'][$k]['v']);
174
			foreach($row['v'] as $value) {
175
				if(empty($rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m])) {
176
					if(isset($valid)) {
177
						$rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m] = "0.0000000000e+00 ";
178
					} else {
179
						$rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m] = $rrdnewxml['rra'][$i]['database']['row'][$k]['v'][$m];
180
					}
181
				} else {
182
					if($value <> " NaN ") {
183
						$valid = true;
184
					} else {
185
						$valid = false;
186
					}
187
				}
188
				$m++;
189
			}
190
			$k++;
191
		}
192
		$i++;
193
	}
194

    
195
	$numrranew = count($rrdoldxml['rra']);
196
	$numdsnew = count($rrdoldxml['ds']);
197
	log_error(sprintf(gettext('The new RRD now has %1$s DS values and %2$s RRA databases'), $numdsnew, $numrranew));
198
	return $rrdoldxml;
199
}
200

    
201
function enable_rrd_graphing() {
202
	global $config, $g, $altq_list_queues;
203

    
204
	if($g['booting'])
205
		echo gettext("Generating RRD graphs...");
206

    
207
	$rrddbpath = "/var/db/rrd/";
208
	$rrdgraphpath = "/usr/local/www/rrd";
209

    
210
	$traffic = "-traffic.rrd";
211
	$packets = "-packets.rrd";
212
	$states = "-states.rrd";
213
	$wireless = "-wireless.rrd";
214
	$queues = "-queues.rrd";
215
	$queuesdrop = "-queuedrops.rrd";
216
	$spamd = "-spamd.rrd";
217
	$proc = "-processor.rrd";
218
	$mem = "-memory.rrd";
219
	$cellular = "-cellular.rrd";
220
	$vpnusers = "-vpnusers.rrd";
221
	$captiveportalconcurrent = "-concurrent.rrd";
222
	$captiveportalloggedin = "-loggedin.rrd";
223

    
224
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
225
	$netstat = "/usr/bin/netstat";
226
	$awk = "/usr/bin/awk";
227
	$tar = "/usr/bin/tar";
228
	$pfctl = "/sbin/pfctl";
229
	$sysctl = "/sbin/sysctl";
230
	$php = "/usr/local/bin/php";
231
	$cpustats = "/usr/local/sbin/cpustats";
232
	$spamd_gather = "/usr/local/bin/spamd_gather_stats.php";
233
	$ifconfig = "/sbin/ifconfig";
234
	$captiveportal_gather = "/usr/local/bin/captiveportal_gather_stats.php";
235

    
236
	$rrdtrafficinterval = 60;
237
	$rrdwirelessinterval = 60;
238
	$rrdqueuesinterval = 60;
239
	$rrdqueuesdropinterval = 60;
240
	$rrdpacketsinterval = 60;
241
	$rrdstatesinterval = 60;
242
	$rrdspamdinterval = 60;
243
	$rrdlbpoolinterval = 60;
244
	$rrdprocinterval = 60;
245
	$rrdmeminterval = 60;
246
	$rrdcellularinterval = 60;
247
	$rrdvpninterval = 60;
248
	$rrdcaptiveportalinterval = 60;
249

    
250
	$trafficvalid = $rrdtrafficinterval * 2;
251
	$wirelessvalid = $rrdwirelessinterval * 2;
252
	$queuesvalid = $rrdqueuesinterval * 2;
253
	$queuesdropvalid = $rrdqueuesdropinterval * 2;
254
	$packetsvalid = $rrdpacketsinterval * 2;
255
	$statesvalid = $rrdstatesinterval*2;
256
	$spamdvalid = $rrdspamdinterval * 2;
257
	$lbpoolvalid = $rrdlbpoolinterval * 2;
258
	$procvalid = $rrdlbpoolinterval * 2;
259
	$memvalid = $rrdmeminterval * 2;
260
	$cellularvalid = $rrdcellularinterval * 2;
261
	$vpnvalid = $rrdvpninterval * 2;
262
	$captiveportalvalid = $rrdcaptiveportalinterval * 2;
263

    
264
	/* Assume 2*10GigE for now */
265
	$downstream = 2500000000;
266
	$upstream = 2500000000;
267

    
268
	/* read the shaper config */
269
	read_altq_config();
270

    
271
	if (isset ($config['rrd']['enable'])) {
272

    
273
		/* create directory if needed */
274
		if (!is_dir($rrddbpath)) {
275
			mkdir($rrddbpath, 0775);
276
		}
277
		chown($rrddbpath, "nobody");
278

    
279
		if ($g['booting']) {
280
			restore_rrd();
281
		}
282

    
283
		/* db update script */
284
		$rrdupdatesh = "#!/bin/sh\n";
285
		$rrdupdatesh .= "\n";
286
		$rrdupdatesh .= "export TERM=dumb\n";
287
		$rrdupdatesh .= "\n";
288
		$rrdupdatesh .= 'echo $$ > ' . $g['varrun_path'] . '/updaterrd.sh.pid';
289
		$rrdupdatesh .= "\n";
290
		$rrdupdatesh .= "counter=1\n";
291
		$rrdupdatesh .= "while [ \"\$counter\" -ne 0 ]\n";
292
		$rrdupdatesh .= "do\n";
293
		$rrdupdatesh .= "";
294

    
295
		$i = 0;
296
		$ifdescrs = get_configured_interface_with_descr();
297
		/* IPsec counters */
298
		$ifdescrs['ipsec'] = "IPsec";
299
		/* OpenVPN server counters */
300
		if(is_array($config['openvpn']['openvpn-server'])) {
301
			foreach($config['openvpn']['openvpn-server'] as $server) {
302
				$serverid = "ovpns" . $server['vpnid'];
303
				$ifdescrs[$serverid] = "{$server['description']}";
304
			}
305
		}
306

    
307
		/* process all real and pseudo interfaces */
308
		foreach ($ifdescrs as $ifname => $ifdescr) {
309
			$temp = get_real_interface($ifname);
310
			if($temp <> "") {
311
				$realif = $temp;
312
			}
313

    
314
			/* TRAFFIC, set up the rrd file */
315
			if (!file_exists("$rrddbpath$ifname$traffic")) {
316
				$rrdcreate = "$rrdtool create $rrddbpath$ifname$traffic --step $rrdtrafficinterval ";
317
				$rrdcreate .= "DS:inpass:COUNTER:$trafficvalid:0:$downstream ";
318
				$rrdcreate .= "DS:outpass:COUNTER:$trafficvalid:0:$upstream ";
319
				$rrdcreate .= "DS:inblock:COUNTER:$trafficvalid:0:$downstream ";
320
				$rrdcreate .= "DS:outblock:COUNTER:$trafficvalid:0:$upstream ";
321
				$rrdcreate .= "DS:inpass6:COUNTER:$trafficvalid:0:$downstream ";
322
				$rrdcreate .= "DS:outpass6:COUNTER:$trafficvalid:0:$upstream ";
323
				$rrdcreate .= "DS:inblock6:COUNTER:$trafficvalid:0:$downstream ";
324
				$rrdcreate .= "DS:outblock6:COUNTER:$trafficvalid:0:$upstream ";
325
				$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
326
				$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
327
				$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
328
				$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
329

    
330
				create_new_rrd($rrdcreate);
331
				unset($rrdcreate);
332
			}
333

    
334
			/* enter UNKNOWN values in the RRD so it knows we rebooted. */
335
			if($g['booting']) {
336
				mwexec("$rrdtool update $rrddbpath$ifname$traffic N:U:U:U:U:U:U:U:U");
337
			}
338

    
339
			$rrdupdatesh .= "\n";
340
			$rrdupdatesh .= "# polling traffic for interface $ifname $realif IPv4/IPv6 counters \n";
341
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$traffic N:";
342
			$rrdupdatesh .= "`$pfctl -vvsI -i {$realif} | awk '\\\n";
343
			$rrdupdatesh .= "/In4\/Pass/ { b4pi = \$6 };/Out4\/Pass/ { b4po = \$6 };/In4\/Block/ { b4bi = \$6 };/Out4\/Block/ { b4bo = \$6 };\\\n";
344
			$rrdupdatesh .= "/In6\/Pass/ { b6pi = \$6 };/Out6\/Pass/ { b6po = \$6 };/In6\/Block/ { b6bi = \$6 };/Out6\/Block/ { b6bo = \$6 };\\\n";
345
			$rrdupdatesh .= "END {print b4pi \":\" b4po \":\" b4bi \":\" b4bo \":\" b6pi \":\" b6po \":\" b6bi \":\" b6bo};'`\n";
346

    
347
			/* PACKETS, set up the rrd file */
348
			if (!file_exists("$rrddbpath$ifname$packets")) {
349
				$rrdcreate = "$rrdtool create $rrddbpath$ifname$packets --step $rrdpacketsinterval ";
350
				$rrdcreate .= "DS:inpass:COUNTER:$packetsvalid:0:$downstream ";
351
				$rrdcreate .= "DS:outpass:COUNTER:$packetsvalid:0:$upstream ";
352
				$rrdcreate .= "DS:inblock:COUNTER:$packetsvalid:0:$downstream ";
353
				$rrdcreate .= "DS:outblock:COUNTER:$packetsvalid:0:$upstream ";
354
				$rrdcreate .= "DS:inpass6:COUNTER:$packetsvalid:0:$downstream ";
355
				$rrdcreate .= "DS:outpass6:COUNTER:$packetsvalid:0:$upstream ";
356
				$rrdcreate .= "DS:inblock6:COUNTER:$packetsvalid:0:$downstream ";
357
				$rrdcreate .= "DS:outblock6:COUNTER:$packetsvalid:0:$upstream ";
358
				$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
359
				$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
360
				$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
361
				$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
362

    
363
				create_new_rrd($rrdcreate);
364
				unset($rrdcreate);
365
			}
366

    
367
			/* enter UNKNOWN values in the RRD so it knows we rebooted. */
368
			if($g['booting']) {
369
				mwexec("$rrdtool update $rrddbpath$ifname$packets N:U:U:U:U:U:U:U:U");
370
			}
371

    
372
			$rrdupdatesh .= "\n";
373
			$rrdupdatesh .= "# polling packets for interface $ifname $realif \n";
374
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$packets N:";
375
			$rrdupdatesh .= "`$pfctl -vvsI -i {$realif} | awk '\\\n";
376
			$rrdupdatesh .= "/In4\/Pass/ { b4pi = \$4 };/Out4\/Pass/ { b4po = \$4 };/In4\/Block/ { b4bi = \$4 };/Out4\/Block/ { b4bo = \$4 };\\\n";
377
			$rrdupdatesh .= "/In6\/Pass/ { b6pi = \$4 };/Out6\/Pass/ { b6po = \$4 };/In6\/Block/ { b6bi = \$4 };/Out6\/Block/ { b6bo = \$4 };\\\n";
378
			$rrdupdatesh .= "END {print b4pi \":\" b4po \":\" b4bi \":\" b4bo \":\" b6pi \":\" b6po \":\" b6bi \":\" b6bo};'`\n";
379

    
380
			/* WIRELESS, set up the rrd file */
381
			if($config['interfaces'][$ifname]['wireless']['mode'] == "bss") {
382
				if (!file_exists("$rrddbpath$ifname$wireless")) {
383
					$rrdcreate = "$rrdtool create $rrddbpath$ifname$wireless --step $rrdwirelessinterval ";
384
					$rrdcreate .= "DS:snr:GAUGE:$wirelessvalid:0:1000 ";
385
					$rrdcreate .= "DS:rate:GAUGE:$wirelessvalid:0:1000 ";
386
					$rrdcreate .= "DS:channel:GAUGE:$wirelessvalid:0:1000 ";
387
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
388
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
389
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
390
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
391

    
392
					create_new_rrd($rrdcreate);
393
					unset($rrdcreate);
394
				}
395

    
396
				/* enter UNKNOWN values in the RRD so it knows we rebooted. */
397
				if($g['booting']) {
398
					mwexec("$rrdtool update $rrddbpath$ifname$wireless N:U:U:U");
399
				}
400

    
401
				$rrdupdatesh .= "\n";
402
				$rrdupdatesh .= "# polling wireless for interface $ifname $realif \n";
403
				$rrdupdatesh .= "WIFI=`$ifconfig {$realif} list sta| $awk 'gsub(\"M\", \"\") {getline 2;print substr(\$5, 0, length(\$5)-2) \":\" $4 \":\" $3}'`\n";
404
				$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$wireless N:\${WIFI}\n";
405
			}
406

    
407
			/* OpenVPN, set up the rrd file */
408
			if(stristr($ifname, "ovpns")) {
409
				if (!file_exists("$rrddbpath$ifname$vpnusers")) {
410
					$rrdcreate = "$rrdtool create $rrddbpath$ifname$vpnusers --step $rrdvpninterval ";
411
					$rrdcreate .= "DS:users:GAUGE:$vpnvalid:0:10000 ";
412
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
413
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
414
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
415
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
416

    
417
					create_new_rrd($rrdcreate);
418
					unset($rrdcreate);
419
				}
420

    
421
				/* enter UNKNOWN values in the RRD so it knows we rebooted. */
422
				if($g['booting']) {
423
					mwexec("$rrdtool update $rrddbpath$ifname$vpnusers N:U");
424
				}
425

    
426
				if(is_array($config['openvpn']['openvpn-server'])) {
427
					foreach($config['openvpn']['openvpn-server'] as $server) {
428
						if("ovpns{$server['vpnid']}" == $ifname) {
429
							$port = $server['local_port'];
430
							$vpnid = $server['vpnid'];
431
						}
432
					}
433
				}
434
				$rrdupdatesh .= "\n";
435
				$rrdupdatesh .= "# polling vpn users for interface $ifname $realif port $port\n";
436
				$rrdupdatesh .= "list_current_users() {\n";
437
				$rrdupdatesh .= " sleep 0.2\n";
438
				$rrdupdatesh .= " echo \"status 2\"\n";
439
				$rrdupdatesh .= " sleep 0.2\n";
440
				$rrdupdatesh .= " echo \"quit\"\n";
441
				$rrdupdatesh .= "}\n";
442
				$rrdupdatesh .= "OVPN=`list_current_users | nc -U {$g['varetc_path']}/openvpn/server{$vpnid}.sock | awk -F\",\" '/^CLIENT_LIST/ {print \$2}' | wc -l | awk '{print $1}'`\n";
443
				$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$vpnusers N:\${OVPN}\n";
444
			}
445

    
446
			/* QUEUES, set up the queues databases */
447
			if ($altq_list_queues[$ifname]) {
448
				$altq =& $altq_list_queues[$ifname];
449
				/* NOTE: Is it worth as its own function?! */
450
				switch ($altq->GetBwscale()) {
451
					case "Gb":
452
						$factor = 1024 * 1024 * 1024;
453
							break;
454
					case "Mb":
455
							$factor = 1024 * 1024;
456
							break;
457
					case "Kb":
458
							$factor = 1024;
459
							break;
460
					case "b":
461
					default:
462
							$factor = 1;
463
							break;
464
				}
465
				$qbandwidth = $altq->GetBandwidth() * $factor;
466
				if ($qbandwidth <=0) {
467
					$qbandwidth = 100 * 1000 * 1000; /* 100Mbit */
468
				}
469
				$qlist =& $altq->get_queue_list($notused);
470
				if (!file_exists("$rrddbpath$ifname$queues")) {
471
					$rrdcreate = "$rrdtool create $rrddbpath$ifname$queues --step $rrdqueuesinterval ";
472
					/* loop list of shaper queues */
473
					$q = 0;
474
					foreach ($qlist as $qname => $q) {
475
						$rrdcreate .= "DS:$qname:COUNTER:$queuesvalid:0:$qbandwidth ";
476
					}
477

    
478
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
479
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
480
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
481
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
482

    
483
					create_new_rrd($rrdcreate);
484
					unset($rrdcreate);
485
				}
486

    
487
				if (!file_exists("$rrddbpath$ifname$queuesdrop")) {
488
					$rrdcreate = "$rrdtool create $rrddbpath$ifname$queuesdrop --step $rrdqueuesdropinterval ";
489
					/* loop list of shaper queues */
490
					$q = 0;
491
					foreach ($qlist as $qname => $q) {
492
						$rrdcreate .= "DS:$qname:COUNTER:$queuesdropvalid:0:$qbandwidth ";
493
					}
494

    
495
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
496
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
497
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
498
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
499

    
500
					create_new_rrd($rrdcreate);
501
					unset($rrdcreate);
502
				}
503

    
504
				if($g['booting']) {
505
					$rrdqcommand = "-t ";
506
					$rrducommand = "N";
507
					$qi = 0;
508
					foreach ($qlist as $qname => $q) {
509
						if($qi == 0) {
510
							$rrdqcommand .= "{$qname}";
511
						} else {
512
							$rrdqcommand .= ":{$qname}";
513
						}
514
						$qi++;
515
						$rrducommand .= ":U";
516
					}
517
					mwexec("$rrdtool update $rrddbpath$ifname$queues $rrdqcommand $rrducommand");
518
					mwexec("$rrdtool update $rrddbpath$ifname$queuesdrop $rrdqcommand $rrducommand");
519
				}
520

    
521
				/* awk function to gather shaper data */
522
				/* yes, it's special */
523
				$rrdupdatesh .= "` pfctl -vsq -i {$realif} | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queues \" } ";
524
				$rrdupdatesh .= "{ ";
525
				$rrdupdatesh .= "if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { ";
526
				$rrdupdatesh .= " dsname = dsname \":\" \$2 ; ";
527
				$rrdupdatesh .= " q=1; ";
528
				$rrdupdatesh .= "} ";
529
				$rrdupdatesh .= " else if ((\$4 == \"bytes:\") && ( q == 1 ) ) { ";
530
				$rrdupdatesh .= " dsdata = dsdata \":\" \$5 ; ";
531
				$rrdupdatesh .= " q=0; ";
532
				$rrdupdatesh .= "} ";
533
				$rrdupdatesh .= "} END { ";
534
				$rrdupdatesh .= " dsname = substr(dsname,2); ";
535
				$rrdupdatesh .= " dsdata = substr(dsdata,2); ";
536
				$rrdupdatesh .= " printf \"-t \" dsname \" N:\" dsdata }' ";
537
				$rrdupdatesh .= " dsname=\"\" dsdata=\"\"`\n\n";
538

    
539
				$rrdupdatesh .= "` pfctl -vsq -i {$realif} | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queuesdrop \" } ";
540
				$rrdupdatesh .= "{ ";
541
				$rrdupdatesh .= "if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { ";
542
				$rrdupdatesh .= " dsname = dsname \":\" \$2 ; ";
543
				$rrdupdatesh .= " q=1; ";
544
				$rrdupdatesh .= "} ";
545
				$rrdupdatesh .= " else if ((\$4 == \"bytes:\") && ( q == 1 ) ) { ";
546
				$rrdupdatesh .= " dsdata = dsdata \":\" \$8 ; ";
547
				$rrdupdatesh .= " q=0; ";
548
				$rrdupdatesh .= "} ";
549
				$rrdupdatesh .= "} END { ";
550
				$rrdupdatesh .= " dsname = substr(dsname,2); ";
551
				$rrdupdatesh .= " dsdata = substr(dsdata,2); ";
552
				$rrdupdatesh .= " printf \"-t \" dsname \" N:\" dsdata }' ";
553
				$rrdupdatesh .= " dsname=\"\" dsdata=\"\"`\n\n";
554
			}
555

    
556
			/* 3G interfaces */
557
			if(preg_match("/ppp[0-9]+/i", $realif))	{
558
				if (!file_exists("$rrddbpath$ifname$cellular")) {
559
					$rrdcreate = "$rrdtool create $rrddbpath$ifname$cellular --step $rrdcellularinterval ";
560
					$rrdcreate .= "DS:rssi:GAUGE:$cellularvalid:0:100 ";
561
					$rrdcreate .= "DS:upstream:GAUGE:$cellularvalid:0:100000000 ";
562
					$rrdcreate .= "DS:downstream:GAUGE:$cellularvalid:0:100000000 ";
563
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
564
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
565
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
566
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
567
					create_new_rrd($rrdcreate);
568
					unset($rrdcreate);
569
				}
570

    
571
				/* enter UNKNOWN values in the RRD so it knows we rebooted. */
572
				if($g['booting']) {
573
					mwexec("$rrdtool update $rrddbpath$ifname$cellular N:U:U:U");
574
				}
575

    
576
				$rrdupdatesh .= "\n";
577
				$rrdupdatesh .= "# polling 3G\n";
578
				$rrdupdatesh .= "GSTATS=`awk -F, 'getline 2 {print \$2 \":\" \$8 \":\" \$9}' < /tmp/3gstats.$ifname`\n";
579
				$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$cellular N:\"\$GSTATS\"";
580
			}
581

    
582
		}
583
		$i++;
584

    
585
		/* System only statistics */
586
		$ifname = "system";
587

    
588
		/* STATES, create pf states database */
589
		if(! file_exists("$rrddbpath$ifname$states")) {
590
			$rrdcreate = "$rrdtool create $rrddbpath$ifname$states --step $rrdstatesinterval ";
591
			$rrdcreate .= "DS:pfrate:GAUGE:$statesvalid:0:10000000 ";
592
			$rrdcreate .= "DS:pfstates:GAUGE:$statesvalid:0:10000000 ";
593
			$rrdcreate .= "DS:pfnat:GAUGE:$statesvalid:0:10000000 ";
594
			$rrdcreate .= "DS:srcip:GAUGE:$statesvalid:0:10000000 ";
595
			$rrdcreate .= "DS:dstip:GAUGE:$statesvalid:0:10000000 ";
596
			$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
597
			$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
598
			$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
599
			$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
600

    
601
			create_new_rrd($rrdcreate);
602
			unset($rrdcreate);
603
		}
604

    
605
		/* enter UNKNOWN values in the RRD so it knows we rebooted. */
606
		if($g['booting']) {
607
			mwexec("$rrdtool update $rrddbpath$ifname$states N:U:U:U:U:U");
608
		}
609

    
610
		/* the pf states gathering function. */
611
		$rrdupdatesh .= "\n";
612
		$rrdupdatesh .= "pfctl_si_out=\"` $pfctl -si > /tmp/pfctl_si_out `\"\n";
613
		$rrdupdatesh .= "pfctl_ss_out=\"` $pfctl -ss > /tmp/pfctl_ss_out`\"\n";
614
		$rrdupdatesh .= "pfrate=\"` cat /tmp/pfctl_si_out | egrep \"inserts|removals\" | awk '{ pfrate = \$3 + pfrate } {print pfrate}'|tail -1 `\"\n";
615
		$rrdupdatesh .= "pfstates=\"` cat /tmp/pfctl_ss_out | egrep -v \"<\\-.*?<\\-|\\->.*?\\->\" | wc -l|sed 's/ //g'`\"\n";
616
		$rrdupdatesh .= "pfnat=\"` cat /tmp/pfctl_ss_out | egrep '<\\-.*?<\\-|\\->.*?\\->' | wc -l|sed 's/ //g' `\"\n";
617
		$rrdupdatesh .= "srcip=\"` cat /tmp/pfctl_ss_out | egrep -v '<\\-.*?<\\-|\\->.*?\\->' | grep '\\->' | awk '{print \$3}' | awk -F: '{print \$1}' | sort -u|wc -l|sed 's/ //g' `\"\n";
618
		$rrdupdatesh .= "dstip=\"` cat /tmp/pfctl_ss_out | egrep -v '<\\-.*?<\\-|\\->.*?\\->' | grep '<\\-' | awk '{print \$3}' | awk -F: '{print \$1}' | sort -u|wc -l|sed 's/ //g' `\"\n";
619
		$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$states N:\$pfrate:\$pfstates:\$pfnat:\$srcip:\$dstip\n\n";
620

    
621
		/* End pf states statistics */
622

    
623
		/* CPU, create CPU statistics database */
624
		if(! file_exists("$rrddbpath$ifname$proc")) {
625
			$rrdcreate = "$rrdtool create $rrddbpath$ifname$proc --step $rrdprocinterval ";
626
			$rrdcreate .= "DS:user:GAUGE:$procvalid:0:10000000 ";
627
			$rrdcreate .= "DS:nice:GAUGE:$procvalid:0:10000000 ";
628
			$rrdcreate .= "DS:system:GAUGE:$procvalid:0:10000000 ";
629
			$rrdcreate .= "DS:interrupt:GAUGE:$procvalid:0:10000000 ";
630
			$rrdcreate .= "DS:processes:GAUGE:$procvalid:0:10000000 ";
631
			$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
632
			$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
633
			$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
634
			$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
635

    
636
			create_new_rrd($rrdcreate);
637
			unset($rrdcreate);
638
		}
639

    
640
		/* enter UNKNOWN values in the RRD so it knows we rebooted. */
641
		if($g['booting']) {
642
			mwexec("$rrdtool update $rrddbpath$ifname$proc N:U:U:U:U:U");
643
		}
644

    
645
		/* the CPU stats gathering function. */
646
		$rrdupdatesh .= "CPU=`$cpustats | cut -f1-4 -d':'`\n";
647
		/* Using ps uxaH will count all processes including system threads. Top was undercounting. */
648
		$rrdupdatesh .= "PROCS=`ps uxaH | wc -l | awk '{print \$1;}'`\n";
649
		$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$proc N:\${CPU}:\${PROCS}\n";
650

    
651
		/* End CPU statistics */
652

    
653
		/* Memory, create Memory statistics database */
654
		if(! file_exists("$rrddbpath$ifname$mem")) {
655
			$rrdcreate = "$rrdtool create $rrddbpath$ifname$mem --step $rrdmeminterval ";
656
			$rrdcreate .= "DS:active:GAUGE:$memvalid:0:10000000 ";
657
			$rrdcreate .= "DS:inactive:GAUGE:$memvalid:0:10000000 ";
658
			$rrdcreate .= "DS:free:GAUGE:$memvalid:0:10000000 ";
659
			$rrdcreate .= "DS:cache:GAUGE:$memvalid:0:10000000 ";
660
			$rrdcreate .= "DS:wire:GAUGE:$memvalid:0:10000000 ";
661
			$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
662
			$rrdcreate .= "RRA:MIN:0.5:5:720 ";
663
			$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
664
			$rrdcreate .= "RRA:MIN:0.5:1440:3652 ";
665
			$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
666
			$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
667
			$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
668
			$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
669
			$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
670
			$rrdcreate .= "RRA:MAX:0.5:5:720 ";
671
			$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
672
			$rrdcreate .= "RRA:MAX:0.5:1440:3652";
673

    
674
			create_new_rrd($rrdcreate);
675
			unset($rrdcreate);
676
		}
677

    
678
		/* enter UNKNOWN values in the RRD so it knows we rebooted. */
679
		if($g['booting']) {
680
			mwexec("$rrdtool update $rrddbpath$ifname$mem N:U:U:U:U:U");
681
		}
682

    
683
		/* the Memory stats gathering function. */
684
		$rrdupdatesh .= "MEM=`$sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_active_count vm.stats.vm.v_inactive_count vm.stats.vm.v_free_count vm.stats.vm.v_cache_count vm.stats.vm.v_wire_count | ";
685
		$rrdupdatesh .= " $awk '{getline active;getline inactive;getline free;getline cache;getline wire;printf ";
686
		$rrdupdatesh .= "((active/$0) * 100)\":\"((inactive/$0) * 100)\":\"((free/$0) * 100)\":\"((cache/$0) * 100)\":\"(wire/$0 * 100)}'`\n";
687
		$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$mem N:\${MEM}\n";
688

    
689
		/* End Memory statistics */
690

    
691
		/* SPAMD, set up the spamd rrd file */
692
		if (isset($config['installedpackages']['spamdsettings']) &&
693
			 $config['installedpackages']['spamdsettings']['config'][0]['enablerrd']) {
694
			/* set up the spamd rrd file */
695
			if (!file_exists("$rrddbpath$ifname$spamd")) {
696
				$rrdcreate = "$rrdtool create $rrddbpath$ifname$spamd --step $rrdspamdinterval ";
697
				$rrdcreate .= "DS:conn:GAUGE:$spamdvalid:0:10000 ";
698
				$rrdcreate .= "DS:time:GAUGE:$spamdvalid:0:86400 ";
699
				$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
700
				$rrdcreate .= "RRA:MIN:0.5:5:720 ";
701
				$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
702
				$rrdcreate .= "RRA:MIN:0.5:1440:3652 ";
703
				$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
704
				$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
705
				$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
706
				$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
707
				$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
708
				$rrdcreate .= "RRA:MAX:0.5:5:720 ";
709
				$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
710
				$rrdcreate .= "RRA:MAX:0.5:1440:3652 ";
711

    
712
				create_new_rrd($rrdcreate);
713
				unset($rrdcreate);
714
			}
715

    
716
			$rrdupdatesh .= "\n";
717
			$rrdupdatesh .= "# polling spamd for connections and tarpitness \n";
718
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$spamd \\\n";
719
			$rrdupdatesh .= "`$php -q $spamd_gather`\n";
720

    
721
		}
722
		/* End System statistics */
723

    
724
		/* Captive Portal statistics, set up the rrd file */
725
		if(is_array($config['captiveportal'])) {
726
			foreach ($config['captiveportal'] as $cpkey => $cp) {
727
				if (!isset($cp['enable']))
728
					continue;
729

    
730
				$ifname= "captiveportal";
731
				$concurrent_filename = $rrddbpath . $ifname . '-' . $cpkey . $captiveportalconcurrent;
732
				if (!file_exists("$concurrent_filename")) {
733
					$rrdcreate = "$rrdtool create $concurrent_filename --step $rrdcaptiveportalinterval ";
734
					$rrdcreate .= "DS:concurrentusers:GAUGE:$captiveportalvalid:0:10000 ";
735
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
736
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
737
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
738
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
739
					$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
740
					$rrdcreate .= "RRA:MIN:0.5:5:720 ";
741
					$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
742
					$rrdcreate .= "RRA:MIN:0.5:1440:3652 ";
743
					$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
744
					$rrdcreate .= "RRA:MAX:0.5:5:720 ";
745
					$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
746
					$rrdcreate .= "RRA:MAX:0.5:1440:3652 ";
747
					$rrdcreate .= "RRA:LAST:0.5:1:1200 ";
748
					$rrdcreate .= "RRA:LAST:0.5:5:720 ";
749
					$rrdcreate .= "RRA:LAST:0.5:60:1860 ";
750
					$rrdcreate .= "RRA:LAST:0.5:1440:3652 ";
751

    
752
					create_new_rrd($rrdcreate);
753
					unset($rrdcreate);
754
				}
755

    
756
				/* enter UNKNOWN values in the RRD so it knows we rebooted. */
757
				if($g['booting']) {
758
					mwexec("$rrdtool update $concurrent_filename N:U");
759
				}
760

    
761
				/* the Captive Portal stats gathering function. */
762
				$rrdupdatesh .= "\n";
763
				$rrdupdatesh .= "# polling Captive Portal for number of concurrent users\n";
764
				$rrdupdatesh .= "CP=`$php -q $captiveportal_gather '$cpkey' $concurrent`\n";
765
				$rrdupdatesh .= "$rrdtool update $concurrent_filename \${CP}\n";
766

    
767
				$loggedin_filename = $rrddbpath . $ifname . '-' . $cpkey . $captiveportalloggedin;
768
				if (!file_exists("$loggedin_filename")) {
769
					$rrdcreate = "$rrdtool create $loggedin_filename --step $rrdcaptiveportalinterval ";
770
					$rrdcreate .= "DS:loggedinusers:GAUGE:$captiveportalvalid:0:10000 ";
771
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
772
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
773
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
774
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:3652 ";
775
					$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
776
					$rrdcreate .= "RRA:MIN:0.5:5:720 ";
777
					$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
778
					$rrdcreate .= "RRA:MIN:0.5:1440:3652 ";
779
					$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
780
					$rrdcreate .= "RRA:MAX:0.5:5:720 ";
781
					$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
782
					$rrdcreate .= "RRA:MAX:0.5:1440:3652 ";
783
					$rrdcreate .= "RRA:LAST:0.5:1:1200 ";
784
					$rrdcreate .= "RRA:LAST:0.5:5:720 ";
785
					$rrdcreate .= "RRA:LAST:0.5:60:1860 ";
786
					$rrdcreate .= "RRA:LAST:0.5:1440:3652 ";
787

    
788
					create_new_rrd($rrdcreate);
789
					unset($rrdcreate);
790
				}
791

    
792
				/* enter UNKNOWN values in the RRD so it knows we rebooted. */
793
				if($g['booting']) {
794
					mwexec("$rrdtool update $loggedin_filename N:U");
795
				}
796

    
797
				/* the Captive Portal stats gathering function. */
798
				$rrdupdatesh .= "\n";
799
				$rrdupdatesh .= "# polling Captive Portal for number of logged in users\n";
800
				$rrdupdatesh .= "CP=`$php -q $captiveportal_gather $cpkey loggedin`\n";
801
				$rrdupdatesh .= "$rrdtool update $loggedin_filename \${CP}\n";
802

    
803
			}
804
		}
805

    
806
		$rrdupdatesh .= "sleep 60\n";
807
		$rrdupdatesh .= "done\n";
808
		log_error(gettext("Creating rrd update script"));
809
		/* write the rrd update script */
810
		$updaterrdscript = "{$g['vardb_path']}/rrd/updaterrd.sh";
811
		$fd = fopen("$updaterrdscript", "w");
812
		fwrite($fd, "$rrdupdatesh");
813
		fclose($fd);
814

    
815
		unset($rrdupdatesh);
816

    
817
		/* kill off traffic collectors */
818
		kill_traffic_collector();
819

    
820
		/* start traffic collector */
821
		mwexec_bg("/usr/bin/nice -n20 /bin/sh $updaterrdscript");
822

    
823
	} else {
824
		/* kill off traffic collectors */
825
		kill_traffic_collector();
826
	}
827

    
828
	$databases = glob("{$rrddbpath}/*.rrd");
829
	foreach($databases as $database) {
830
		chown($database, "nobody");
831
	}
832

    
833
	if($g['booting'])
834
		echo gettext("done.") . "\n";
835

    
836
}
837

    
838
function kill_traffic_collector() {
839
	global $g;
840

    
841
	killbypid("{$g['varrun_path']}/updaterrd.sh.pid");
842
}
843

    
844
?>
(46-46/66)