summaryrefslogtreecommitdiffstats
path: root/etc/inc/rrd.inc
diff options
context:
space:
mode:
authorSeth Mos <seth.mos@xs4all.nl>2008-12-24 10:14:41 +0000
committerSeth Mos <seth.mos@xs4all.nl>2008-12-24 10:14:41 +0000
commitea4bc46f6ceb05453395d6bd23e29e35015b68f1 (patch)
tree01c3e51bd92cfae60a9689aa6210fa256dde7a5f /etc/inc/rrd.inc
parente4f4eb7d099ad1f37aba04336d8661d4ef27271d (diff)
downloadpfsense-ea4bc46f6ceb05453395d6bd23e29e35015b68f1.zip
pfsense-ea4bc46f6ceb05453395d6bd23e29e35015b68f1.tar.gz
Add enable_rrd_graphing();
Diffstat (limited to 'etc/inc/rrd.inc')
-rw-r--r--etc/inc/rrd.inc471
1 files changed, 471 insertions, 0 deletions
diff --git a/etc/inc/rrd.inc b/etc/inc/rrd.inc
index 34cdcf7..122c505 100644
--- a/etc/inc/rrd.inc
+++ b/etc/inc/rrd.inc
@@ -133,3 +133,474 @@ function migrate_rrd_format($rrdoldxml, $rrdnewxml) {
return $rrdoldxml;
}
+function enable_rrd_graphing() {
+ global $config, $g, $altq_list_queues;
+
+ if($g['booting'])
+ echo "Generating RRD graphs...";
+
+ $rrddbpath = "/var/db/rrd/";
+ $rrdgraphpath = "/usr/local/www/rrd";
+
+ $traffic = "-traffic.rrd";
+ $packets = "-packets.rrd";
+ $states = "-states.rrd";
+ $wireless = "-wireless.rrd";
+ $queues = "-queues.rrd";
+ $queuesdrop = "-queuedrops.rrd";
+ $spamd = "-spamd.rrd";
+ $proc = "-processor.rrd";
+ $mem = "-memory.rrd";
+
+ $rrdtool = "/usr/local/bin/rrdtool";
+ $netstat = "/usr/bin/netstat";
+ $awk = "/usr/bin/awk";
+ $tar = "/usr/bin/tar";
+ $pfctl = "/sbin/pfctl";
+ $sysctl = "/sbin/sysctl";
+ $php = "/usr/local/bin/php";
+ $top = "/usr/bin/top";
+ $spamd_gather = "/usr/local/bin/spamd_gather_stats.php";
+ $ifconfig = "/sbin/ifconfig";
+
+ $rrdtrafficinterval = 60;
+ $rrdwirelessinterval = 60;
+ $rrdqueuesinterval = 60;
+ $rrdqueuesdropinterval = 60;
+ $rrdpacketsinterval = 60;
+ $rrdstatesinterval = 60;
+ $rrdspamdinterval = 60;
+ $rrdlbpoolinterval = 60;
+ $rrdprocinterval = 60;
+ $rrdmeminterval = 60;
+
+ $trafficvalid = $rrdtrafficinterval * 2;
+ $wirelessvalid = $rrdwirelessinterval * 2;
+ $queuesvalid = $rrdqueuesinterval * 2;
+ $queuesdropvalid = $rrdqueuesdropinterval * 2;
+ $packetsvalid = $rrdpacketsinterval * 2;
+ $statesvalid = $rrdstatesinterval*2;
+ $spamdvalid = $rrdspamdinterval * 2;
+ $lbpoolvalid = $rrdlbpoolinterval * 2;
+ $procvalid = $rrdlbpoolinterval * 2;
+ $memvalid = $rrdmeminterval * 2;
+
+ /* Asume GigE for now */
+ $downstream = 125000000;
+ $upstream = 125000000;
+
+ /* read the shaper config */
+ read_altq_config();
+
+ $rrdrestore = "";
+ $rrdreturn = "";
+
+ if (isset ($config['rrd']['enable'])) {
+
+ /* create directory if needed */
+ if (!is_dir("$rrddbpath")) {
+ mkdir("$rrddbpath", 0755);
+ }
+
+ if ($g['booting']) {
+ if ($g['platform'] != "pfSense") {
+ /* restore the databases, if we have one */
+ if (file_exists("{$g['cf_conf_path']}/rrd.tgz")) {
+ exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/rrd.tgz 2>&1", $rrdrestore, $rrdreturn);
+ $rrdrestore = implode(" ", $rrdrestore);
+ if($rrdreturn <> 0) {
+ log_error("RRD restore failed exited with $rrdreturn, the error is: $rrdrestore\n");
+ }
+ }
+ }
+ }
+
+ /* db update script */
+ $rrdupdatesh = "#!/bin/sh\n";
+ $rrdupdatesh .= "\n";
+ $rrdupdatesh .= "counter=1\n";
+ $rrdupdatesh .= "while [ \"\$counter\" -ne 0 ]\n";
+ $rrdupdatesh .= "do\n";
+ $rrdupdatesh .= "";
+
+ $i = 0;
+ $vfaces = array (
+ "vlan.?*",
+ "enc.?*"
+ );
+ $ifdescrs = get_interface_list(true, true, $vfaces);
+ $ifdescrs['enc0']['friendly'] = "ipsec";
+ $ifdescrs['enc0']['descr'] = "IPsec";
+ $ifdescrs['enc0']['up'] = true;
+
+ foreach ($ifdescrs as $realif => $ifdescr) {
+ $ifname = $ifdescr['friendly'];
+ $state = $ifdescr['up'];
+
+ /* skip interfaces that do not have a friendly name */
+ if ("$ifname" == "") {
+ continue;
+ }
+
+ /* or are down */
+ if (!$state) {
+ continue;
+ }
+
+ /* TRAFFIC, set up the rrd file */
+ if (!file_exists("$rrddbpath$ifname$traffic")) {
+ $rrdcreate = "$rrdtool create $rrddbpath$ifname$traffic --step $rrdtrafficinterval ";
+ $rrdcreate .= "DS:inpass:COUNTER:$trafficvalid:0:$downstream ";
+ $rrdcreate .= "DS:outpass:COUNTER:$trafficvalid:0:$upstream ";
+ $rrdcreate .= "DS:inblock:COUNTER:$trafficvalid:0:$downstream ";
+ $rrdcreate .= "DS:outblock:COUNTER:$trafficvalid:0:$upstream ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1440:1500 ";
+
+ create_new_rrd($rrdcreate);
+ }
+
+ /* enter UNKNOWN values in the RRD so it knows we rebooted. */
+ if($g['booting']) {
+ exec("$rrdtool update $rrddbpath$ifname$traffic N:U:U:U:U");
+ }
+
+ $rrdupdatesh .= "\n";
+ $rrdupdatesh .= "# polling traffic for interface $ifname $realif \n";
+ $rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$traffic N:\\\n";
+ $rrdupdatesh .= "`$pfctl -vvsI -i {$realif} | awk '/In4\/Pass|Out4\/Pass/ {printf \$6 \":\"}'`\\\n";
+ $rrdupdatesh .= "`$pfctl -vvsI -i {$realif} | awk '/In4\/Block|Out4\/Block/ {printf \$6 \":\"}'|sed -e 's/.\$//'`\n";
+
+ /* PACKETS, set up the rrd file */
+ if (!file_exists("$rrddbpath$ifname$packets")) {
+ $rrdcreate = "$rrdtool create $rrddbpath$ifname$packets --step $rrdpacketsinterval ";
+ $rrdcreate .= "DS:inpass:COUNTER:$packetsvalid:0:$downstream ";
+ $rrdcreate .= "DS:outpass:COUNTER:$packetsvalid:0:$upstream ";
+ $rrdcreate .= "DS:inblock:COUNTER:$packetsvalid:0:$downstream ";
+ $rrdcreate .= "DS:outblock:COUNTER:$packetsvalid:0:$upstream ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1440:1500 ";
+
+ create_new_rrd($rrdcreate);
+ }
+
+ /* enter UNKNOWN values in the RRD so it knows we rebooted. */
+ if($g['booting']) {
+ exec("$rrdtool update $rrddbpath$ifname$packets N:U:U:U:U");
+ }
+
+ $rrdupdatesh .= "\n";
+ $rrdupdatesh .= "# polling packets for interface $ifname $realif \n";
+ $rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$packets N:\\\n";
+ $rrdupdatesh .= "`$pfctl -vvsI -i {$realif} | awk '/In4\/Pass|Out4\/Pass/ {printf \$4 \":\"}'`\\\n";
+ $rrdupdatesh .= "`$pfctl -vvsI -i {$realif} | awk '/In4\/Block|Out4\/Block/ {printf \$4 \":\"}'|sed -e 's/.\$//'`\n";
+
+ /* WIRELESS, set up the rrd file */
+ 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 ";
+ $rrdcreate .= "DS:rate:GAUGE:$wirelessvalid:0:1000 ";
+ $rrdcreate .= "DS:channel:GAUGE:$wirelessvalid:0:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1440:1500 ";
+
+ create_new_rrd($rrdcreate);
+ }
+
+ /* enter UNKNOWN values in the RRD so it knows we rebooted. */
+ if($g['booting']) {
+ exec("$rrdtool update $rrddbpath$ifname$wireless N:U:U:U");
+ }
+
+ $rrdupdatesh .= "\n";
+ $rrdupdatesh .= "# polling wireless for interface $ifname $realif \n";
+ $rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$wireless N:\\\n";
+ $rrdupdatesh .= "`$ifconfig {$realif} list ap| $awk 'gsub(\"M\", \"\") {getline 2;print substr(\$5, 0, length(\$5)-2) \":\" $4 \":\" $3}'`\n";
+ }
+
+ /* QUEUES, set up the queues databases */
+ if ($altq_list_queues[$ifname]) {
+ $altq =& $altq_list_queues[$ifname];
+ /* NOTE: Is it worth as its own function?! */
+ switch ($altq->GetBwscale()) {
+ case "Gb":
+ $factor = 1024 * 1024 * 1024;
+ break;
+ case "Mb":
+ $factor = 1024 * 1024;
+ break;
+ case "Kb":
+ $factor = 1024;
+ break;
+ case "b":
+ default:
+ $factor = 1;
+ break;
+ }
+ $qbandwidth = $altq->GetBandwidth() * $factor;
+ if ($qbandwidth <=0)
+ $qbandwidth = 100 * 1000 * 1000; /* 100Mbit */
+ $qlist =& $altq->get_queue_list($notused);
+ if (!file_exists("$rrddbpath$ifname$queues")) {
+ $rrdcreate = "$rrdtool create $rrddbpath$ifname$queues --step $rrdqueuesinterval ";
+ /* loop list of shaper queues */
+ $q = 0;
+ foreach ($qlist as $qname => $q) {
+ $rrdcreate .= "DS:$qname:COUNTER:$queuesvalid:0:$qbandwidth ";
+ }
+
+ $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1440:1500 ";
+
+ create_new_rrd($rrdcreate);
+ }
+
+ if (!file_exists("$rrddbpath$ifname$queuesdrop")) {
+ $rrdcreate = "$rrdtool create $rrddbpath$ifname$queuesdrop --step $rrdqueuesdropinterval ";
+ /* loop list of shaper queues */
+ $q = 0;
+ foreach ($qlist as $qname => $q) {
+ $rrdcreate .= "DS:$qname:COUNTER:$queuesdropvalid:0:$qbandwidth ";
+ }
+
+ $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1440:1500 ";
+
+ create_new_rrd($rrdcreate);
+ }
+
+ if($g['booting']) {
+ $rrdqcommand = "-t ";
+ $rrducommand = "N";
+ $q = 0;
+ foreach ($qlist as $qname => $q) {
+ if($q == 0) {
+ $rrdqcommand .= "{$qname}";
+ } else {
+ $rrdqcommand .= ":{$qname}";
+ }
+ $q++;
+ $rrducommand .= ":U";
+ }
+ mwexec("$rrdtool update $rrddbpath$ifname$queues $rrdqcommand $rrducommand");
+ mwexec("$rrdtool update $rrddbpath$ifname$queuesdrop $rrdqcommand $rrducommand");
+ }
+
+ /* awk function to gather shaper data */
+ /* yes, it's special */
+ $rrdupdatesh .= "` pfctl -vsq -i {$realif} | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queues \" } ";
+ $rrdupdatesh .= "{ ";
+ $rrdupdatesh .= "if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { ";
+ $rrdupdatesh .= "dsname = dsname \":\" \$2 ; ";
+ $rrdupdatesh .= "q=1; ";
+ $rrdupdatesh .= "} ";
+ $rrdupdatesh .= "else if ((\$4 == \"bytes:\") && ( q == 1 ) ) { ";
+ $rrdupdatesh .= "dsdata = dsdata \":\" \$5 ; ";
+ $rrdupdatesh .= "q=0; ";
+ $rrdupdatesh .= "} ";
+ $rrdupdatesh .= "} END { ";
+ $rrdupdatesh .= "dsname = substr(dsname,2); ";
+ $rrdupdatesh .= "dsdata = substr(dsdata,2); ";
+ $rrdupdatesh .= "printf \"-t \" dsname \" N:\" dsdata }' ";
+ $rrdupdatesh .= "dsname=\"\" dsdata=\"\"`\n\n";
+
+ $rrdupdatesh .= "` pfctl -vsq -i {$realif} | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queuesdrop \" } ";
+ $rrdupdatesh .= "{ ";
+ $rrdupdatesh .= "if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { ";
+ $rrdupdatesh .= "dsname = dsname \":\" \$2 ; ";
+ $rrdupdatesh .= "q=1; ";
+ $rrdupdatesh .= "} ";
+ $rrdupdatesh .= "else if ((\$4 == \"bytes:\") && ( q == 1 ) ) { ";
+ $rrdupdatesh .= "dsdata = dsdata \":\" \$8 ; ";
+ $rrdupdatesh .= "q=0; ";
+ $rrdupdatesh .= "} ";
+ $rrdupdatesh .= "} END { ";
+ $rrdupdatesh .= "dsname = substr(dsname,2); ";
+ $rrdupdatesh .= "dsdata = substr(dsdata,2); ";
+ $rrdupdatesh .= "printf \"-t \" dsname \" N:\" dsdata }' ";
+ $rrdupdatesh .= "dsname=\"\" dsdata=\"\"`\n\n";
+ }
+ }
+ $i++;
+
+ /* System only statistics */
+ $ifname = "system";
+
+ /* STATES, create pf states database */
+ 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 ";
+ $rrdcreate .= "DS:pfnat:GAUGE:$statesvalid:0:10000000 ";
+ $rrdcreate .= "DS:srcip:GAUGE:$statesvalid:0:10000000 ";
+ $rrdcreate .= "DS:dstip:GAUGE:$statesvalid:0:10000000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1440:1500 ";
+
+ create_new_rrd($rrdcreate);
+ }
+
+ /* enter UNKNOWN values in the RRD so it knows we rebooted. */
+ if($g['booting']) {
+ exec("$rrdtool update $rrddbpath$ifname$states N:U:U:U:U:U");
+ }
+
+ /* the pf states gathering function. */
+ $rrdupdatesh .= "\n";
+ $rrdupdatesh .= "pfctl_si_out=\"` $pfctl -si > /tmp/pfctl_si_out `\"\n";
+ $rrdupdatesh .= "pfctl_ss_out=\"` $pfctl -ss > /tmp/pfctl_ss_out`\"\n";
+ $rrdupdatesh .= "pfrate=\"` cat /tmp/pfctl_si_out | egrep \"inserts|removals\" | awk '{ pfrate = \$3 + pfrate } {print pfrate}'|tail -1 `\"\n";
+ $rrdupdatesh .= "pfstates=\"` cat /tmp/pfctl_ss_out | egrep -v \"<\\-.*?<\\-|\\->.*?\\->\" | wc -l|sed 's/ //g'`\"\n";
+ $rrdupdatesh .= "pfnat=\"` cat /tmp/pfctl_ss_out | egrep '<\\-.*?<\\-|\\->.*?\\->' | wc -l|sed 's/ //g' `\"\n";
+ $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";
+ $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";
+ $rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$states N:\$pfrate:\$pfstates:\$pfnat:\$srcip:\$dstip\n\n";
+
+ /* End pf states statistics */
+
+ /* CPU, create CPU statistics database */
+ 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 ";
+ $rrdcreate .= "DS:system:GAUGE:$procvalid:0:10000000 ";
+ $rrdcreate .= "DS:interrupt:GAUGE:$procvalid:0:10000000 ";
+ $rrdcreate .= "DS:processes:GAUGE:$procvalid:0:10000000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1440:1500 ";
+
+ create_new_rrd($rrdcreate);
+ }
+
+ /* enter UNKNOWN values in the RRD so it knows we rebooted. */
+ if($g['booting']) {
+ exec("$rrdtool update $rrddbpath$ifname$proc N:U:U:U:U:U");
+ }
+
+ /* the CPU stats gathering function. */
+ $rrdupdatesh .= "`$top -d 2 -s 1 0 | $awk '{gsub(/%/, \"\")} BEGIN { \\\n";
+ $rrdupdatesh .= "printf \"$rrdtool update $rrddbpath$ifname$proc \" } \\\n";
+ $rrdupdatesh .= "{ if ( \$2 == \"processes:\" ) { processes = \$1; } \\\n";
+ $rrdupdatesh .= "else if ( \$1 == \"CPU:\" ) { user = \$2; nice = \$4; sys = \$6; interrupt = \$8; } \\\n";
+ $rrdupdatesh .= "} END { printf \"N:\"user\":\"nice\":\"sys\":\"interrupt\":\"processes }'`\n\n";
+
+ /* End CPU statistics */
+
+ /* Memory, create Memory statistics database */
+ 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 ";
+ $rrdcreate .= "DS:free:GAUGE:$memvalid:0:10000000 ";
+ $rrdcreate .= "DS:cache:GAUGE:$memvalid:0:10000000 ";
+ $rrdcreate .= "DS:wire:GAUGE:$memvalid:0:10000000 ";
+ $rrdcreate .= "RRA:MIN:0.5:1:1000 ";
+ $rrdcreate .= "RRA:MIN:0.5:5:1000 ";
+ $rrdcreate .= "RRA:MIN:0.5:60:1000 ";
+ $rrdcreate .= "RRA:MIN:0.5:720:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
+ $rrdcreate .= "RRA:MAX:0.5:1:1000 ";
+ $rrdcreate .= "RRA:MAX:0.5:5:1000 ";
+ $rrdcreate .= "RRA:MAX:0.5:60:1000 ";
+ $rrdcreate .= "RRA:MAX:0.5:720:1000";
+
+ create_new_rrd($rrdcreate);
+ }
+
+ /* enter UNKNOWN values in the RRD so it knows we rebooted. */
+ if($g['booting']) {
+ exec("$rrdtool update $rrddbpath$ifname$mem N:U:U:U:U:U");
+ }
+
+ /* the Memory stats gathering function. */
+ $rrdupdatesh .= "`$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 | ";
+ $rrdupdatesh .= " $awk '{getline active;getline inactive;getline free;getline cache;getline wire;printf \"$rrdtool update $rrddbpath$ifname$mem N:\"";
+ $rrdupdatesh .= "((active/$0) * 100)\":\"((inactive/$0) * 100)\":\"((free/$0) * 100)\":\"((cache/$0) * 100)\":\"(wire/$0 * 100)}'`\n\n";
+
+ /* End Memory statistics */
+
+ /* SPAMD, set up the spamd rrd file */
+ if (isset($config['installedpackages']['spamdsettings']) &&
+ isset ($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 ";
+ $rrdcreate .= "DS:conn:GAUGE:$spamdvalid:0:10000 ";
+ $rrdcreate .= "DS:time:GAUGE:$spamdvalid:0:86400 ";
+ $rrdcreate .= "RRA:MIN:0.5:1:1000 ";
+ $rrdcreate .= "RRA:MIN:0.5:5:1000 ";
+ $rrdcreate .= "RRA:MIN:0.5:60:1000 ";
+ $rrdcreate .= "RRA:MIN:0.5:720:1000 ";
+ $rrdcreate .= "RRA:MIN:0.5:1440:1500 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:720:1000 ";
+ $rrdcreate .= "RRA:AVERAGE:0.5:1440:1500 ";
+ $rrdcreate .= "RRA:MAX:0.5:1:1000 ";
+ $rrdcreate .= "RRA:MAX:0.5:5:1000 ";
+ $rrdcreate .= "RRA:MAX:0.5:60:1000 ";
+ $rrdcreate .= "RRA:MAX:0.5:720:1000 ";
+ $rrdcreate .= "RRA:MAX:0.5:1440:1500 ";
+
+ create_new_rrd($rrdcreate);
+ }
+
+ $rrdupdatesh .= "\n";
+ $rrdupdatesh .= "# polling spamd for connections and tarpitness \n";
+ $rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$spamd \\\n";
+ $rrdupdatesh .= "`$php -q $spamd_gather`\n";
+
+ }
+ /* End System statistics */
+
+ $rrdupdatesh .= "sleep 60\n";
+ $rrdupdatesh .= "done\n";
+ log_error("Creating rrd update script");
+ /* write the rrd update script */
+ $updaterrdscript = "{$g['vardb_path']}/rrd/updaterrd.sh";
+ $fd = fopen("$updaterrdscript", "w");
+ fwrite($fd, "$rrdupdatesh");
+ fclose($fd);
+
+ /* kill off traffic collectors */
+ kill_traffic_collector();
+
+ /* start traffic collector */
+ mwexec_bg("/usr/bin/nice -n20 /bin/sh $updaterrdscript");
+
+ } else {
+ /* kill off traffic collectors */
+ kill_traffic_collector();
+ }
+
+ if($g['booting'])
+ echo "done.\n";
+
+}
+
OpenPOWER on IntegriCloud