diff options
author | Seth Mos <seth.mos@xs4all.nl> | 2008-12-19 22:08:21 +0000 |
---|---|---|
committer | Seth Mos <seth.mos@xs4all.nl> | 2008-12-19 22:08:21 +0000 |
commit | 529f7ddf2f617d31079ac88ed102d9890328dd55 (patch) | |
tree | 95dc76e713ba7e7af324e253daa9e1dcc8518fe8 /etc/inc | |
parent | b0a5b824a72924ae98f7064ad17326b088dd507f (diff) | |
download | pfsense-529f7ddf2f617d31079ac88ed102d9890328dd55.zip pfsense-529f7ddf2f617d31079ac88ed102d9890328dd55.tar.gz |
RRD file conversion code. Needs testing ofcourse. So far early tests show promising.
Diffstat (limited to 'etc/inc')
-rw-r--r-- | etc/inc/config.inc | 79 |
1 files changed, 56 insertions, 23 deletions
diff --git a/etc/inc/config.inc b/etc/inc/config.inc index 7cf3a84..007c593 100644 --- a/etc/inc/config.inc +++ b/etc/inc/config.inc @@ -2064,9 +2064,20 @@ endif; /* Convert 5.4 -> 5.5 */ if ($config['version'] <= 5.4) { /* RRD files changed for quality, traffic and packets graphs */ + ini_set("max_execution_time", "1800"); + /* convert traffic RRD file */ + $listtags = array("ds", "v", "rra", "row"); + $rrddbpath = "/var/db/rrd/"; $rrdtool = "/usr/local/bin/rrdtool"; + $rrdinterval = 60; + $valid = $rrdinterval * 2; + + /* Asume GigE for now */ + $downstream = 125000000; + $upstream = 125000000; + /* build a list of quality databases */ /* roundtrip has become delay */ /* the roundtrip times need to be divided by 1000 to get seconds, really */ @@ -2079,34 +2090,56 @@ endif; /* let apinger recreate required files */ setup_gateways_monitor(); - /* build a list of traffic databases */ - exec("cd $rrddbpath;/usr/bin/find -name *-traffic.rrd", $databases); + /* build a list of traffic and packets databases */ + exec("cd $rrddbpath;/usr/bin/find *-traffic.rrd *-packets.rrd", $databases); rsort($databases); foreach($databases as $database) { - log_error("Upgrading rrd database {$rrddbpath}{$database}"); - /* rename DS source */ - mwexec("$rrdtool tune {$rrddbpath}{$database} -r in:inpass "); - mwexec("$rrdtool tune {$rrddbpath}{$database} -r out:outpass "); - /* dump contents to xml and move database out of the way */ - mwexec("$rrdtool dump {$rrddbpath}{$database} > {$g['tmp_path']}/{$database}.xml"); - mwexec("mv {$rrddbpath}{$database} {$g['tmp_path']}/{$database}.backup"); - /* let enable_rrd_graphing recreate the database and restore the contents */ - mwexec("$rrdtool restore {$g['tmp_path']}/{$database}.xml {$rrddbpath}{$database} "); - } + $databasetmp = "{$database}.tmp"; + $xmldump = "{$database}.old.xml"; + $xmldumptmp = "{$database}.tmp.xml"; + $databasenew = "{$database}.new.xml"; - /* build a list of packets databases */ - exec("cd $rrddbpath;/usr/bin/find -name *-packets.rrd", $databases); - rsort($databases); - foreach($databases as $database) { - log_error("Upgrading rrd database {$rrddbpath}{$database}"); + log_error("Upgrading rrd database {$rrddbpath}/{$database}"); /* rename DS source */ - mwexec("$rrdtool tune {$rrddbpath}{$database} -r in:inpass "); - mwexec("$rrdtool tune {$rrddbpath}{$database} -r out:outpass "); + mwexec("$rrdtool tune {$rrddbpath}/{$database} -r in:inpass"); + mwexec("$rrdtool tune {$rrddbpath}/{$database} -r out:outpass"); + /* dump contents to xml and move database out of the way */ - mwexec("$rrdtool dump {$rrddbpath}{$database} > {$g['tmp_path']}/{$database}.xml"); - mwexec("mv {$rrddbpath}{$database} {$g['tmp_path']}/$databases.backup "); - /* let enable_rrd_graphing recreate the database and restore the contents */ - mwexec("$rrdtool restore {$g['tmp_path']}/{$database}.xml {$rrddbpath}{$database} "); + dump_rrd_to_xml("{$rrddbpath}/{$database}", "{$g['tmp_path']}/{$xmldump}"); + + /* create new rrd database file */ + echo "Create RRD database {$g['tmp_path']}/{$databasetmp}\n"; + $rrdcreate = "$rrdtool create {$g['tmp_path']}/{$databasetmp} --step $rrdinterval "; + $rrdcreate .= "DS:inpass:COUNTER:$valid:0:$downstream "; + $rrdcreate .= "DS:outpass:COUNTER:$valid:0:$upstream "; + $rrdcreate .= "DS:inblock:COUNTER:$valid:0:$downstream "; + $rrdcreate .= "DS:outblock:COUNTER:$valid: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"); + /* create temporary xml from new RRD */ + dump_rrd_to_xml("{$g['tmp_path']}/{$databasetmp}", "{$g['tmp_path']}/{$xmldumptmp}"); + + $rrdold = parse_xml_config_raw("{$g['tmp_path']}/{$xmldump}", "rrd"); + $rrdnew = parse_xml_config_raw("{$g['tmp_path']}/{$xmldumptmp}", "rrd"); + + /* remove any MAX RRA's. Not needed for traffic. */ + $i = 0; + foreach ($rrdold['rra'] as $rra) { + if(trim($rra['cf']) == "MAX") { + unset($rrdold['rra'][$i]); + } + $i++; + } + + $rrdxmlarray = migrate_rrd_format($rrdold, $rrdnew); + $rrdxml = dump_xml_config_raw($rrdxmlarray, "rrd"); + file_put_contents("{$g['tmp_path']}/{$databasenew}", $rrdxml); + exec("$rrdtool restore -f {$g['tmp_path']}/{$databasenew} {$rrddbpath}/{$database}"); } $config['version'] = "5.5"; } |