]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - config/qos/migrate.pl
coreutils: Update to 8.30
[people/pmueller/ipfire-2.x.git] / config / qos / migrate.pl
CommitLineData
0f3c7a54 1#!/usr/bin/perl
c8a726f1
CS
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2008 Michael Tremer & Christian Schmidt #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
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
24
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
0f3c7a54
CS
28
29my $rrddir = "/var/log/rrd";
c8a726f1 30my @files = `cd $rrddir && ls class_*.rrd`;
0f3c7a54 31
c8a726f1 32# Ff migration was already done we will skip this to avoid errors
0f3c7a54
CS
33if ( -e "$rrddir/migrated" ){print "Already migrated rrd files -> exit.\n";exit 1;}
34
c8a726f1 35# Stop collectd and qos to ensure that no one further write to the rrds
0f3c7a54
CS
36system("/etc/init.d/collectd stop");
37system("/usr/local/bin/qosctrl stop");
38
39foreach (@files){
40 chomp($_);
c8a726f1
CS
41
42 # Dump the whole rrd file to human readable xml format into an array
0f3c7a54
CS
43 my @lines = `rrdtool dump $rrddir/$_`;
44
c8a726f1 45 # to ensure only needed raw data is extracted we will use a marker
0f3c7a54 46 my $fromhere = 0;
c8a726f1
CS
47
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
50 # after migration
0f3c7a54
CS
51 my @newlines = "<!-- Round Robin Database Dump --><rrd> <version> 0003 </version>
52 <step> 10 </step> <!-- Seconds -->
53 <lastupdate> </lastupdate>
54
55 <ds>
56 <name> bytes </name>
57 <type> COUNTER </type>
58 <minimal_heartbeat> 20 </minimal_heartbeat>
59 <min> 0.0000000000e+00 </min>
60 <max> NaN </max>
61
62 <!-- PDP Status -->
63 <last_ds> </last_ds>
64 <value> </value>
65 <unknown_sec> 0 </unknown_sec>
66 </ds>
67
68<!-- Round Robin Archives --> <rra>
69 <cf> AVERAGE </cf>
70 <pdp_per_row> 1 </pdp_per_row> <!-- 10 seconds -->
71
72 <params>
73 <xff> 5.0000000000e-01 </xff>
74 </params>
75 <cdp_prep>
76 <ds>
77 <primary_value> </primary_value>
78 <secondary_value> NaN </secondary_value>
79 <value> NaN </value>
80 <unknown_datapoints> 0 </unknown_datapoints>
81 </ds>
82 </cdp_prep>
83 <database>
84";
85 foreach (@lines){
c8a726f1
CS
86
87 # if database content line is found we will start to extract the values
0f3c7a54
CS
88 if ( $_ =~ /\<database\>/ ){
89 $fromhere = 1;next;
90 }
c8a726f1 91 # if database content is finished we will stop to extract the values
0f3c7a54
CS
92 if ( $_ =~ /\<\/database\>/ ){
93 $fromhere = 0;next;
94 }
c8a726f1
CS
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
0f3c7a54
CS
98 if ( $fromhere eq "0" ){
99 next;
100 }else{
101 my @t = split(/<v>/,$_);
102 push(@newlines,$t[0]."<v>".$t[1]."</row>\n");
103 }
104 }
c8a726f1 105# Add default footer to the array so a valid rrd xml file will be created
0f3c7a54
CS
106push(@newlines," </database>
107 </rra>
108</rrd>");
c8a726f1 109# Now write the whole array to an xml file
0f3c7a54
CS
110open(DATEI, ">/tmp/rrd.xml") || die "Unable to create temp file";
111print DATEI @newlines;
112close(DATEI);
113
c8a726f1 114# Delete the old rrd file and restore a new one with content from the xml file
0f3c7a54
CS
115system("rm -f $rrddir/$_");
116system("rrdtool restore -f /tmp/rrd.xml $rrddir/$_");
117print "$_ ... resized\n";
118}
119
c8a726f1 120# Now we can restart the collection
0f3c7a54
CS
121system("/etc/init.d/collectd start");
122system("/usr/local/bin/qosctrl start");
c8a726f1
CS
123
124# Finaly we will delete unneeded evt files and touch the migration file
bec900b3 125system("rm -f $rrddir/*.evt");
0f3c7a54
CS
126system("touch $rrddir/migrated");
127exit 0;