diff options
author | Seth Mos <seth.mos@xs4all.nl> | 2006-11-22 17:47:36 +0000 |
---|---|---|
committer | Seth Mos <seth.mos@xs4all.nl> | 2006-11-22 17:47:36 +0000 |
commit | 6ab7ae508a026c9a0fa906d3a274a9efc7adfe75 (patch) | |
tree | 9a11da22755935484cdd5dd0030c755e70595887 /etc/inc | |
parent | 09da8bfab1063df6e50aa0a9a51c1b0a851c06d1 (diff) | |
download | pfsense-6ab7ae508a026c9a0fa906d3a274a9efc7adfe75.zip pfsense-6ab7ae508a026c9a0fa906d3a274a9efc7adfe75.tar.gz |
Merge newer rrd graphing code, drop down now only lists valid rrd
targets. Added CPU and States graphs. More logging in case of graph
generation. Minor bugfixes and cleanup.
Diffstat (limited to 'etc/inc')
-rw-r--r-- | etc/inc/pfsense-utils.inc | 489 |
1 files changed, 318 insertions, 171 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index a67782e..a079981 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -1953,80 +1953,93 @@ function convert_real_interface_to_friendly_descr($interface) { return $interface; } -function enable_rrd_graphing() -{ -// consider syncing the rrd files to usb storage/xml (cdrom, embbedded) +function enable_rrd_graphing() { global $config, $g; - $rrddbpath = "/var/db/rrd/"; - $rrdgraphpath = "/usr/local/www/rrd"; - $rrdtrafficinterval = 60; - $rrdqualityinterval = 60; - $rrdqueuesinterval = 60; - $rrdpacketsinterval = 60; - $rrdspamdinterval = 60; + $rrddbpath = "/var/db/rrd/"; + $rrdgraphpath = "/usr/local/www/rrd"; $traffic = "-traffic.rrd"; $packets = "-packets.rrd"; + $states = "-states.rrd"; $quality = "-quality.rrd"; $queues = "-queues.rrd"; - $spamd = "spamd.rrd"; + $queuesdrop = "-queuesdrop.rrd"; + $spamd = "-spamd.rrd"; + $proc = "-processor.rrd"; + $rrdtool = "/usr/local/bin/rrdtool"; $netstat = "/usr/bin/netstat"; $awk = "/usr/bin/awk"; $tar = "/usr/bin/tar"; + $pfctl = "/sbin/pfctl"; $php = "/usr/local/bin/php"; + $top = "/usr/bin/top"; $spamd_gather = "/usr/local/bin/spamd_gather_stats.php"; - $gatewayip = exec("/sbin/route -n get default | /usr/bin/grep gateway | /usr/bin/awk '{print $2}'"); - /* if an alternative gateway is defined, use it. */ - if($config['system']['use_rrd_gateway']) + /* if an alternative gateway is defined, use it */ + if ($config['system']['use_rrd_gateway'] <> "") $gatewayip = $config['system']['use_rrd_gateway']; + else + $gatewayip = exec("/sbin/route -n get default | /usr/bin/grep gateway | /usr/bin/awk '{print $2}'"); + $numpings = 5; $btick = '`'; - $trafficvalid = $rrdtrafficinterval*2 ; - $qualityvalid = $rrdqualityinterval*2 ; - $queuesvalid = $rrdqueuesinterval*2 ; - $packetsvalid = $rrdpacketsinterval*2 ; - $spamdvalid = $rrdspamdinterval*2 ; + $rrdtrafficinterval = 60; + $rrdqualityinterval = 60; + $rrdqueuesinterval = 60; + $rrdqueuesdropinterval = 60; + $rrdpacketsinterval = 60; + $rrdstatesinterval = 60; + $rrdspamdinterval = 60; + $rrdlbpoolinterval = 60; + $rrdprocinterval = 60; + + $trafficvalid = $rrdtrafficinterval * 2; + $qualityvalid = $rrdqualityinterval * 2; + $queuesvalid = $rrdqueuesinterval * 2; + $queuesdropvalid = $rrdqueuesdropinterval * 2; + $packetsvalid = $rrdpacketsinterval * 2; + $statesvalid = $rrdstatesinterval*2; + $spamdvalid = $rrdspamdinterval * 2; + $lbpoolvalid = $rrdlbpoolinterval * 2; + $procvalid = $rrdlbpoolinterval * 2; /* Asume GigE for now */ $downstream = 125000000; - $upstream = 125000000; + $upstream = 125000000; $rrdrestore = ""; $rrdreturn = ""; $config['rrd']['enable'] = true; - if (isset($config['rrd']['enable'])) { + if (isset ($config['rrd']['enable'])) { /* create directory if needed */ - if(!is_dir("$rrddbpath")) { + if (!is_dir("$rrddbpath")) { mkdir("$rrddbpath", 0755); } - if($g['booting']) { + if ($g['booting']) { /* if we are on livecd or embedded use a memoryfs. */ /* 6MB is enough for everyone. *cough* */ - if($g['platform'] != "pfSense") { + if ($g['platform'] != "pfSense") { /* determine highest MD device */ $mdnr = `mount |grep md | awk -F"md" '{print $2}'|tail -1 |cut -c 1`; $mdnr = $mdnr +1; system("/sbin/mdmfs -M -s 6m md$mdnr $rrddbpath"); /* we now have something to write "on", restore the databases if we have them */ - if(file_exists("{$g['cf_conf_path']}/rrd.tgz")) { + if (file_exists("{$g['cf_conf_path']}/rrd.tgz")) { exec("cd /;/usr/bin/tar -xzf {$g['cf_conf_path']}/rrd.tgz", $rrdrestore, $rrdreturn); if((int)$rrdrestore <> 0) { - log_error("RRD restore failed exited with $rrdreturn, the - error is: $rrdrestore[0]\n"); + log_error("RRD restore failed exited with $rrdreturn, the error is: $rrdrestore[0]\n"); } } } - } /* db update script */ @@ -2037,62 +2050,52 @@ function enable_rrd_graphing() $rrdupdatesh .= "do\n"; $rrdupdatesh .= ""; - /* directory index */ - $rrdgraphindexhtml = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> -<HTML> -<HEAD> - <TITLE>MRTG Index Page</TITLE> - <META HTTP-EQUIV=\"Refresh\" CONTENT=\"360\"> - <META HTTP-EQUIV=\"Cache-Control\" content=\"no-cache\"> - <META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"> - <META HTTP-EQUIV=\"Expires\" CONTENT=\"Tue, 22 May 2001 09:22:45 GMT\"> -</HEAD> -<BODY bgcolor=\"#ffffff\" text=\"#000000\" link=\"#000000\" vlink=\"#000000\" alink=\"#000000\"> -<H1>MRTG Index Page</H1> -<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=10>"; - - $i = 0; - $vfaces = array("vlan.?*"); - $ifdescrs = get_interface_list(true, true, $vfaces); - foreach ($ifdescrs as $realif => $ifdescr) { + $i = 0; + $vfaces = array ( + "vlan.?*" + ); + $ifdescrs = get_interface_list(true, true, $vfaces); + foreach ($ifdescrs as $realif => $ifdescr) { $ifname = $ifdescr['friendly']; $state = $ifdescr['up']; /* skip interfaces that do not have a friendly name */ - if("$ifname" == "") { + if ("$ifname" == "") { continue; } /* or are down */ - if(! $state) { + if (!$state) { continue; } - /* set up the rrd file */ - if(! file_exists("$rrddbpath$ifname$traffic")) { + /* TRAFFIC, set up the rrd file */ + if (!file_exists("$rrddbpath$ifname$traffic")) { /* create rrd file if it does not exist */ log_error("Create RRD database $rrddbpath$ifname$traffic"); $rrdcreate = "$rrdtool create $rrddbpath$ifname$traffic --step $rrdtrafficinterval \ - DS:in:COUNTER:$trafficvalid:0:$downstream \ - DS:out:COUNTER:$trafficvalid:0:$upstream \ - RRA:AVERAGE:0.5:1:1000 \ - RRA:AVERAGE:0.5:5:1000 \ - RRA:AVERAGE:0.5:60:1000 \ - RRA:AVERAGE:0.5:360:1000 \ - RRA:MAX:0.5:1:1000 \ - RRA:MAX:0.5:5:1000 \ - RRA:MAX:0.5:60:1000 \ - RRA:MAX:0.5:3600:1000"; + DS:in:COUNTER:$trafficvalid:0:$downstream \ + DS:out:COUNTER:$trafficvalid:0:$upstream \ + RRA:AVERAGE:0.5:1:1000 \ + RRA:AVERAGE:0.5:5:1000 \ + RRA:AVERAGE:0.5:60:1000 \ + RRA:AVERAGE:0.5:720:1000 \ + RRA:MAX:0.5:1:1000 \ + RRA:MAX:0.5:5:1000 \ + RRA:MAX:0.5:60:1000 \ + RRA:MAX:0.5:720:1000"; $rrdcreateoutput = array(); $rrdcreatereturn = ""; $rrdcreatel = exec("$rrdcreate 2>&1", $rrdcreateoutput, $rrdcreatereturn); - if($rrdcreatereturn != 0) { - log_error("RRD create failed exited with $rrdcreatereturn, the error is: $rrdcreateoutput[0]\n"); + if ($rrdcreatereturn != 0) { + log_error("RRD create failed exited with $rrdcreatereturn, the + error is: $rrdcreateoutput[0]\n"); } } + /* enter UNKNOWN values in the RRD so it knows we rebooted. */ if($g['booting']) { exec("$rrdtool update $rrddbpath$ifname$traffic N:U:U"); } @@ -2103,28 +2106,30 @@ function enable_rrd_graphing() $rrdupdatesh .= "`$netstat -nbf link -I {$realif} | $awk '{getline 2;print \$7}'`:\\\n"; $rrdupdatesh .= "`$netstat -nbf link -I {$realif} | $awk '{getline 2;print \$10}'`\n\n"; - /* set up the rrd file */ - if(! file_exists("$rrddbpath$ifname$packets")) { + /* PACKETS, set up the rrd file */ + if (!file_exists("$rrddbpath$ifname$packets")) { /* create rrd file if it does not exist */ log_error("Create RRD database $rrddbpath$ifname$packets"); $rrdcreate = "$rrdtool create $rrddbpath$ifname$packets --step $rrdpacketsinterval \ - DS:in:COUNTER:$packetsvalid:0:$downstream \ - DS:out:COUNTER:$packetsvalid:0:$upstream \ - RRA:AVERAGE:0.5:1:1000 \ - RRA:AVERAGE:0.5:5:1000 \ - RRA:AVERAGE:0.5:60:1000 \ - RRA:AVERAGE:0.5:360:1000 \ - RRA:MAX:0.5:1:1000 \ - RRA:MAX:0.5:5:1000 \ - RRA:MAX:0.5:60:1000 \ - RRA:MAX:0.5:360:1000"; + DS:in:COUNTER:$packetsvalid:0:$downstream \ + DS:out:COUNTER:$packetsvalid:0:$upstream \ + RRA:AVERAGE:0.5:1:1000 \ + RRA:AVERAGE:0.5:5:1000 \ + RRA:AVERAGE:0.5:60:1000 \ + RRA:AVERAGE:0.5:720:1000 \ + RRA:MAX:0.5:1:1000 \ + RRA:MAX:0.5:5:1000 \ + RRA:MAX:0.5:60:1000 \ + RRA:MAX:0.5:720:1000"; $rrdcreatel = exec("$rrdcreate 2>&1", $rrdcreateoutput, $rrdcreatereturn); - if($rrdcreatereturn != 0) { - log_error("RRD create failed exited with $rrdcreatereturn, the error is: $rrdcreateoutput[0]\n"); + if ($rrdcreatereturn != 0) { + log_error("RRD create failed exited with $rrdcreatereturn, the + error is: $rrdcreateoutput[0]\n"); } } + /* enter UNKNOWN values in the RRD so it knows we rebooted. */ if($g['booting']) { exec("$rrdtool update $rrddbpath$ifname$packets N:U:U"); } @@ -2135,20 +2140,11 @@ function enable_rrd_graphing() $rrdupdatesh .= "`$netstat -nbf link -I {$realif} | $awk '{getline 2;print \$5}'`:\\\n"; $rrdupdatesh .= "`$netstat -nbf link -I {$realif} | $awk '{getline 2;print \$8}'`\n\n"; - $rrdgraphindexhtml .= "<TR> -<TD><DIV><B>Traffic Analysis for $ifname -- day</B></DIV> -<DIV><IMG BORDER=1 ALT=\"$ifname Traffic Graph\" SRC=\"$ifname-day.png\"> -<BR> -</TD> -<TD><DIV><B>Traffic Analysis for $ifname -- week</B></DIV> -<DIV><IMG BORDER=1 ALT=\"$ifname Traffic Graph\" SRC=\"$ifname-week.png\"> -<BR> -</TD> -</TR>"; - - if("$ifname" == "wan") { - /* create link quality database */ - if(! file_exists("$rrddbpath$ifname$quality")) { + /* WAN interface only statistics */ + if ("$ifname" == "wan") { + + /* QUALITY, create link quality database */ + if (!file_exists("$rrddbpath$ifname$quality")) { /* create rrd file if it does not exist */ log_error("Create RRD database $rrddbpath$ifname$quality"); $rrdcreate = "$rrdtool create $rrddbpath$ifname$quality --step $rrdqualityinterval \ @@ -2157,128 +2153,286 @@ function enable_rrd_graphing() RRA:AVERAGE:0.5:1:1000 \ RRA:AVERAGE:0.5:5:1000 \ RRA:AVERAGE:0.5:60:1000 \ - RRA:AVERAGE:0.5:360:1000"; + RRA:AVERAGE:0.5:720:1000"; $rrdcreatel = exec("$rrdcreate 2>&1", $rrdcreateoutput, $rrdcreatereturn); - if($rrdcreatereturn != 0) { - log_error("RRD create failed exited with $rrdcreatereturn, the - error is: $rrdcreateoutput[0]\n"); + if ($rrdcreatereturn != 0) { + log_error("RRD create failed exited with $rrdcreatereturn, the error is: $rrdcreateoutput[0]\n"); } } + /* enter UNKNOWN values in the RRD so it knows we rebooted. */ + if($g['booting']) { + exec("$rrdtool update $rrddbpath$ifname$quality N:U:U"); + } + /* the ping test function. We call this on the last line */ $rrdupdatesh .= "get_ping_stats () { - packetloss=100 - roundtrip=0 - local out - out=$btick ping -c $numpings -q $gatewayip $btick - if [ $? -eq 0 ]; then - packetloss=$btick echo \$out | cut -f18 -d' ' | cut -c -1 $btick - roundtrip=$btick echo \$out | cut -f24 -d' ' | cut -f2 -d'/' $btick - fi - $rrdtool update $rrddbpath$ifname$quality N:\$packetloss:\$roundtrip - }\n\n"; + packetloss=100 + roundtrip=0 + local out + out=$btick ping -c $numpings -q $gatewayip $btick + if [ $? -eq 0 ]; then + packetloss=$btick echo \$out | cut -f18 -d' ' | cut -c -1 $btick + roundtrip=$btick echo \$out | cut -f24 -d' ' | cut -f2 -d'/' $btick + fi + $rrdtool update $rrddbpath$ifname$quality N:\$packetloss:\$roundtrip + }\n\n"; $rrdupdatesh .= "get_ping_stats &\n\n"; + /* QUEUES, set up the queues databases */ if (!is_array($config['shaper']['queue'])) { - $config['shaper']['queue'] = array(); + $config['shaper']['queue'] = array (); } - $a_queues = &$config['shaper']['queue']; + $a_queues = & $config['shaper']['queue']; - if(isset($config['shaper']['enable'])) { - if(!file_exists("$rrddbpath$ifname$queues")) { + if (isset ($config['shaper']['enable'])) { + if (!file_exists("$rrddbpath$ifname$queues")) { /* create rrd file if it does not exist */ log_error("Create RRD database $rrddbpath$ifname$queues"); $rrdcreate = "$rrdtool create $rrddbpath$ifname$queues --step $rrdqueuesinterval \\\n"; /* loop list of shaper queues */ $q = 0; - foreach ($a_queues as $queue) { + foreach ($a_queues as $queue) { $name = $queue['name']; $rrdcreate .= "DS:$name:COUNTER:$queuesvalid:0:$downstream \\\n"; } $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 \ - RRA:AVERAGE:0.5:5:1000 \ - RRA:AVERAGE:0.5:60:1000 \ - RRA:AVERAGE:0.5:360:1000"; + RRA:AVERAGE:0.5:5:1000 \ + RRA:AVERAGE:0.5:60:1000 \ + RRA:AVERAGE:0.5:720:1000"; + + $rrdcreatel = exec("$rrdcreate 2>&1", $rrdcreateoutput, $rrdcreatereturn); + if ($rrdcreatereturn != 0) { + log_error("RRD create failed exited with $rrdcreatereturn, the + error is: $rrdcreateoutput[0]\n"); + } + } + + if (!file_exists("$rrddbpath$ifname$queuesdrop")) { + /* create rrd file if it does not exist */ + log_error("Create RRD database $rrddbpath$ifname$queuesdrop"); + $rrdcreate = "$rrdtool create $rrddbpath$ifname$queuesdrop --step $rrdqueuesdropinterval \\\n"; + /* loop list of shaper queues */ + $q = 0; + foreach ($a_queues as $queue) { + $name = $queue['name']; + $rrdcreate .= "DS:$name:COUNTER:$queuesdropvalid:0:$downstream \\\n"; + } + + $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 \ + RRA:AVERAGE:0.5:5:1000 \ + RRA:AVERAGE:0.5:60:1000 \ + RRA:AVERAGE:0.5:720:1000"; $rrdcreatel = exec("$rrdcreate 2>&1", $rrdcreateoutput, $rrdcreatereturn); - if($rrdcreatereturn != 0) { - log_error("RRD create failed exited with $rrdcreatereturn, the - error is: $rrdcreateoutput[0]\n"); + if ($rrdcreatereturn != 0) { + log_error("RRD create failed exited with $rrdcreatereturn, the error is: $rrdcreateoutput[0]\n"); } } if($g['booting']) { - $rrducommand = "$rrdtool update $rrddbpath$ifname$queues N"; + $rrdqcommand = "-t "; + $rrducommand = "N"; + $q = 0; foreach ($a_queues as $queue) { + if($q == 0) { + $rrdqcommand .= "{$queue['name']}"; + } else { + $rrdqcommand .= ":{$queue['name']}"; + } + $q++; $rrducommand .= ":U"; } - exec("$rrducommand"); + exec("$rrdtool update $rrddbpath$ifname$queues $rrdqcommand $rrducommand"); + exec("$rrdtool update $rrddbpath$ifname$queuesdrop $rrdqcommand $rrducommand"); } - /* awk function to gather shaper data */ - /* yes, it's special */ - $rrdupdatesh .= "` pfctl -vsq | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queues \" } \\ - { \ - if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { \\ - dsname = dsname \":\" \$2 ; \\ - q=1; \\ - } \\ - else if ((\$4 == \"bytes:\") && ( q == 1 ) ) { \\ - dsdata = dsdata \":\" \$5 ; \\ - q=0; \\ - } \\ - } END { \\ - dsname = substr(dsname,2); \\ - dsdata = substr(dsdata,2); \\ - printf \"-t \" dsname \" N:\" dsdata }' \\ - dsname=\"\" dsdata=\"\"`\n\n"; + /* awk function to gather shaper data */ + /* yes, it's special */ + $rrdupdatesh .= "` pfctl -vsq | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queues \" } \\ + { \\ + if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { \\ + dsname = dsname \":\" \$2 ; \\ + q=1; \\ + } \\ + else if ((\$4 == \"bytes:\") && ( q == 1 ) ) { \\ + dsdata = dsdata \":\" \$5 ; \\ + q=0; \\ + } \\ + } END { \\ + dsname = substr(dsname,2); \\ + dsdata = substr(dsdata,2); \\ + printf \"-t \" dsname \" N:\" dsdata }' \\ + dsname=\"\" dsdata=\"\"`\n\n"; + + $rrdupdatesh .= "` pfctl -vsq | awk 'BEGIN {printf \"$rrdtool update $rrddbpath$ifname$queuesdrop \" } \\ + { \\ + if ((\$1 == \"queue\") && ( \$2 ~ /^q/ )) { \\ + dsname = dsname \":\" \$2 ; \\ + q=1; \\ + } \\ + else if ((\$4 == \"bytes:\") && ( q == 1 ) ) { \\ + dsdata = dsdata \":\" \$8 ; \\ + q=0; \\ + } \\ + } END { \\ + dsname = substr(dsname,2); \\ + dsdata = substr(dsdata,2); \\ + printf \"-t \" dsname \" N:\" dsdata }' \\ + dsname=\"\" dsdata=\"\"`\n\n"; } } + } + $i++; - } - $i++; + /* System only statistics */ + $ifname = "system"; - $rrdgraphindexhtml .= "</TABLE> -</BODY> -</HTML>"; + /* STATES, create pf states database */ + if(! file_exists("$rrddbpath$ifname$states")) { + /* create rrd file if it does not exist */ + log_error("Create RRD database $rrddbpath$ifname$states"); + $rrdcreate = "$rrdtool create $rrddbpath$ifname$states --step $rrdstatesinterval \ + DS:pfrate:GAUGE:$statesvalid:0:10000000 \ + DS:pfstates:GAUGE:$statesvalid:0:10000000 \ + DS:pfnat:GAUGE:$statesvalid:0:10000000 \ + DS:srcip:GAUGE:$statesvalid:0:10000000 \ + DS:dstip:GAUGE:$statesvalid:0:10000000 \ + RRA:MIN:0.5:1:1000 \ + RRA:MIN:0.5:5:1000 \ + RRA:MIN:0.5:60:1000 \ + RRA:MIN:0.5:360:1000 \ + RRA:AVERAGE:0.5:1:1000 \ + RRA:AVERAGE:0.5:5:1000 \ + RRA:AVERAGE:0.5:60:1000 \ + RRA:AVERAGE:0.5:360:1000 \ + RRA:MAX:0.5:1:1000 \ + RRA:MAX:0.5:5:1000 \ + RRA:MAX:0.5:60:1000 \ + RRA:MAX:0.5:360:1000"; - if(isset($config['installedpackages']['spamdsettings']['config'][0]['enablerrd'])) { - /* set up the spamd rrd file */ - if(! file_exists("$rrddbpath$spamd")) { + $rrdcreatel = exec("$rrdcreate 2>&1", $rrdcreateoutput, $rrdcreatereturn); + if($rrdcreatereturn != 0) { + log_error("RRD create failed exited with $rrdcreatereturn, the + error is: $rrdcreateoutput[0]\n"); + } + } + + /* 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 .= " + pfrate=\"` $pfctl -si | egrep \"inserts|removals\" | awk '{ pfrate = \$3 + pfrate } {print pfrate}'|tail -1 `\" + pfstates=\"` $pfctl -ss | egrep -v \"<\\-.*?<\\-|\\->.*?\\->\" | wc -l|sed 's/ //g'`\" + pfnat=\"` $pfctl -ss | egrep '<\\-.*?<\\-|\\->.*?\\->' | wc -l|sed 's/ //g' `\" + srcip=\"` $pfctl -ss | egrep -v '<\\-.*?<\\-|\\->.*?\\->' | grep '\\->' | awk '{print \$3}' | awk -F: '{print \$1}' | sort -u|wc -l|sed 's/ //g' `\" + dstip=\"` $pfctl -ss | egrep -v '<\\-.*?<\\-|\\->.*?\\->' | grep '<\\-' | awk '{print \$3}' | awk -F: '{print \$1}' | sort -u|wc -l|sed 's/ //g' `\" + + $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")) { /* create rrd file if it does not exist */ - log_error("Create RRD database $rrddbpath$spamd"); - $rrdcreate = "$rrdtool create $rrddbpath$spamd --step $rrdspamdinterval \ - DS:conn:GAUGE:$trafficvalid:0:10000 \ - DS:time:GAUGE:$trafficvalid:0:86400 \ - RRA:MIN:0.5:1:1000 \ - RRA:MIN:0.5:5:1000 \ - RRA:MIN:0.5:60:1000 \ - RRA:MIN:0.5:360:1000 \ - RRA:AVERAGE:0.5:1:1000 \ - RRA:AVERAGE:0.5:5:1000 \ - RRA:AVERAGE:0.5:60:1000 \ - RRA:AVERAGE:0.5:360:1000 \ - RRA:MAX:0.5:1:1000 \ - RRA:MAX:0.5:5:1000 \ - RRA:MAX:0.5:60:1000 \ - RRA:MAX:0.5:360:1000"; + log_error("Create RRD database $rrddbpath$ifname$proc"); + $rrdcreate = "$rrdtool create $rrddbpath$ifname$proc --step $rrdprocinterval \ + DS:user:GAUGE:$procvalid:0:10000000 \ + DS:nice:GAUGE:$procvalid:0:10000000 \ + DS:system:GAUGE:$procvalid:0:10000000 \ + DS:interrupt:GAUGE:$procvalid:0:10000000 \ + DS:processes:GAUGE:$procvalid:0:10000000 \ + RRA:MIN:0.5:1:1000 \ + RRA:MIN:0.5:5:1000 \ + RRA:MIN:0.5:60:1000 \ + RRA:MIN:0.5:360:1000 \ + RRA:AVERAGE:0.5:1:1000 \ + RRA:AVERAGE:0.5:5:1000 \ + RRA:AVERAGE:0.5:60:1000 \ + RRA:AVERAGE:0.5:360:1000 \ + RRA:MAX:0.5:1:1000 \ + RRA:MAX:0.5:5:1000 \ + RRA:MAX:0.5:60:1000 \ + RRA:MAX:0.5:360:1000"; $rrdcreatel = exec("$rrdcreate 2>&1", $rrdcreateoutput, $rrdcreatereturn); if($rrdcreatereturn != 0) { - log_error("RRD create failed exited with $rrdcreatereturn, the + log_error("RRD create failed exited with $rrdcreatereturn, the error is: $rrdcreateoutput[0]\n"); } } - $rrdupdatesh .= "\n"; - $rrdupdatesh .= "# polling spamd for connections and tarpitness \n"; - $rrdupdatesh .= "$rrdtool update $rrddbpath$spamd \\\n"; - $rrdupdatesh .= "`$php -q $spamd_gather`\n"; + /* 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 { \\ + printf \"$rrdtool update $rrddbpath$ifname$proc \" } \\ + { if ( \$2 == \"processes:\" ) { \\ + processes = \$1; \\ + } \\ + else if ( \$1 == \"CPU\" ) { \\ + user = \$3; \\ + nice = \$5; \\ + sys = \$7; \\ + interrupt = \$9; \\ + } \\ + } END { \\ + printf \"N:\"user\":\"nice\":\"sys\":\"interrupt\":\"processes \\ + }'`\n\n"; + + /* End CPU statistics */ + + /* SPAMD, set up the spamd rrd file */ + if (isset($config['installedpackages']['spamdsettings']) && + isset ($config['installedpackages']['spamdsettings']['config'][0]['enablerrd'])) { + /* Move old name to new name */ + if (file_exists("{$rrddbpath}spamd.rrd")) { + rename("{$rrddbpath}spamd.rrd", "$rrddbpath$ifname$spamd"); + } + /* set up the spamd rrd file */ + if (!file_exists("$rrddbpath$ifname$spamd")) { + /* create rrd file if it does not exist */ + log_error("Create RRD database $rrddbpath$ifname$spamd"); + $rrdcreate = "$rrdtool create $rrddbpath$ifname$spamd --step $rrdspamdinterval \ + DS:conn:GAUGE:$spamdvalid:0:10000 \ + DS:time:GAUGE:$spamdvalid:0:86400 \ + RRA:MIN:0.5:1:1000 \ + RRA:MIN:0.5:5:1000 \ + RRA:MIN:0.5:60:1000 \ + RRA:MIN:0.5:720:1000 \ + RRA:AVERAGE:0.5:1:1000 \ + RRA:AVERAGE:0.5:5:1000 \ + RRA:AVERAGE:0.5:60:1000 \ + RRA:AVERAGE:0.5:720:1000 \ + RRA:MAX:0.5:1:1000 \ + RRA:MAX:0.5:5:1000 \ + RRA:MAX:0.5:60:1000 \ + RRA:MAX:0.5:720:1000"; + + $rrdcreatel = exec("$rrdcreate 2>&1", $rrdcreateoutput, $rrdcreatereturn); + if ($rrdcreatereturn != 0) { + log_error("RRD create failed exited with $rrdcreatereturn, the + error is: $rrdcreateoutput[0]\n"); + } + } + + $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"; @@ -2289,13 +2443,6 @@ function enable_rrd_graphing() fwrite($fd, "$rrdupdatesh"); fclose($fd); - log_error("Creating rrd graph index"); - /* write the index.html script */ - $rrdgraphindex = "{$g['vardb_path']}/rrd/index.html"; - $fd = fopen("$rrdgraphindex", "w"); - fwrite($fd, "$rrdgraphindexhtml"); - fclose($fd); - /* kill off traffic collectors */ kill_traffic_collector(); |