Project

General

Profile

Download (39.4 KB) Statistics
| Branch: | Tag: | Revision:
1 b0a5b824 Seth Mos
<?php
2
/*
3 ac24dc24 Renato Botelho
 * rrd.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 c5d81585 Renato Botelho
 * Copyright (c) 2010 Seth Mos <seth.mos@dds.nl>
7 38809d47 Renato Botelho do Couto
 * Copyright (c) 2010-2013 BSD Perimeter
8
 * Copyright (c) 2013-2016 Electric Sheep Fencing
9 402c98a2 Reid Linnemann
 * Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
10 ac24dc24 Renato Botelho
 * All rights reserved.
11
 *
12 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15 ac24dc24 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
17 ac24dc24 Renato Botelho
 *
18 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23 ac24dc24 Renato Botelho
 */
24 b0a5b824 Seth Mos
25
/* include all configuration functions */
26
27
function dump_rrd_to_xml($rrddatabase, $xmldumpfile) {
28 d9acea75 Scott Ullrich
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
29 552f5a6a Renato Botelho
	unlink_if_exists($xmldumpfile);
30 1b25fc27 Seth Mos
31 873c1701 Renato Botelho
	exec("$rrdtool dump " . escapeshellarg($rrddatabase) . " {$xmldumpfile} 2>&1", $dumpout, $dumpret);
32 b0a5b824 Seth Mos
	if ($dumpret <> 0) {
33
		$dumpout = implode(" ", $dumpout);
34 addc0439 Renato Botelho
		log_error(sprintf(gettext('RRD dump failed exited with %1$s, the error is: %2$s'), $dumpret, $dumpout));
35 b0a5b824 Seth Mos
	}
36
	return($dumpret);
37
}
38
39
function create_new_rrd($rrdcreatecmd) {
40
	$rrdcreateoutput = array();
41
	$rrdcreatereturn = 0;
42 2159494f Ermal
	$_gb = exec("$rrdcreatecmd 2>&1", $rrdcreateoutput, $rrdcreatereturn);
43 b0a5b824 Seth Mos
	if ($rrdcreatereturn <> 0) {
44
		$rrdcreateoutput = implode(" ", $rrdcreateoutput);
45 addc0439 Renato Botelho
		log_error(sprintf(gettext('RRD create failed exited with %1$s, the error is: %2$s'), $rrdcreatereturn, $rrdcreateoutput));
46 b0a5b824 Seth Mos
	}
47 2159494f Ermal
	unset($rrdcreateoutput);
48 b0a5b824 Seth Mos
	return $rrdcreatereturn;
49
}
50
51
function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
52 61e047a5 Phil Davis
	if (!file_exists("/tmp/rrd_notice_sent.txt")) {
53 2159494f Ermal
		$_gb = exec("echo 'Converting RRD configuration to new format.  This might take a bit...' | wall");
54
		@touch("/tmp/rrd_notice_sent.txt");
55 fdd20aba Scott Ullrich
	}
56 b0a5b824 Seth Mos
	$numrraold = count($rrdoldxml['rra']);
57
	$numrranew = count($rrdnewxml['rra']);
58 2159494f Ermal
	$numdsold = count($rrdoldxml['ds']);
59 b0a5b824 Seth Mos
	$numdsnew = count($rrdnewxml['ds']);
60 086cf944 Phil Davis
	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));
61 5e5d5abc Renato Botelho
62 b0a5b824 Seth Mos
	/* add data sources not found in the old array from the new array */
63
	$i = 0;
64 61e047a5 Phil Davis
	foreach ($rrdnewxml['ds'] as $ds) {
65
		if (!is_array($rrdoldxml['ds'][$i])) {
66 b0a5b824 Seth Mos
			$rrdoldxml['ds'][$i] = $rrdnewxml['ds'][$i];
67 d9e896fa Seth Mos
			/* set unknown values to 0 */
68
			$rrdoldxml['ds'][$i]['last_ds'] = " 0.0000000000e+00 ";
69
			$rrdoldxml['ds'][$i]['value'] = " 0.0000000000e+00 ";
70
			$rrdoldxml['ds'][$i]['unknown_sec'] = "0";
71 b0a5b824 Seth Mos
		}
72
		$i++;
73
	}
74
75
	$i = 0;
76
	$rracountold = count($rrdoldxml['rra']);
77
	$rracountnew = count($rrdnewxml['rra']);
78
	/* process each RRA, which contain a database */
79 61e047a5 Phil Davis
	foreach ($rrdnewxml['rra'] as $rra) {
80
		if (!is_array($rrdoldxml['rra'][$i])) {
81 b0a5b824 Seth Mos
			$rrdoldxml['rra'][$i] = $rrdnewxml['rra'][$i];
82
		}
83
84
		$d = 0;
85
		/* process cdp_prep */
86
		$cdp_prep = $rra['cdp_prep'];
87 61e047a5 Phil Davis
		foreach ($cdp_prep['ds'] as $ds) {
88
			if (!is_array($rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d])) {
89 b0a5b824 Seth Mos
				$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d] = $rrdnewxml['rra'][$i]['cdp_prep']['ds'][$d];
90 d9e896fa Seth Mos
				$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['primary_value'] = " 0.0000000000e+00 ";
91
				$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['secondary_value'] = " 0.0000000000e+00 ";
92
				$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['value'] = " 0.0000000000e+00 ";
93
				$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['unknown_datapoints'] = "0";
94 b0a5b824 Seth Mos
			}
95
			$d++;
96
		}
97
98
		/* process database */
99
		$rows = $rra['database'];
100
		$k = 0;
101
		$rowcountold = count($rrdoldxml['rra'][$i]['database']['row']);
102
		$rowcountnew = count($rrdnewxml['rra'][$i]['database']['row']);
103 ddc26847 Seth Mos
		$rowcountdiff = $rowcountnew - $rowcountold;
104
		/* save old rows for a bit before we put the required empty rows before it */
105
		$rowsdata = $rows;
106
		$rowsempty = array();
107
		$r = 0;
108 61e047a5 Phil Davis
		while ($r < $rowcountdiff) {
109 ddc26847 Seth Mos
			$rowsempty[] = $rrdnewxml['rra'][$i]['database']['row'][$r];
110
			$r++;
111
		}
112
		$rows = $rowsempty + $rowsdata;
113 b0a5b824 Seth Mos
		/* now foreach the rows in the database */
114 61e047a5 Phil Davis
		foreach ($rows['row'] as $row) {
115
			if (!is_array($rrdoldxml['rra'][$i]['database']['row'][$k])) {
116 b0a5b824 Seth Mos
				$rrdoldxml['rra'][$i]['database']['row'][$k] = $rrdnewxml['rra'][$i]['database']['row'][$k];
117
			}
118
			$m = 0;
119
			$vcountold = count($rrdoldxml['rra'][$i]['database']['row'][$k]['v']);
120
			$vcountnew = count($rrdnewxml['rra'][$i]['database']['row'][$k]['v']);
121 61e047a5 Phil Davis
			foreach ($row['v'] as $value) {
122
				if (empty($rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m])) {
123
					if (isset($valid)) {
124 ed3ea464 Seth Mos
						$rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m] = "0.0000000000e+00 ";
125
					} else {
126
						$rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m] = $rrdnewxml['rra'][$i]['database']['row'][$k]['v'][$m];
127
					}
128
				} else {
129 61e047a5 Phil Davis
					if ($value <> " NaN ") {
130 ed3ea464 Seth Mos
						$valid = true;
131
					} else {
132
						$valid = false;
133
					}
134 b0a5b824 Seth Mos
				}
135
				$m++;
136
			}
137
			$k++;
138
		}
139
		$i++;
140
	}
141
142
	$numrranew = count($rrdoldxml['rra']);
143
	$numdsnew = count($rrdoldxml['ds']);
144 addc0439 Renato Botelho
	log_error(sprintf(gettext('The new RRD now has %1$s DS values and %2$s RRA databases'), $numdsnew, $numrranew));
145 b0a5b824 Seth Mos
	return $rrdoldxml;
146
}
147
148 ea4bc46f Seth Mos
function enable_rrd_graphing() {
149
	global $config, $g, $altq_list_queues;
150
151 61e047a5 Phil Davis
	if (platform_booting()) {
152 9eda6186 Carlos Eduardo Ramos
		echo gettext("Generating RRD graphs...");
153 61e047a5 Phil Davis
	}
154 ea4bc46f Seth Mos
155 afb6ae0c Renato Botelho
	$rrddbpath = "{$g['vardb_path']}/rrd/";
156 ea4bc46f Seth Mos
	$rrdgraphpath = "/usr/local/www/rrd";
157
158
	$traffic = "-traffic.rrd";
159
	$packets = "-packets.rrd";
160
	$states = "-states.rrd";
161
	$wireless = "-wireless.rrd";
162
	$queues = "-queues.rrd";
163
	$queuesdrop = "-queuedrops.rrd";
164
	$proc = "-processor.rrd";
165
	$mem = "-memory.rrd";
166 3ed917c7 jim-p
	$mbuf = "-mbuf.rrd";
167 33a37573 Viktor G
	$sensors = "-sensors.rrd";
168 ec51a222 thompsa
	$cellular = "-cellular.rrd";
169 edd2d8b7 smos
	$vpnusers = "-vpnusers.rrd";
170 20413b72 Warren Baker
	$captiveportalconcurrent = "-concurrent.rrd";
171
	$captiveportalloggedin = "-loggedin.rrd";
172 1f3eff9b nagyrobi
	$ntpd = "ntpd.rrd";
173 89f3ec04 heper
	$dhcpd = "-dhcpd.rrd";
174 ea4bc46f Seth Mos
175 d9acea75 Scott Ullrich
	$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
176 ea4bc46f Seth Mos
	$netstat = "/usr/bin/netstat";
177
	$awk = "/usr/bin/awk";
178 33a37573 Viktor G
	$sed = "/usr/bin/sed";
179 ea4bc46f Seth Mos
	$tar = "/usr/bin/tar";
180
	$pfctl = "/sbin/pfctl";
181
	$sysctl = "/sbin/sysctl";
182 cb7d18d5 Renato Botelho
	$php = "/usr/local/bin/php-cgi";
183 e9e295f7 jim-p
	$cpustats = "/usr/local/sbin/cpustats";
184 ea4bc46f Seth Mos
	$ifconfig = "/sbin/ifconfig";
185 20413b72 Warren Baker
	$captiveportal_gather = "/usr/local/bin/captiveportal_gather_stats.php";
186 89f3ec04 heper
	$dhcpd_gather = "/usr/local/bin/dhcpd_gather_stats.php";
187 617f9edf nagyrobi
	$ntpq = "/usr/local/sbin/ntpq";
188 ea4bc46f Seth Mos
189
	$rrdtrafficinterval = 60;
190
	$rrdwirelessinterval = 60;
191
	$rrdqueuesinterval = 60;
192
	$rrdqueuesdropinterval = 60;
193
	$rrdpacketsinterval = 60;
194
	$rrdstatesinterval = 60;
195
	$rrdlbpoolinterval = 60;
196
	$rrdprocinterval = 60;
197
	$rrdmeminterval = 60;
198 3ed917c7 jim-p
	$rrdmbufinterval = 60;
199 33a37573 Viktor G
	$rrdsensorsinterval = 60;
200 ec51a222 thompsa
	$rrdcellularinterval = 60;
201 55c08a96 smos
	$rrdvpninterval = 60;
202 20413b72 Warren Baker
	$rrdcaptiveportalinterval = 60;
203 1f3eff9b nagyrobi
	$rrdntpdinterval = 60;
204 89f3ec04 heper
	$rrddhcpdinterval = 60;
205 ea4bc46f Seth Mos
206
	$trafficvalid = $rrdtrafficinterval * 2;
207
	$wirelessvalid = $rrdwirelessinterval * 2;
208
	$queuesvalid = $rrdqueuesinterval * 2;
209
	$queuesdropvalid = $rrdqueuesdropinterval * 2;
210
	$packetsvalid = $rrdpacketsinterval * 2;
211
	$statesvalid = $rrdstatesinterval*2;
212
	$lbpoolvalid = $rrdlbpoolinterval * 2;
213
	$procvalid = $rrdlbpoolinterval * 2;
214
	$memvalid = $rrdmeminterval * 2;
215 3ed917c7 jim-p
	$mbufvalid = $rrdmbufinterval * 2;
216 33a37573 Viktor G
	$sensorsvalid = $rrdsensorsinterval * 2;
217 ec51a222 thompsa
	$cellularvalid = $rrdcellularinterval * 2;
218 edd2d8b7 smos
	$vpnvalid = $rrdvpninterval * 2;
219 20413b72 Warren Baker
	$captiveportalvalid = $rrdcaptiveportalinterval * 2;
220 1f3eff9b nagyrobi
	$ntpdvalid = $rrdntpdinterval * 2;
221 89f3ec04 heper
	$dhcpdvalid = $rrddhcpdinterval * 2;
222 4e322e2c Phil Davis
223 fa3b33a5 Renato Botelho
	/* Assume 2*10GigE for now */
224
	$downstream = 2500000000;
225
	$upstream = 2500000000;
226 ea4bc46f Seth Mos
227
	/* read the shaper config */
228
	read_altq_config();
229
230
	if (isset ($config['rrd']['enable'])) {
231
232
		/* create directory if needed */
233 3d83f02e jim-p
		if (!is_dir($rrddbpath)) {
234
			mkdir($rrddbpath, 0775);
235 ea4bc46f Seth Mos
		}
236 25cca20b jim-p
		chown($rrddbpath, "nobody");
237 ea4bc46f Seth Mos
238
		/* db update script */
239
		$rrdupdatesh = "#!/bin/sh\n";
240
		$rrdupdatesh .= "\n";
241 a555cc58 Seth Mos
		$rrdupdatesh .= "export TERM=dumb\n";
242 3d54aa10 Renato Botelho
		$rrdupdatesh .= "\n";
243 2568e151 Christian McDonald
		$rrdupdatesh .= 'echo $$ > ' . g_get('varrun_path') . '/updaterrd.sh.pid';
244 3d54aa10 Renato Botelho
		$rrdupdatesh .= "\n";
245 ea4bc46f Seth Mos
		$rrdupdatesh .= "counter=1\n";
246
		$rrdupdatesh .= "while [ \"\$counter\" -ne 0 ]\n";
247
		$rrdupdatesh .= "do\n";
248
		$rrdupdatesh .= "";
249
250
		$i = 0;
251 4563d12f Seth Mos
		$ifdescrs = get_configured_interface_with_descr();
252 edd2d8b7 smos
		/* IPsec counters */
253 4563d12f Seth Mos
		$ifdescrs['ipsec'] = "IPsec";
254 edd2d8b7 smos
		/* OpenVPN server counters */
255 f5b91462 Reid Linnemann
		$ovpncfg = config_get_path('openvpn/openvpn-server');
256
		if (is_array($ovpncfg)) {
257
			foreach ($ovpncfg as $server) {
258 55c08a96 smos
				$serverid = "ovpns" . $server['vpnid'];
259
				$ifdescrs[$serverid] = "{$server['description']}";
260
			}
261
		}
262 4563d12f Seth Mos
263 edd2d8b7 smos
		/* process all real and pseudo interfaces */
264 4563d12f Seth Mos
		foreach ($ifdescrs as $ifname => $ifdescr) {
265 65615d89 Seth Mos
			$temp = get_real_interface($ifname);
266 61e047a5 Phil Davis
			if ($temp <> "") {
267 65615d89 Seth Mos
				$realif = $temp;
268
			}
269 ea4bc46f Seth Mos
270
			/* TRAFFIC, set up the rrd file */
271
			if (!file_exists("$rrddbpath$ifname$traffic")) {
272
				$rrdcreate = "$rrdtool create $rrddbpath$ifname$traffic --step $rrdtrafficinterval ";
273
				$rrdcreate .= "DS:inpass:COUNTER:$trafficvalid:0:$downstream ";
274
				$rrdcreate .= "DS:outpass:COUNTER:$trafficvalid:0:$upstream ";
275
				$rrdcreate .= "DS:inblock:COUNTER:$trafficvalid:0:$downstream ";
276
				$rrdcreate .= "DS:outblock:COUNTER:$trafficvalid:0:$upstream ";
277 9bc8b6b6 Seth Mos
				$rrdcreate .= "DS:inpass6:COUNTER:$trafficvalid:0:$downstream ";
278
				$rrdcreate .= "DS:outpass6:COUNTER:$trafficvalid:0:$upstream ";
279
				$rrdcreate .= "DS:inblock6:COUNTER:$trafficvalid:0:$downstream ";
280
				$rrdcreate .= "DS:outblock6:COUNTER:$trafficvalid:0:$upstream ";
281 492b1314 N0YB
				$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
282
				$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
283
				$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
284 3e2ecafe N0YB
				$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
285 ea4bc46f Seth Mos
286
				create_new_rrd($rrdcreate);
287 cba9d7d9 Renato Botelho
				unset($rrdcreate);
288 ea4bc46f Seth Mos
			}
289
290
			/* enter UNKNOWN values in the RRD so it knows we rebooted. */
291 61e047a5 Phil Davis
			if (platform_booting()) {
292 9bc8b6b6 Seth Mos
				mwexec("$rrdtool update $rrddbpath$ifname$traffic N:U:U:U:U:U:U:U:U");
293 ea4bc46f Seth Mos
			}
294
295
			$rrdupdatesh .= "\n";
296 9bc8b6b6 Seth Mos
			$rrdupdatesh .= "# polling traffic for interface $ifname $realif IPv4/IPv6 counters \n";
297 a555cc58 Seth Mos
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$traffic N:";
298
			$rrdupdatesh .= "`$pfctl -vvsI -i {$realif} | awk '\\\n";
299
			$rrdupdatesh .= "/In4\/Pass/ { b4pi = \$6 };/Out4\/Pass/ { b4po = \$6 };/In4\/Block/ { b4bi = \$6 };/Out4\/Block/ { b4bo = \$6 };\\\n";
300
			$rrdupdatesh .= "/In6\/Pass/ { b6pi = \$6 };/Out6\/Pass/ { b6po = \$6 };/In6\/Block/ { b6bi = \$6 };/Out6\/Block/ { b6bo = \$6 };\\\n";
301
			$rrdupdatesh .= "END {print b4pi \":\" b4po \":\" b4bi \":\" b4bo \":\" b6pi \":\" b6po \":\" b6bi \":\" b6bo};'`\n";
302 ea4bc46f Seth Mos
303
			/* PACKETS, set up the rrd file */
304
			if (!file_exists("$rrddbpath$ifname$packets")) {
305
				$rrdcreate = "$rrdtool create $rrddbpath$ifname$packets --step $rrdpacketsinterval ";
306
				$rrdcreate .= "DS:inpass:COUNTER:$packetsvalid:0:$downstream ";
307
				$rrdcreate .= "DS:outpass:COUNTER:$packetsvalid:0:$upstream ";
308
				$rrdcreate .= "DS:inblock:COUNTER:$packetsvalid:0:$downstream ";
309
				$rrdcreate .= "DS:outblock:COUNTER:$packetsvalid:0:$upstream ";
310 9bc8b6b6 Seth Mos
				$rrdcreate .= "DS:inpass6:COUNTER:$packetsvalid:0:$downstream ";
311
				$rrdcreate .= "DS:outpass6:COUNTER:$packetsvalid:0:$upstream ";
312
				$rrdcreate .= "DS:inblock6:COUNTER:$packetsvalid:0:$downstream ";
313
				$rrdcreate .= "DS:outblock6:COUNTER:$packetsvalid:0:$upstream ";
314 492b1314 N0YB
				$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
315
				$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
316
				$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
317 3e2ecafe N0YB
				$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
318 ea4bc46f Seth Mos
319
				create_new_rrd($rrdcreate);
320 cba9d7d9 Renato Botelho
				unset($rrdcreate);
321 ea4bc46f Seth Mos
			}
322
323
			/* enter UNKNOWN values in the RRD so it knows we rebooted. */
324 61e047a5 Phil Davis
			if (platform_booting()) {
325 9bc8b6b6 Seth Mos
				mwexec("$rrdtool update $rrddbpath$ifname$packets N:U:U:U:U:U:U:U:U");
326 ea4bc46f Seth Mos
			}
327
328
			$rrdupdatesh .= "\n";
329
			$rrdupdatesh .= "# polling packets for interface $ifname $realif \n";
330 a555cc58 Seth Mos
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$packets N:";
331
			$rrdupdatesh .= "`$pfctl -vvsI -i {$realif} | awk '\\\n";
332
			$rrdupdatesh .= "/In4\/Pass/ { b4pi = \$4 };/Out4\/Pass/ { b4po = \$4 };/In4\/Block/ { b4bi = \$4 };/Out4\/Block/ { b4bo = \$4 };\\\n";
333
			$rrdupdatesh .= "/In6\/Pass/ { b6pi = \$4 };/Out6\/Pass/ { b6po = \$4 };/In6\/Block/ { b6bi = \$4 };/Out6\/Block/ { b6bo = \$4 };\\\n";
334
			$rrdupdatesh .= "END {print b4pi \":\" b4po \":\" b4bi \":\" b4bo \":\" b6pi \":\" b6po \":\" b6bi \":\" b6bo};'`\n";
335 ea4bc46f Seth Mos
336
			/* WIRELESS, set up the rrd file */
337 61e047a5 Phil Davis
			if ($config['interfaces'][$ifname]['wireless']['mode'] == "bss") {
338 ea4bc46f Seth Mos
				if (!file_exists("$rrddbpath$ifname$wireless")) {
339
					$rrdcreate = "$rrdtool create $rrddbpath$ifname$wireless --step $rrdwirelessinterval ";
340
					$rrdcreate .= "DS:snr:GAUGE:$wirelessvalid:0:1000 ";
341
					$rrdcreate .= "DS:rate:GAUGE:$wirelessvalid:0:1000 ";
342
					$rrdcreate .= "DS:channel:GAUGE:$wirelessvalid:0:1000 ";
343 492b1314 N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
344
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
345
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
346 3e2ecafe N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
347 5e5d5abc Renato Botelho
348 ea4bc46f Seth Mos
					create_new_rrd($rrdcreate);
349 cba9d7d9 Renato Botelho
					unset($rrdcreate);
350 ea4bc46f Seth Mos
				}
351
352
				/* enter UNKNOWN values in the RRD so it knows we rebooted. */
353 61e047a5 Phil Davis
				if (platform_booting()) {
354 e256e9d4 smos
					mwexec("$rrdtool update $rrddbpath$ifname$wireless N:U:U:U");
355 ea4bc46f Seth Mos
				}
356
357
				$rrdupdatesh .= "\n";
358
				$rrdupdatesh .= "# polling wireless for interface $ifname $realif \n";
359 e9e295f7 jim-p
				$rrdupdatesh .= "WIFI=`$ifconfig {$realif} list sta| $awk 'gsub(\"M\", \"\") {getline 2;print substr(\$5, 0, length(\$5)-2) \":\" $4 \":\" $3}'`\n";
360 488595df smos
				$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$wireless N:\${WIFI}\n";
361 ea4bc46f Seth Mos
			}
362
363 edd2d8b7 smos
			/* OpenVPN, set up the rrd file */
364 61e047a5 Phil Davis
			if (stristr($ifname, "ovpns")) {
365 edd2d8b7 smos
				if (!file_exists("$rrddbpath$ifname$vpnusers")) {
366
					$rrdcreate = "$rrdtool create $rrddbpath$ifname$vpnusers --step $rrdvpninterval ";
367
					$rrdcreate .= "DS:users:GAUGE:$vpnvalid:0:10000 ";
368 492b1314 N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
369
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
370
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
371 3e2ecafe N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
372 5e5d5abc Renato Botelho
373 edd2d8b7 smos
					create_new_rrd($rrdcreate);
374 cba9d7d9 Renato Botelho
					unset($rrdcreate);
375 edd2d8b7 smos
				}
376
377
				/* enter UNKNOWN values in the RRD so it knows we rebooted. */
378 61e047a5 Phil Davis
				if (platform_booting()) {
379 edd2d8b7 smos
					mwexec("$rrdtool update $rrddbpath$ifname$vpnusers N:U");
380
				}
381 ea4bc46f Seth Mos
382 f5b91462 Reid Linnemann
				$ovpncfg = config_get_path('openvpn/openvpn-server');
383
				if (is_array($ovpncfg)) {
384
					foreach ($ovpncfg as $server) {
385 61e047a5 Phil Davis
						if ("ovpns{$server['vpnid']}" == $ifname) {
386 edd2d8b7 smos
							$port = $server['local_port'];
387 5f250a24 smos
							$vpnid = $server['vpnid'];
388 edd2d8b7 smos
						}
389
					}
390
				}
391
				$rrdupdatesh .= "\n";
392
				$rrdupdatesh .= "# polling vpn users for interface $ifname $realif port $port\n";
393
				$rrdupdatesh .= "list_current_users() {\n";
394
				$rrdupdatesh .= " sleep 0.2\n";
395
				$rrdupdatesh .= " echo \"status 2\"\n";
396
				$rrdupdatesh .= " sleep 0.2\n";
397
				$rrdupdatesh .= " echo \"quit\"\n";
398
				$rrdupdatesh .= "}\n";
399 348c2af1 jim-p
				$rrdupdatesh .= "OVPN=`list_current_users | /usr/bin/nc -U {$g['openvpn_base']}/server{$vpnid}/sock | /usr/bin/awk -F\",\" '/^CLIENT_LIST/ {print \$2}' | /usr/bin/wc -l | /usr/bin/awk '{print $1}'`\n";
400 e9e295f7 jim-p
				$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$vpnusers N:\${OVPN}\n";
401 edd2d8b7 smos
			}
402 ea4bc46f Seth Mos
403 edd2d8b7 smos
			/* QUEUES, set up the queues databases */
404 aa3bbcb4 Steve Wheeler
			if (($altq_list_queues[$ifname]) &&
405 55d340b8 Viktor G
			    !empty($altq_list_queues[$ifname]->get_queue_list())) {
406 edd2d8b7 smos
				$altq =& $altq_list_queues[$ifname];
407
				/* NOTE: Is it worth as its own function?! */
408
				switch ($altq->GetBwscale()) {
409
					case "Gb":
410
						$factor = 1024 * 1024 * 1024;
411 e8c516a0 Phil Davis
						break;
412 edd2d8b7 smos
					case "Mb":
413 e8c516a0 Phil Davis
						$factor = 1024 * 1024;
414
						break;
415 edd2d8b7 smos
					case "Kb":
416 e8c516a0 Phil Davis
						$factor = 1024;
417
						break;
418 edd2d8b7 smos
					case "b":
419
					default:
420 e8c516a0 Phil Davis
						$factor = 1;
421
						break;
422 edd2d8b7 smos
				}
423 3c95346d jim-p
				$qbandwidth = (int) $altq->GetBandwidth() * $factor;
424 6c07db48 Phil Davis
				if ($qbandwidth <= 0) {
425 edd2d8b7 smos
					$qbandwidth = 100 * 1000 * 1000; /* 100Mbit */
426
				}
427
				$qlist =& $altq->get_queue_list($notused);
428
				if (!file_exists("$rrddbpath$ifname$queues")) {
429
					$rrdcreate = "$rrdtool create $rrddbpath$ifname$queues --step $rrdqueuesinterval ";
430
					/* loop list of shaper queues */
431
					$q = 0;
432
					foreach ($qlist as $qname => $q) {
433
						$rrdcreate .= "DS:$qname:COUNTER:$queuesvalid:0:$qbandwidth ";
434 ea4bc46f Seth Mos
					}
435
436 492b1314 N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
437
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
438
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
439 3e2ecafe N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
440 ea4bc46f Seth Mos
441 edd2d8b7 smos
					create_new_rrd($rrdcreate);
442 cba9d7d9 Renato Botelho
					unset($rrdcreate);
443 edd2d8b7 smos
				}
444 ea4bc46f Seth Mos
445 edd2d8b7 smos
				if (!file_exists("$rrddbpath$ifname$queuesdrop")) {
446
					$rrdcreate = "$rrdtool create $rrddbpath$ifname$queuesdrop --step $rrdqueuesdropinterval ";
447
					/* loop list of shaper queues */
448
					$q = 0;
449
					foreach ($qlist as $qname => $q) {
450
						$rrdcreate .= "DS:$qname:COUNTER:$queuesdropvalid:0:$qbandwidth ";
451 ea4bc46f Seth Mos
					}
452
453 492b1314 N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
454
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
455
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
456 3e2ecafe N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
457 edd2d8b7 smos
458
					create_new_rrd($rrdcreate);
459 cba9d7d9 Renato Botelho
					unset($rrdcreate);
460 edd2d8b7 smos
				}
461
462 61e047a5 Phil Davis
				if (platform_booting()) {
463 edd2d8b7 smos
					$rrdqcommand = "-t ";
464
					$rrducommand = "N";
465 857a4a79 jim-p
					$qi = 0;
466 edd2d8b7 smos
					foreach ($qlist as $qname => $q) {
467 61e047a5 Phil Davis
						if ($qi == 0) {
468 edd2d8b7 smos
							$rrdqcommand .= "{$qname}";
469
						} else {
470
							$rrdqcommand .= ":{$qname}";
471 ea4bc46f Seth Mos
						}
472 857a4a79 jim-p
						$qi++;
473 edd2d8b7 smos
						$rrducommand .= ":U";
474 ea4bc46f Seth Mos
					}
475 edd2d8b7 smos
					mwexec("$rrdtool update $rrddbpath$ifname$queues $rrdqcommand $rrducommand");
476
					mwexec("$rrdtool update $rrddbpath$ifname$queuesdrop $rrdqcommand $rrducommand");
477 ea4bc46f Seth Mos
				}
478 edd2d8b7 smos
479
				/* awk function to gather shaper data */
480
				/* yes, it's special */
481
				$rrdupdatesh .= "` pfctl -vsq -i {$realif} | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queues \" } ";
482
				$rrdupdatesh .= "{ ";
483
				$rrdupdatesh .= "if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { ";
484
				$rrdupdatesh .= " dsname = dsname \":\" \$2 ; ";
485
				$rrdupdatesh .= " q=1; ";
486
				$rrdupdatesh .= "} ";
487
				$rrdupdatesh .= " else if ((\$4 == \"bytes:\") && ( q == 1 ) ) { ";
488
				$rrdupdatesh .= " dsdata = dsdata \":\" \$5 ; ";
489
				$rrdupdatesh .= " q=0; ";
490
				$rrdupdatesh .= "} ";
491
				$rrdupdatesh .= "} END { ";
492
				$rrdupdatesh .= " dsname = substr(dsname,2); ";
493
				$rrdupdatesh .= " dsdata = substr(dsdata,2); ";
494
				$rrdupdatesh .= " printf \"-t \" dsname \" N:\" dsdata }' ";
495
				$rrdupdatesh .= " dsname=\"\" dsdata=\"\"`\n\n";
496
497
				$rrdupdatesh .= "` pfctl -vsq -i {$realif} | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queuesdrop \" } ";
498
				$rrdupdatesh .= "{ ";
499
				$rrdupdatesh .= "if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { ";
500
				$rrdupdatesh .= " dsname = dsname \":\" \$2 ; ";
501
				$rrdupdatesh .= " q=1; ";
502
				$rrdupdatesh .= "} ";
503
				$rrdupdatesh .= " else if ((\$4 == \"bytes:\") && ( q == 1 ) ) { ";
504
				$rrdupdatesh .= " dsdata = dsdata \":\" \$8 ; ";
505
				$rrdupdatesh .= " q=0; ";
506
				$rrdupdatesh .= "} ";
507
				$rrdupdatesh .= "} END { ";
508
				$rrdupdatesh .= " dsname = substr(dsname,2); ";
509
				$rrdupdatesh .= " dsdata = substr(dsdata,2); ";
510
				$rrdupdatesh .= " printf \"-t \" dsname \" N:\" dsdata }' ";
511
				$rrdupdatesh .= " dsname=\"\" dsdata=\"\"`\n\n";
512
			}
513 5e589685 smos
514
			/* 3G interfaces */
515 61e047a5 Phil Davis
			if (preg_match("/ppp[0-9]+/i", $realif))	{
516 5e589685 smos
				if (!file_exists("$rrddbpath$ifname$cellular")) {
517
					$rrdcreate = "$rrdtool create $rrddbpath$ifname$cellular --step $rrdcellularinterval ";
518
					$rrdcreate .= "DS:rssi:GAUGE:$cellularvalid:0:100 ";
519
					$rrdcreate .= "DS:upstream:GAUGE:$cellularvalid:0:100000000 ";
520
					$rrdcreate .= "DS:downstream:GAUGE:$cellularvalid:0:100000000 ";
521 492b1314 N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
522
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
523
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
524 3e2ecafe N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
525 5e589685 smos
					create_new_rrd($rrdcreate);
526 cba9d7d9 Renato Botelho
					unset($rrdcreate);
527 5e589685 smos
				}
528
529
				/* enter UNKNOWN values in the RRD so it knows we rebooted. */
530 61e047a5 Phil Davis
				if (platform_booting()) {
531 5e589685 smos
					mwexec("$rrdtool update $rrddbpath$ifname$cellular N:U:U:U");
532
				}
533
534
				$rrdupdatesh .= "\n";
535
				$rrdupdatesh .= "# polling 3G\n";
536 2b095a33 smos
				$rrdupdatesh .= "GSTATS=`awk -F, 'getline 2 {print \$2 \":\" \$8 \":\" \$9}' < /tmp/3gstats.$ifname`\n";
537
				$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$cellular N:\"\$GSTATS\"";
538 5e589685 smos
			}
539
540 ea4bc46f Seth Mos
		}
541
		$i++;
542
543
		/* System only statistics */
544
		$ifname = "system";
545
546 edd2d8b7 smos
		/* STATES, create pf states database */
547 61e047a5 Phil Davis
		if (!file_exists("$rrddbpath$ifname$states")) {
548 edd2d8b7 smos
			$rrdcreate = "$rrdtool create $rrddbpath$ifname$states --step $rrdstatesinterval ";
549
			$rrdcreate .= "DS:pfrate:GAUGE:$statesvalid:0:10000000 ";
550
			$rrdcreate .= "DS:pfstates:GAUGE:$statesvalid:0:10000000 ";
551
			$rrdcreate .= "DS:pfnat:GAUGE:$statesvalid:0:10000000 ";
552
			$rrdcreate .= "DS:srcip:GAUGE:$statesvalid:0:10000000 ";
553
			$rrdcreate .= "DS:dstip:GAUGE:$statesvalid:0:10000000 ";
554 492b1314 N0YB
			$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
555
			$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
556
			$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
557 3e2ecafe N0YB
			$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
558 edd2d8b7 smos
559
			create_new_rrd($rrdcreate);
560 cba9d7d9 Renato Botelho
			unset($rrdcreate);
561 edd2d8b7 smos
		}
562 ea4bc46f Seth Mos
563 edd2d8b7 smos
		/* enter UNKNOWN values in the RRD so it knows we rebooted. */
564 61e047a5 Phil Davis
		if (platform_booting()) {
565 edd2d8b7 smos
			mwexec("$rrdtool update $rrddbpath$ifname$states N:U:U:U:U:U");
566
		}
567 ea4bc46f Seth Mos
568 edd2d8b7 smos
		/* the pf states gathering function. */
569 d9fa4584 Reid Linnemann
		$nat_match_pattern = '\(([0-9a-f:.]|\[|\])+\) (\->|<\-)';
570 edd2d8b7 smos
		$rrdupdatesh .= "\n";
571
		$rrdupdatesh .= "pfctl_si_out=\"` $pfctl -si > /tmp/pfctl_si_out `\"\n";
572
		$rrdupdatesh .= "pfctl_ss_out=\"` $pfctl -ss > /tmp/pfctl_ss_out`\"\n";
573
		$rrdupdatesh .= "pfrate=\"` cat /tmp/pfctl_si_out | egrep \"inserts|removals\" | awk '{ pfrate = \$3 + pfrate } {print pfrate}'|tail -1 `\"\n";
574 d9fa4584 Reid Linnemann
		$rrdupdatesh .= "pfstates=\"` cat /tmp/pfctl_ss_out | egrep -v '{$nat_match_pattern}' | wc -l|sed 's/ //g'`\"\n";
575
		$rrdupdatesh .= "pfnat=\"` cat /tmp/pfctl_ss_out | egrep '{$nat_match_pattern}' | wc -l|sed 's/ //g' `\"\n";
576
		$rrdupdatesh .= "srcip=\"` cat /tmp/pfctl_ss_out | egrep -v '{$nat_match_pattern}' | grep '\\->' | awk '{print \$3}' | awk -F: '{print \$1}' | sort -u|wc -l|sed 's/ //g' `\"\n";
577
		$rrdupdatesh .= "dstip=\"` cat /tmp/pfctl_ss_out | egrep -v '{$nat_match_pattern}' | grep '<\\-' | awk '{print \$3}' | awk -F: '{print \$1}' | sort -u|wc -l|sed 's/ //g' `\"\n";
578 edd2d8b7 smos
		$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$states N:\$pfrate:\$pfstates:\$pfnat:\$srcip:\$dstip\n\n";
579
580
		/* End pf states statistics */
581
582
		/* CPU, create CPU statistics database */
583 61e047a5 Phil Davis
		if (!file_exists("$rrddbpath$ifname$proc")) {
584 edd2d8b7 smos
			$rrdcreate = "$rrdtool create $rrddbpath$ifname$proc --step $rrdprocinterval ";
585
			$rrdcreate .= "DS:user:GAUGE:$procvalid:0:10000000 ";
586
			$rrdcreate .= "DS:nice:GAUGE:$procvalid:0:10000000 ";
587
			$rrdcreate .= "DS:system:GAUGE:$procvalid:0:10000000 ";
588
			$rrdcreate .= "DS:interrupt:GAUGE:$procvalid:0:10000000 ";
589
			$rrdcreate .= "DS:processes:GAUGE:$procvalid:0:10000000 ";
590 492b1314 N0YB
			$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
591
			$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
592
			$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
593 3e2ecafe N0YB
			$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
594 edd2d8b7 smos
595
			create_new_rrd($rrdcreate);
596 cba9d7d9 Renato Botelho
			unset($rrdcreate);
597 edd2d8b7 smos
		}
598 ea4bc46f Seth Mos
599 edd2d8b7 smos
		/* enter UNKNOWN values in the RRD so it knows we rebooted. */
600 61e047a5 Phil Davis
		if (platform_booting()) {
601 edd2d8b7 smos
			mwexec("$rrdtool update $rrddbpath$ifname$proc N:U:U:U:U:U");
602
		}
603 ea4bc46f Seth Mos
604 edd2d8b7 smos
		/* the CPU stats gathering function. */
605 e9e295f7 jim-p
		$rrdupdatesh .= "CPU=`$cpustats | cut -f1-4 -d':'`\n";
606
		/* Using ps uxaH will count all processes including system threads. Top was undercounting. */
607
		$rrdupdatesh .= "PROCS=`ps uxaH | wc -l | awk '{print \$1;}'`\n";
608
		$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$proc N:\${CPU}:\${PROCS}\n";
609 edd2d8b7 smos
610
		/* End CPU statistics */
611
612
		/* Memory, create Memory statistics database */
613 61e047a5 Phil Davis
		if (!file_exists("$rrddbpath$ifname$mem")) {
614 edd2d8b7 smos
			$rrdcreate = "$rrdtool create $rrddbpath$ifname$mem --step $rrdmeminterval ";
615
			$rrdcreate .= "DS:active:GAUGE:$memvalid:0:10000000 ";
616
			$rrdcreate .= "DS:inactive:GAUGE:$memvalid:0:10000000 ";
617
			$rrdcreate .= "DS:free:GAUGE:$memvalid:0:10000000 ";
618
			$rrdcreate .= "DS:cache:GAUGE:$memvalid:0:10000000 ";
619
			$rrdcreate .= "DS:wire:GAUGE:$memvalid:0:10000000 ";
620 0d83ed08 jim-p
			$rrdcreate .= "DS:userwire:GAUGE:$memvalid:0:10000000 ";
621
			$rrdcreate .= "DS:laundry:GAUGE:$memvalid:0:10000000 ";
622
			$rrdcreate .= "DS:buffers:GAUGE:$memvalid:0:10000000 ";
623 492b1314 N0YB
			$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
624
			$rrdcreate .= "RRA:MIN:0.5:5:720 ";
625
			$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
626 3e2ecafe N0YB
			$rrdcreate .= "RRA:MIN:0.5:1440:2284 ";
627 492b1314 N0YB
			$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
628
			$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
629
			$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
630 3e2ecafe N0YB
			$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
631 492b1314 N0YB
			$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
632
			$rrdcreate .= "RRA:MAX:0.5:5:720 ";
633
			$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
634 3e2ecafe N0YB
			$rrdcreate .= "RRA:MAX:0.5:1440:2284";
635 edd2d8b7 smos
636
			create_new_rrd($rrdcreate);
637 cba9d7d9 Renato Botelho
			unset($rrdcreate);
638 edd2d8b7 smos
		}
639 ea4bc46f Seth Mos
640 edd2d8b7 smos
		/* enter UNKNOWN values in the RRD so it knows we rebooted. */
641 61e047a5 Phil Davis
		if (platform_booting()) {
642 6f8ad15a jim-p
			mwexec("$rrdtool update $rrddbpath$ifname$mem N:U:U:U:U:U:U:U:U");
643 edd2d8b7 smos
		}
644 ea4bc46f Seth Mos
645 0d83ed08 jim-p
		/* Memory stats gathering function. */
646
		$rrdupdatesh .= "MEM=`$sysctl -qn ";
647
		/* Total pages */
648
		$rrdupdatesh .= "vm.stats.vm.v_page_count ";
649
		/* Active pages  */
650
		$rrdupdatesh .= "vm.stats.vm.v_active_count ";
651
		/* Inactive pages */
652
		$rrdupdatesh .= "vm.stats.vm.v_inactive_count ";
653
		/* Free pages  */
654
		$rrdupdatesh .= "vm.stats.vm.v_free_count ";
655
		if (is_module_loaded('zfs.ko')) {
656
			/* If the system is using ZFS, use ARC size as "cache" (value is bytes, not pages) */
657
			$rrdupdatesh .= "kstat.zfs.misc.arcstats.size ";
658
		} else {
659
			/* If the system is using UFS, use dirhash memory as "cache" (value is bytes, not pages) */
660
			$rrdupdatesh .= "vfs.ufs.dirhash_mem ";
661
		}
662
		/* Wired pages */
663
		$rrdupdatesh .= "vm.stats.vm.v_wire_count ";
664
		/* User wired pages */
665
		$rrdupdatesh .= "vm.stats.vm.v_user_wire_count ";
666
		/* Laundy pages */
667
		$rrdupdatesh .= "vm.stats.vm.v_laundry_count ";
668
		/* UFS Buffer space (value is in bytes, not pages) */
669
		$rrdupdatesh .= "vfs.bufspace ";
670
		/* Page size for calculations */
671
		$rrdupdatesh .= "hw.pagesize ";
672
		$rrdupdatesh .= " | ";
673
		/* Start the AWK code */
674
		$rrdupdatesh .= " $awk '{";
675
		/* Assign sysctl output to named variables */
676
		$rrdupdatesh .= "getline active;getline inactive;getline free;getline cache;getline wire;getline userwire;getline laundry;getline buffers;getline pagesize;";
677
		/* Divide cache and buffer values by page size so all values are in the same units */
678
		$rrdupdatesh .= "cache=(cache/pagesize);buffers=(buffers/pagesize);";
679
		/* Start of RRD-friendly output */
680
		$rrdupdatesh .= "printf ";
681
		/* Calculate values as a percentage of total pages */
682
		/* Active pages */
683
		$rrdupdatesh .= "((active/$0) * 100)";
684
		/* Inactive pages */
685
		$rrdupdatesh .= "\":\"((inactive/$0) * 100)";
686
		/* Free pages */
687
		$rrdupdatesh .= "\":\"((free/$0) * 100)";
688
		/* Cache (previously converted to pages) */
689
		$rrdupdatesh .= "\":\"((cache/$0) * 100)";
690
		/* Wired pages less cache and buffer pages (which are included in wired pages) */
691
		$rrdupdatesh .= "\":\"((wire - (cache + buffers))/$0 * 100)";
692
		/* User wired pages */
693
		$rrdupdatesh .= "\":\"((userwire/$0) * 100)";
694
		/* Laundry pages */
695
		$rrdupdatesh .= "\":\"((laundry/$0) * 100)";
696
		/* UFS Buffer space (previously converted to pages) */
697
		$rrdupdatesh .= "\":\"((buffers/$0) * 100)";
698
		/* Finish the AWK code */
699
		$rrdupdatesh .= "}'`\n";
700
		/* Update the database with new values */
701 e9e295f7 jim-p
		$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$mem N:\${MEM}\n";
702 5e5d5abc Renato Botelho
703 edd2d8b7 smos
		/* End Memory statistics */
704
705 3ed917c7 jim-p
		/* mbuf, create mbuf statistics database */
706 61e047a5 Phil Davis
		if (!file_exists("$rrddbpath$ifname$mbuf")) {
707 3ed917c7 jim-p
			$rrdcreate = "$rrdtool create $rrddbpath$ifname$mbuf --step $rrdmbufinterval ";
708
			$rrdcreate .= "DS:current:GAUGE:$mbufvalid:0:10000000 ";
709
			$rrdcreate .= "DS:cache:GAUGE:$mbufvalid:0:10000000 ";
710
			$rrdcreate .= "DS:total:GAUGE:$mbufvalid:0:10000000 ";
711
			$rrdcreate .= "DS:max:GAUGE:$mbufvalid:0:10000000 ";
712
			$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
713
			$rrdcreate .= "RRA:MIN:0.5:5:720 ";
714
			$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
715 3e2ecafe N0YB
			$rrdcreate .= "RRA:MIN:0.5:1440:2284 ";
716 3ed917c7 jim-p
			$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
717
			$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
718
			$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
719 3e2ecafe N0YB
			$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
720 3ed917c7 jim-p
			$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
721
			$rrdcreate .= "RRA:MAX:0.5:5:720 ";
722
			$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
723 3e2ecafe N0YB
			$rrdcreate .= "RRA:MAX:0.5:1440:2284";
724 3ed917c7 jim-p
725
			create_new_rrd($rrdcreate);
726
			unset($rrdcreate);
727
		}
728
729
		/* enter UNKNOWN values in the RRD so it knows we rebooted. */
730 61e047a5 Phil Davis
		if (platform_booting()) {
731 06ff126e N0YB
			mwexec("$rrdtool update $rrddbpath$ifname$mbuf N:U:U:U:U");
732 3ed917c7 jim-p
		}
733
734
		/* the mbuf stats gathering function. */
735
		$rrdupdatesh .= "MBUF=`$netstat -m | ";
736
		$rrdupdatesh .= " $awk '/mbuf clusters in use/ { gsub(/\//, \":\", $1); print $1; }'`\n";
737
		$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$mbuf N:\${MBUF}\n";
738
739
		/* End mbuf statistics */
740
741 33a37573 Viktor G
		/* CPU temperature */
742
743
		$sensors_array = array();
744
		$unknown = "";
745
		$rrdupdateds = "";
746
		$rrdsensors = "";
747 aa3bbcb4 Steve Wheeler
		$_gb = exec("/sbin/sysctl -q hw.acpi.thermal dev.cpu dev.t5nex dev.armada_thermal dev.cordbuc dev.pchtherm | /usr/bin/grep temperature | /usr/bin/cut -d':' -f1", $sensors_array);
748 33a37573 Viktor G
749
		if (!empty($sensors_array)) {
750
			foreach ($sensors_array as $sensor) {
751
				preg_match("/^(.+)\.(.+\..+)\.temperature/", $sensor, $sensor_match);
752
				$sensor_name = str_replace(".", "_", $sensor_match[2]);
753
				$rrdcreateds .= "DS:$sensor_name:GAUGE:$sensorsvalid:0:100 ";
754
				$unknown .= ":U";
755
				$rrddsname = strtoupper($sensor_name);
756
				$rrdupdateds .= "$rrddsname=`$sysctl -qn $sensor | $sed 's/C//'`\n";
757
				$rrdsensors .= ":\${$rrddsname}";
758
			}
759
			if (!file_exists("$rrddbpath$ifname$sensors")) {
760
				$rrdcreate = "$rrdtool create $rrddbpath$ifname$sensors --step $rrdsensorsinterval ";
761
				$rrdcreate .= $rrdcreateds;
762
				$rrdcreate .= "RRA:MIN:0.5:5:720 ";
763
				$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
764
				$rrdcreate .= "RRA:MIN:0.5:1440:2284 ";
765
				$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
766
				$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
767
				$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
768
				$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
769
				$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
770
				$rrdcreate .= "RRA:MAX:0.5:5:720 ";
771
				$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
772
				$rrdcreate .= "RRA:MAX:0.5:1440:2284";
773
774
				create_new_rrd($rrdcreate);
775
				unset($rrdcreate);
776
			}
777
778
			/* enter UNKNOWN values in the RRD so it knows we rebooted. */
779
			if (platform_booting()) {
780
				mwexec("$rrdtool update $rrddbpath$ifname$sensors N$unknown");
781
			}
782
783
			/* the CPU temp gathering function. */
784
785
			$rrdupdatesh .= $rrdupdateds;
786
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$sensors N$rrdsensors\n";
787
		}
788
789
		/* End CPU temperature */
790
791 20413b72 Warren Baker
		/* Captive Portal statistics, set up the rrd file */
792 61e047a5 Phil Davis
		if (is_array($config['captiveportal'])) {
793 cba9d7d9 Renato Botelho
			foreach ($config['captiveportal'] as $cpkey => $cp) {
794 61e047a5 Phil Davis
				if (!isset($cp['enable'])) {
795 cba9d7d9 Renato Botelho
					continue;
796 61e047a5 Phil Davis
				}
797 cba9d7d9 Renato Botelho
798
				$ifname= "captiveportal";
799
				$concurrent_filename = $rrddbpath . $ifname . '-' . $cpkey . $captiveportalconcurrent;
800
				if (!file_exists("$concurrent_filename")) {
801
					$rrdcreate = "$rrdtool create $concurrent_filename --step $rrdcaptiveportalinterval ";
802
					$rrdcreate .= "DS:concurrentusers:GAUGE:$captiveportalvalid:0:10000 ";
803 492b1314 N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
804
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
805
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
806 3e2ecafe N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
807 492b1314 N0YB
					$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
808
					$rrdcreate .= "RRA:MIN:0.5:5:720 ";
809
					$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
810 3e2ecafe N0YB
					$rrdcreate .= "RRA:MIN:0.5:1440:2284 ";
811 492b1314 N0YB
					$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
812
					$rrdcreate .= "RRA:MAX:0.5:5:720 ";
813
					$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
814 3e2ecafe N0YB
					$rrdcreate .= "RRA:MAX:0.5:1440:2284 ";
815 492b1314 N0YB
					$rrdcreate .= "RRA:LAST:0.5:1:1200 ";
816
					$rrdcreate .= "RRA:LAST:0.5:5:720 ";
817
					$rrdcreate .= "RRA:LAST:0.5:60:1860 ";
818 3e2ecafe N0YB
					$rrdcreate .= "RRA:LAST:0.5:1440:2284 ";
819 20413b72 Warren Baker
820 cba9d7d9 Renato Botelho
					create_new_rrd($rrdcreate);
821
					unset($rrdcreate);
822
				}
823 20413b72 Warren Baker
824 cba9d7d9 Renato Botelho
				/* enter UNKNOWN values in the RRD so it knows we rebooted. */
825 61e047a5 Phil Davis
				if (platform_booting()) {
826 cba9d7d9 Renato Botelho
					mwexec("$rrdtool update $concurrent_filename N:U");
827
				}
828 5e5d5abc Renato Botelho
829 cba9d7d9 Renato Botelho
				/* the Captive Portal stats gathering function. */
830
				$rrdupdatesh .= "\n";
831
				$rrdupdatesh .= "# polling Captive Portal for number of concurrent users\n";
832 9e378421 jim-p
				$rrdupdatesh .= "CP=`${php} -q ${captiveportal_gather} '${cpkey}' 'concurrent'`\n";
833 cba9d7d9 Renato Botelho
				$rrdupdatesh .= "$rrdtool update $concurrent_filename \${CP}\n";
834
835
				$loggedin_filename = $rrddbpath . $ifname . '-' . $cpkey . $captiveportalloggedin;
836
				if (!file_exists("$loggedin_filename")) {
837
					$rrdcreate = "$rrdtool create $loggedin_filename --step $rrdcaptiveportalinterval ";
838
					$rrdcreate .= "DS:loggedinusers:GAUGE:$captiveportalvalid:0:10000 ";
839 492b1314 N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
840
					$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
841
					$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
842 3e2ecafe N0YB
					$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
843 492b1314 N0YB
					$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
844
					$rrdcreate .= "RRA:MIN:0.5:5:720 ";
845
					$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
846 3e2ecafe N0YB
					$rrdcreate .= "RRA:MIN:0.5:1440:2284 ";
847 492b1314 N0YB
					$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
848
					$rrdcreate .= "RRA:MAX:0.5:5:720 ";
849
					$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
850 3e2ecafe N0YB
					$rrdcreate .= "RRA:MAX:0.5:1440:2284 ";
851 492b1314 N0YB
					$rrdcreate .= "RRA:LAST:0.5:1:1200 ";
852
					$rrdcreate .= "RRA:LAST:0.5:5:720 ";
853
					$rrdcreate .= "RRA:LAST:0.5:60:1860 ";
854 3e2ecafe N0YB
					$rrdcreate .= "RRA:LAST:0.5:1440:2284 ";
855 20413b72 Warren Baker
856 cba9d7d9 Renato Botelho
					create_new_rrd($rrdcreate);
857
					unset($rrdcreate);
858
				}
859 20413b72 Warren Baker
860 cba9d7d9 Renato Botelho
				/* enter UNKNOWN values in the RRD so it knows we rebooted. */
861 61e047a5 Phil Davis
				if (platform_booting()) {
862 cba9d7d9 Renato Botelho
					mwexec("$rrdtool update $loggedin_filename N:U");
863
				}
864 20413b72 Warren Baker
865 cba9d7d9 Renato Botelho
				/* the Captive Portal stats gathering function. */
866
				$rrdupdatesh .= "\n";
867
				$rrdupdatesh .= "# polling Captive Portal for number of logged in users\n";
868 9e378421 jim-p
				$rrdupdatesh .= "CP=`${php} -q ${captiveportal_gather} '${cpkey}' 'loggedin'`\n";
869 cba9d7d9 Renato Botelho
				$rrdupdatesh .= "$rrdtool update $loggedin_filename \${CP}\n";
870 7e5f3edb Warren Baker
871 cba9d7d9 Renato Botelho
			}
872 20413b72 Warren Baker
		}
873 1f3eff9b nagyrobi
		/* End Captive Portal statistics */
874
875
		/* NTP, set up the ntpd rrd file */
876 b5d5da0c Viktor Gurov
		if (isset($config['ntpd']['statsgraph']) && ($config['ntpd']['enable'] != 'disabled')) {
877 1f3eff9b nagyrobi
			/* set up the ntpd rrd file */
878 a88376d9 nagyrobi
			if (!file_exists("$rrddbpath$ntpd")) {
879 1f3eff9b nagyrobi
				$rrdcreate = "$rrdtool create $rrddbpath$ntpd --step $rrdntpdinterval ";
880 da8b271a David Wood
				$rrdcreate .= "DS:offset:GAUGE:$ntpdvalid:-1000:1000 ";
881 1f3eff9b nagyrobi
				$rrdcreate .= "DS:sjit:GAUGE:$ntpdvalid:0:1000 ";
882
				$rrdcreate .= "DS:cjit:GAUGE:$ntpdvalid:0:1000 ";
883
				$rrdcreate .= "DS:wander:GAUGE:$ntpdvalid:0:1000 ";
884 3ccfb627 Viktor G
				$rrdcreate .= "DS:freq:GAUGE:$ntpdvalid:-1000:1000 ";
885 1f3eff9b nagyrobi
				$rrdcreate .= "DS:disp:GAUGE:$ntpdvalid:0:1000 ";
886
				$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
887
				$rrdcreate .= "RRA:MIN:0.5:5:720 ";
888
				$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
889
				$rrdcreate .= "RRA:MIN:0.5:1440:2284 ";
890
				$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
891
				$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
892
				$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
893
				$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
894
				$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
895
				$rrdcreate .= "RRA:MAX:0.5:5:720 ";
896
				$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
897
				$rrdcreate .= "RRA:MAX:0.5:1440:2284 ";
898
899
				create_new_rrd($rrdcreate);
900
				unset($rrdcreate);
901
			}
902
903
			/* enter UNKNOWN values in the RRD so it knows we rebooted. */
904 61e047a5 Phil Davis
			if (platform_booting()) {
905
				mwexec("$rrdtool update $rrddbpath$ntpd N:U:U:U:U:U:U");
906 1f3eff9b nagyrobi
			}
907
908
			/* the ntp stats gathering function. */
909
			$rrdupdatesh .= "\n";
910
			$rrdupdatesh .= "$ntpq -c rv | $awk 'BEGIN{ RS=\",\"}{ print }' >> /tmp/ntp-rrdstats.$$\n";
911
			$rrdupdatesh .= "NOFFSET=`grep offset /tmp/ntp-rrdstats.$$ | awk 'BEGIN{FS=\"=\"}{print $2}'`\n";
912
			$rrdupdatesh .= "NFREQ=`grep frequency /tmp/ntp-rrdstats.$$ | awk 'BEGIN{FS=\"=\"}{print $2}'`\n";
913
			$rrdupdatesh .= "NSJIT=`grep sys_jitter /tmp/ntp-rrdstats.$$ | awk 'BEGIN{FS=\"=\"}{print $2}'`\n";
914
			$rrdupdatesh .= "NCJIT=`grep clk_jitter /tmp/ntp-rrdstats.$$ | awk 'BEGIN{FS=\"=\"}{print $2}'`\n";
915
			$rrdupdatesh .= "NWANDER=`grep clk_wander /tmp/ntp-rrdstats.$$ | awk 'BEGIN{FS=\"=\"}{print $2}'`\n";
916
			$rrdupdatesh .= "NDISPER=`grep rootdisp /tmp/ntp-rrdstats.$$ | awk 'BEGIN{FS=\"=\"}{print $2}'`\n";
917
			$rrdupdatesh .= "$rrdtool update $rrddbpath$ntpd \N:\${NOFFSET}:\${NSJIT}:\${NCJIT}:\${NWANDER}:\${NFREQ}:\${NDISPER}\n";
918
			$rrdupdatesh .= "rm /tmp/ntp-rrdstats.$$\n";
919
			$rrdupdatesh .= "\n";
920
921
		}
922
		/* End NTP statistics */
923 4e322e2c Phil Davis
924 89f3ec04 heper
		/* Start dhcpd statistics */
925 ec5b9e96 Chris Buechler
		if (is_array($config['dhcpd'])) {
926
			foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) {
927 fae6b2c0 jim-p
				if (empty($dhcpifconf)) {
928
					continue;
929
				}
930 4e322e2c Phil Davis
				if (isset($config['dhcpd'][$dhcpif]['statsgraph'])) {
931 ec5b9e96 Chris Buechler
					if (!file_exists("$rrddbpath$dhcpif$dhcpd")) {
932
						$rrdcreate = "$rrdtool create $rrddbpath$dhcpif$dhcpd --step $rrddhcpdinterval ";
933
						$rrdcreate .= "DS:leases:GAUGE:$dhcpdvalid:0:100000 ";
934
						$rrdcreate .= "DS:staticleases:GAUGE:$dhcpdvalid:0:100000 ";
935
						$rrdcreate .= "DS:dhcprange:GAUGE:$dhcpdvalid:0:100000 ";
936
						$rrdcreate .= "RRA:MIN:0.5:1:1200 ";
937
						$rrdcreate .= "RRA:MIN:0.5:5:720 ";
938
						$rrdcreate .= "RRA:MIN:0.5:60:1860 ";
939
						$rrdcreate .= "RRA:MIN:0.5:1440:2284 ";
940
						$rrdcreate .= "RRA:AVERAGE:0.5:1:1200 ";
941
						$rrdcreate .= "RRA:AVERAGE:0.5:5:720 ";
942
						$rrdcreate .= "RRA:AVERAGE:0.5:60:1860 ";
943
						$rrdcreate .= "RRA:AVERAGE:0.5:1440:2284 ";
944
						$rrdcreate .= "RRA:MAX:0.5:1:1200 ";
945
						$rrdcreate .= "RRA:MAX:0.5:5:720 ";
946
						$rrdcreate .= "RRA:MAX:0.5:60:1860 ";
947
						$rrdcreate .= "RRA:MAX:0.5:1440:2284 ";
948
						create_new_rrd($rrdcreate);
949
						unset($rrdcreate);
950
					}
951 89f3ec04 heper
952 ec5b9e96 Chris Buechler
					/* enter UNKNOWN values in the RRD so it knows we rebooted. */
953
					if (platform_booting()) {
954 3401dbe2 heper
						mwexec("$rrdtool update $rrddbpath$dhcpif$dhcpd N:U:U:U");
955 ec5b9e96 Chris Buechler
					}
956 89f3ec04 heper
957 ec5b9e96 Chris Buechler
					$rrdupdatesh .= "\n";
958
					$rrdupdatesh .= "# polling leases for dhcp \n";
959
					$rrdupdatesh .= "DHCP=`${php} -q ${dhcpd_gather} '${dhcpif}'`\n";
960
					$rrdupdatesh .= "$rrdtool update $rrddbpath$dhcpif$dhcpd \${DHCP}\n";
961 4e322e2c Phil Davis
962 ec5b9e96 Chris Buechler
				}
963 89f3ec04 heper
			}
964
		}
965
		/* END dhcpd statistics */
966 ec51a222 thompsa
967 c53acd0f Renato Botelho
		/* Start gateway quality */
968
		$rrdupdatesh .= <<<EOD
969
970
# Gateway quality graphs
971
for sock in {$g['varrun_path']}/dpinger_*.sock; do
972
	if [ ! -S "\$sock" ]; then
973
		continue
974
	fi
975 73e3aa21 Renato Botelho
976 9f268ac0 Denny Page
	t=\$(/usr/bin/nc -U \$sock)
977 0e1eef54 Denny Page
	if [ -z "\$t" ]; then
978 73e3aa21 Renato Botelho
		continue
979
	fi
980
981 0e1eef54 Denny Page
	gw=\$(echo "\$t" | awk '{ print \$1 }')
982
	delay=\$(echo "\$t" | awk '{ print \$2 }')
983 0b3613ef Denny Page
	stddev=\$(echo "\$t" | awk '{ print \$3 }')
984 0e1eef54 Denny Page
	loss=\$(echo "\$t" | awk '{ print \$4 }')
985 c53acd0f Renato Botelho
986
	if echo "\$loss" | grep -Eqv '^[0-9]+\$'; then
987
		loss="U"
988
	fi
989
	if echo "\$delay" | grep -Eqv '^[0-9]+\$'; then
990
		delay="U"
991 4fa580c2 Renato Botelho
	else
992 515887c3 NOYB
		# Convert delay from microseconds to seconds
993 834b97f1 Renato Botelho
		delay=\$(echo "scale=7; \$delay / 1000 / 1000" | /usr/bin/bc)
994 c53acd0f Renato Botelho
	fi
995 0b3613ef Denny Page
	if echo "\$stddev" | grep -Eqv '^[0-9]+\$'; then
996
		stddev="U"
997
	else
998 515887c3 NOYB
		# Convert stddev from microseconds to seconds
999 0b3613ef Denny Page
		stddev=\$(echo "scale=7; \$stddev / 1000 / 1000" | /usr/bin/bc)
1000
	fi
1001 c53acd0f Renato Botelho
1002
	if [ ! -f {$rrddbpath}\$gw-quality.rrd ]; then
1003
		{$rrdtool} create {$rrddbpath}\$gw-quality.rrd --step 60 \\
1004
		DS:loss:GAUGE:120:0:100 \\
1005
		DS:delay:GAUGE:120:0:100000 \\
1006 0b3613ef Denny Page
		DS:stddev:GAUGE:120:0:100000 \\
1007 c53acd0f Renato Botelho
		RRA:AVERAGE:0.5:1:1200 \\
1008
		RRA:AVERAGE:0.5:5:720 \\
1009
		RRA:AVERAGE:0.5:60:1860 \\
1010
		RRA:AVERAGE:0.5:1440:2284
1011
1012 0b3613ef Denny Page
		{$rrdtool} update {$rrddbpath}\$gw-quality.rrd -t loss:delay:stddev N:U:U:U
1013 c53acd0f Renato Botelho
	fi
1014
1015 0b3613ef Denny Page
	{$rrdtool} update {$rrddbpath}\$gw-quality.rrd -t loss:delay:stddev N:\$loss:\$delay:\$stddev
1016 c53acd0f Renato Botelho
done
1017
1018
EOD;
1019
		/* End gateway quality */
1020
1021 ea4bc46f Seth Mos
		$rrdupdatesh .= "sleep 60\n";
1022
		$rrdupdatesh .= "done\n";
1023 9eda6186 Carlos Eduardo Ramos
		log_error(gettext("Creating rrd update script"));
1024 ea4bc46f Seth Mos
		/* write the rrd update script */
1025
		$updaterrdscript = "{$g['vardb_path']}/rrd/updaterrd.sh";
1026
		$fd = fopen("$updaterrdscript", "w");
1027
		fwrite($fd, "$rrdupdatesh");
1028
		fclose($fd);
1029
1030 cba9d7d9 Renato Botelho
		unset($rrdupdatesh);
1031
1032 ea4bc46f Seth Mos
		/* kill off traffic collectors */
1033
		kill_traffic_collector();
1034
1035
		/* start traffic collector */
1036
		mwexec_bg("/usr/bin/nice -n20 /bin/sh $updaterrdscript");
1037
1038
	} else {
1039
		/* kill off traffic collectors */
1040
		kill_traffic_collector();
1041
	}
1042
1043 25cca20b jim-p
	$databases = glob("{$rrddbpath}/*.rrd");
1044 61e047a5 Phil Davis
	foreach ($databases as $database) {
1045 8e23a630 Chris Buechler
		if (file_exists($database)) {
1046
			chown($database, "nobody");
1047
		}
1048 25cca20b jim-p
	}
1049
1050 61e047a5 Phil Davis
	if (platform_booting()) {
1051 9eda6186 Carlos Eduardo Ramos
		echo gettext("done.") . "\n";
1052 61e047a5 Phil Davis
	}
1053 5e5d5abc Renato Botelho
1054 ea4bc46f Seth Mos
}
1055
1056 ab7658da Seth Mos
function kill_traffic_collector() {
1057 3d54aa10 Renato Botelho
	global $g;
1058
1059
	killbypid("{$g['varrun_path']}/updaterrd.sh.pid");
1060 ab7658da Seth Mos
}
1061
1062 9bc8b6b6 Seth Mos
?>