]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/qos/migrate.pl
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2008 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 # This skript will migrate all old rrd files with ADSL Optimizer Style to a
23 # custom IPFire one only collecting byte count for the QoS classes
25 # Fore testing purpose i recommend to copy your rrd files to /tmp and change
26 # the rrddir, then you are able to test the migration without problems
27 # Migration will take all classes rrd into count
29 my $rrddir = "/var/log/rrd";
30 my @files = `cd $rrddir && ls class_*.rrd`;
32 # Ff migration was already done we will skip this to avoid errors
33 if ( -e
"$rrddir/migrated" ){print "Already migrated rrd files -> exit.\n";exit 1;}
35 # Stop collectd and qos to ensure that no one further write to the rrds
36 system("/etc/init.d/collectd stop");
37 system("/usr/local/bin/qosctrl stop");
42 # Dump the whole rrd file to human readable xml format into an array
43 my @lines = `rrdtool dump $rrddir/$_`;
45 # to ensure only needed raw data is extracted we will use a marker
48 # because every rrd hase the same header we can use a general one deleting
49 # lastupdate and lastvalue they will be set the first time rrd is written
51 my @newlines = "<!-- Round Robin Database Dump --><rrd> <version> 0003 </version>
52 <step> 10 </step> <!-- Seconds -->
53 <lastupdate> </lastupdate>
57 <type> COUNTER </type>
58 <minimal_heartbeat> 20 </minimal_heartbeat>
59 <min> 0.0000000000e+00 </min>
65 <unknown_sec> 0 </unknown_sec>
68 <!-- Round Robin Archives --> <rra>
70 <pdp_per_row> 1 </pdp_per_row> <!-- 10 seconds -->
73 <xff> 5.0000000000e-01 </xff>
77 <primary_value> </primary_value>
78 <secondary_value> NaN </secondary_value>
80 <unknown_datapoints> 0 </unknown_datapoints>
87 # if database content line is found we will start to extract the values
88 if ( $_ =~ /\<database\>/ ){
91 # if database content is finished we will stop to extract the values
92 if ( $_ =~ /\<\/database\
>/ ){
95 # if extraction is not set we will skip this line else we will extract
96 # only the first row and drop all the other ones, the new raw line
97 # will be written to and array
98 if ( $fromhere eq "0" ){
101 my @t = split(/<v>/,$_);
102 push(@newlines,$t[0]."<v>".$t[1]."</row>\n");
105 # Add default footer to the array so a valid rrd xml file will be created
106 push(@newlines," </database>
109 # Now write the whole array to an xml file
110 open(DATEI
, ">/tmp/rrd.xml") || die "Unable to create temp file";
111 print DATEI
@newlines;
114 # Delete the old rrd file and restore a new one with content from the xml file
115 system("rm -f $rrddir/$_");
116 system("rrdtool restore -f /tmp/rrd.xml $rrddir/$_");
117 print "$_ ... resized\n";
120 # Now we can restart the collection
121 system("/etc/init.d/collectd start");
122 system("/usr/local/bin/qosctrl start");
124 # Finaly we will delete unneeded evt files and touch the migration file
125 system("rm -f $rrddir/*.evt");
126 system("touch $rrddir/migrated");