summaryrefslogtreecommitdiffstats
path: root/etc/inc/rrd.inc
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2015-03-03 00:11:10 +0545
committerPhil Davis <phil.davis@inf.org>2015-03-03 00:11:10 +0545
commit61e047a50339da4a0b6a9202f163950573e8a578 (patch)
tree138a33434240f27f42e88483ed66cd1743cadf2a /etc/inc/rrd.inc
parent8f5f40c9fca0bfb637589b4c86e53bfb80753c87 (diff)
downloadpfsense-61e047a50339da4a0b6a9202f163950573e8a578.zip
pfsense-61e047a50339da4a0b6a9202f163950573e8a578.tar.gz
Code style etc in r s
Diffstat (limited to 'etc/inc/rrd.inc')
-rw-r--r--etc/inc/rrd.inc112
1 files changed, 59 insertions, 53 deletions
diff --git a/etc/inc/rrd.inc b/etc/inc/rrd.inc
index c620419..5aaff68 100644
--- a/etc/inc/rrd.inc
+++ b/etc/inc/rrd.inc
@@ -61,14 +61,15 @@ function restore_rrd() {
}
unset($rrdrestore);
$_gb = exec("cd /;LANG=C /usr/bin/tar -tf {$g['cf_conf_path']}/rrd.tgz", $rrdrestore, $rrdreturn);
- if($rrdreturn != 0) {
+ if ($rrdreturn != 0) {
log_error("RRD restore failed exited with $rrdreturn, the error is: $rrdrestore\n");
return;
}
foreach ($rrdrestore as $xml_file) {
$rrd_file = '/' . substr($xml_file, 0, -4) . '.rrd';
- if (file_exists("{$rrd_file}"))
+ if (file_exists("{$rrd_file}")) {
@unlink($rrd_file);
+ }
file_put_contents("{$g['tmp_path']}/rrd_restore", $xml_file);
$_gb = exec("cd /;LANG=C /usr/bin/tar -xf {$g['cf_conf_path']}/rrd.tgz -T {$g['tmp_path']}/rrd_restore");
if (!file_exists("/{$xml_file}")) {
@@ -107,7 +108,7 @@ function create_new_rrd($rrdcreatecmd) {
}
function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
- if(!file_exists("/tmp/rrd_notice_sent.txt")) {
+ if (!file_exists("/tmp/rrd_notice_sent.txt")) {
$_gb = exec("echo 'Converting RRD configuration to new format. This might take a bit...' | wall");
@touch("/tmp/rrd_notice_sent.txt");
}
@@ -119,8 +120,8 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
/* add data sources not found in the old array from the new array */
$i = 0;
- foreach($rrdnewxml['ds'] as $ds) {
- if(!is_array($rrdoldxml['ds'][$i])) {
+ foreach ($rrdnewxml['ds'] as $ds) {
+ if (!is_array($rrdoldxml['ds'][$i])) {
$rrdoldxml['ds'][$i] = $rrdnewxml['ds'][$i];
/* set unknown values to 0 */
$rrdoldxml['ds'][$i]['last_ds'] = " 0.0000000000e+00 ";
@@ -134,16 +135,16 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
$rracountold = count($rrdoldxml['rra']);
$rracountnew = count($rrdnewxml['rra']);
/* process each RRA, which contain a database */
- foreach($rrdnewxml['rra'] as $rra) {
- if(!is_array($rrdoldxml['rra'][$i])) {
+ foreach ($rrdnewxml['rra'] as $rra) {
+ if (!is_array($rrdoldxml['rra'][$i])) {
$rrdoldxml['rra'][$i] = $rrdnewxml['rra'][$i];
}
$d = 0;
/* process cdp_prep */
$cdp_prep = $rra['cdp_prep'];
- foreach($cdp_prep['ds'] as $ds) {
- if(!is_array($rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d])) {
+ foreach ($cdp_prep['ds'] as $ds) {
+ if (!is_array($rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d])) {
$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d] = $rrdnewxml['rra'][$i]['cdp_prep']['ds'][$d];
$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['primary_value'] = " 0.0000000000e+00 ";
$rrdoldxml['rra'][$i]['cdp_prep']['ds'][$d]['secondary_value'] = " 0.0000000000e+00 ";
@@ -163,28 +164,28 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
$rowsdata = $rows;
$rowsempty = array();
$r = 0;
- while($r < $rowcountdiff) {
+ while ($r < $rowcountdiff) {
$rowsempty[] = $rrdnewxml['rra'][$i]['database']['row'][$r];
$r++;
}
$rows = $rowsempty + $rowsdata;
/* now foreach the rows in the database */
- foreach($rows['row'] as $row) {
- if(!is_array($rrdoldxml['rra'][$i]['database']['row'][$k])) {
+ foreach ($rows['row'] as $row) {
+ if (!is_array($rrdoldxml['rra'][$i]['database']['row'][$k])) {
$rrdoldxml['rra'][$i]['database']['row'][$k] = $rrdnewxml['rra'][$i]['database']['row'][$k];
}
$m = 0;
$vcountold = count($rrdoldxml['rra'][$i]['database']['row'][$k]['v']);
$vcountnew = count($rrdnewxml['rra'][$i]['database']['row'][$k]['v']);
- foreach($row['v'] as $value) {
- if(empty($rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m])) {
- if(isset($valid)) {
+ foreach ($row['v'] as $value) {
+ if (empty($rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m])) {
+ if (isset($valid)) {
$rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m] = "0.0000000000e+00 ";
} else {
$rrdoldxml['rra'][$i]['database']['row'][$k]['v'][$m] = $rrdnewxml['rra'][$i]['database']['row'][$k]['v'][$m];
}
} else {
- if($value <> " NaN ") {
+ if ($value <> " NaN ") {
$valid = true;
} else {
$valid = false;
@@ -206,8 +207,9 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
function enable_rrd_graphing() {
global $config, $g, $altq_list_queues;
- if(platform_booting())
+ if (platform_booting()) {
echo gettext("Generating RRD graphs...");
+ }
$rrddbpath = "/var/db/rrd/";
$rrdgraphpath = "/usr/local/www/rrd";
@@ -309,16 +311,17 @@ function enable_rrd_graphing() {
/* IPsec counters */
$ifdescrs['ipsec'] = "IPsec";
/* OpenVPN server counters */
- if(is_array($config['openvpn']['openvpn-server'])) {
- foreach($config['openvpn']['openvpn-server'] as $server) {
+ if (is_array($config['openvpn']['openvpn-server'])) {
+ foreach ($config['openvpn']['openvpn-server'] as $server) {
$serverid = "ovpns" . $server['vpnid'];
$ifdescrs[$serverid] = "{$server['description']}";
}
}
if (platform_booting()) {
- if (!is_dir("{$g['vardb_path']}/rrd"))
+ if (!is_dir("{$g['vardb_path']}/rrd")) {
mkdir("{$g['vardb_path']}/rrd", 0775);
+ }
@chown("{$g['vardb_path']}/rrd", "nobody");
}
@@ -326,7 +329,7 @@ function enable_rrd_graphing() {
/* process all real and pseudo interfaces */
foreach ($ifdescrs as $ifname => $ifdescr) {
$temp = get_real_interface($ifname);
- if($temp <> "") {
+ if ($temp <> "") {
$realif = $temp;
}
@@ -351,7 +354,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$traffic N:U:U:U:U:U:U:U:U");
}
@@ -384,7 +387,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$packets N:U:U:U:U:U:U:U:U");
}
@@ -397,7 +400,7 @@ function enable_rrd_graphing() {
$rrdupdatesh .= "END {print b4pi \":\" b4po \":\" b4bi \":\" b4bo \":\" b6pi \":\" b6po \":\" b6bi \":\" b6bo};'`\n";
/* WIRELESS, set up the rrd file */
- if($config['interfaces'][$ifname]['wireless']['mode'] == "bss") {
+ if ($config['interfaces'][$ifname]['wireless']['mode'] == "bss") {
if (!file_exists("$rrddbpath$ifname$wireless")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$wireless --step $rrdwirelessinterval ";
$rrdcreate .= "DS:snr:GAUGE:$wirelessvalid:0:1000 ";
@@ -413,7 +416,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$wireless N:U:U:U");
}
@@ -424,7 +427,7 @@ function enable_rrd_graphing() {
}
/* OpenVPN, set up the rrd file */
- if(stristr($ifname, "ovpns")) {
+ if (stristr($ifname, "ovpns")) {
if (!file_exists("$rrddbpath$ifname$vpnusers")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$vpnusers --step $rrdvpninterval ";
$rrdcreate .= "DS:users:GAUGE:$vpnvalid:0:10000 ";
@@ -438,13 +441,13 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$vpnusers N:U");
}
- if(is_array($config['openvpn']['openvpn-server'])) {
- foreach($config['openvpn']['openvpn-server'] as $server) {
- if("ovpns{$server['vpnid']}" == $ifname) {
+ if (is_array($config['openvpn']['openvpn-server'])) {
+ foreach ($config['openvpn']['openvpn-server'] as $server) {
+ if ("ovpns{$server['vpnid']}" == $ifname) {
$port = $server['local_port'];
$vpnid = $server['vpnid'];
}
@@ -520,12 +523,12 @@ function enable_rrd_graphing() {
unset($rrdcreate);
}
- if(platform_booting()) {
+ if (platform_booting()) {
$rrdqcommand = "-t ";
$rrducommand = "N";
$qi = 0;
foreach ($qlist as $qname => $q) {
- if($qi == 0) {
+ if ($qi == 0) {
$rrdqcommand .= "{$qname}";
} else {
$rrdqcommand .= ":{$qname}";
@@ -573,7 +576,7 @@ function enable_rrd_graphing() {
}
/* 3G interfaces */
- if(preg_match("/ppp[0-9]+/i", $realif)) {
+ if (preg_match("/ppp[0-9]+/i", $realif)) {
if (!file_exists("$rrddbpath$ifname$cellular")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$cellular --step $rrdcellularinterval ";
$rrdcreate .= "DS:rssi:GAUGE:$cellularvalid:0:100 ";
@@ -588,7 +591,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$cellular N:U:U:U");
}
@@ -605,7 +608,7 @@ function enable_rrd_graphing() {
$ifname = "system";
/* STATES, create pf states database */
- if(! file_exists("$rrddbpath$ifname$states")) {
+ if (!file_exists("$rrddbpath$ifname$states")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$states --step $rrdstatesinterval ";
$rrdcreate .= "DS:pfrate:GAUGE:$statesvalid:0:10000000 ";
$rrdcreate .= "DS:pfstates:GAUGE:$statesvalid:0:10000000 ";
@@ -622,7 +625,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$states N:U:U:U:U:U");
}
@@ -640,7 +643,7 @@ function enable_rrd_graphing() {
/* End pf states statistics */
/* CPU, create CPU statistics database */
- if(! file_exists("$rrddbpath$ifname$proc")) {
+ if (!file_exists("$rrddbpath$ifname$proc")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$proc --step $rrdprocinterval ";
$rrdcreate .= "DS:user:GAUGE:$procvalid:0:10000000 ";
$rrdcreate .= "DS:nice:GAUGE:$procvalid:0:10000000 ";
@@ -657,7 +660,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$proc N:U:U:U:U:U");
}
@@ -670,7 +673,7 @@ function enable_rrd_graphing() {
/* End CPU statistics */
/* Memory, create Memory statistics database */
- if(! file_exists("$rrddbpath$ifname$mem")) {
+ if (!file_exists("$rrddbpath$ifname$mem")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$mem --step $rrdmeminterval ";
$rrdcreate .= "DS:active:GAUGE:$memvalid:0:10000000 ";
$rrdcreate .= "DS:inactive:GAUGE:$memvalid:0:10000000 ";
@@ -695,7 +698,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$mem N:U:U:U:U:U");
}
@@ -708,7 +711,7 @@ function enable_rrd_graphing() {
/* End Memory statistics */
/* mbuf, create mbuf statistics database */
- if(! file_exists("$rrddbpath$ifname$mbuf")) {
+ if (!file_exists("$rrddbpath$ifname$mbuf")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$mbuf --step $rrdmbufinterval ";
$rrdcreate .= "DS:current:GAUGE:$mbufvalid:0:10000000 ";
$rrdcreate .= "DS:cache:GAUGE:$mbufvalid:0:10000000 ";
@@ -732,7 +735,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $rrddbpath$ifname$mbuf N:U:U:U:U");
}
@@ -745,7 +748,7 @@ function enable_rrd_graphing() {
/* SPAMD, set up the spamd rrd file */
if (isset($config['installedpackages']['spamdsettings']) &&
- $config['installedpackages']['spamdsettings']['config'][0]['enablerrd']) {
+ $config['installedpackages']['spamdsettings']['config'][0]['enablerrd']) {
/* set up the spamd rrd file */
if (!file_exists("$rrddbpath$ifname$spamd")) {
$rrdcreate = "$rrdtool create $rrddbpath$ifname$spamd --step $rrdspamdinterval ";
@@ -777,10 +780,11 @@ function enable_rrd_graphing() {
/* End System statistics */
/* Captive Portal statistics, set up the rrd file */
- if(is_array($config['captiveportal'])) {
+ if (is_array($config['captiveportal'])) {
foreach ($config['captiveportal'] as $cpkey => $cp) {
- if (!isset($cp['enable']))
+ if (!isset($cp['enable'])) {
continue;
+ }
$ifname= "captiveportal";
$concurrent_filename = $rrddbpath . $ifname . '-' . $cpkey . $captiveportalconcurrent;
@@ -809,7 +813,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $concurrent_filename N:U");
}
@@ -845,7 +849,7 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
+ if (platform_booting()) {
mwexec("$rrdtool update $loggedin_filename N:U");
}
@@ -888,8 +892,8 @@ function enable_rrd_graphing() {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
- mwexec("$rrdtool update $rrddbpath$ntpd N:U:U:U:U:U:U");
+ if (platform_booting()) {
+ mwexec("$rrdtool update $rrddbpath$ntpd N:U:U:U:U:U:U");
}
/* the ntp stats gathering function. */
@@ -931,12 +935,13 @@ function enable_rrd_graphing() {
}
$databases = glob("{$rrddbpath}/*.rrd");
- foreach($databases as $database) {
+ foreach ($databases as $database) {
chown($database, "nobody");
}
- if(platform_booting())
+ if (platform_booting()) {
echo gettext("done.") . "\n";
+ }
}
@@ -963,9 +968,10 @@ function create_gateway_quality_rrd($rrd_file) {
}
/* enter UNKNOWN values in the RRD so it knows we rebooted. */
- if(platform_booting()) {
- if (!is_dir("{$g['vardb_path']}/rrd"))
+ if (platform_booting()) {
+ if (!is_dir("{$g['vardb_path']}/rrd")) {
mkdir("{$g['vardb_path']}/rrd", 0775);
+ }
@chown("{$g['vardb_path']}/rrd", "nobody");
OpenPOWER on IntegriCloud