#!/usr/bin/perl -w # # matapicos v2.2 - Vins Vilaplana $tempfile`; # Scan the XML dump checking the variations and exponent deviations open(FICH,"<$tempfile") || die "$0: Cannot open file $tempfile:\n $! - $@"; while () { chomp; $linea=$_; $cdo=0; if ($linea=~/^(.*)/) { $tstamp=$1; } if ($linea=~/(.*)$/) { $tresto=$1; } if (/\s\d\.\d+e.(\d+)\s<\/v>/) { @dump = split(/<\/v>/, $tresto); for ($lino=0; $lino<=$#dump-1; $lino++) { # scans DS's within each row if ( $dump[$lino]=~/\d\.\d+e.(\d+)\s/ ) { # make sure it is a number (and not NaN) $a=substr("0$lino",-2).":".$1; $exp{$a}++; # store exponents $tot{substr("0$lino",-2)}++; # and keep a per DS total } } } } close FICH; ########################################################################### # Scan the hash to get the percentage variation of each value foreach $lino (sort keys %exp) { ($a)=$lino=~/^(\d+)\:/; $por{$lino}=(100*$exp{$lino})/$tot{$a}; } if ($DEBUG) { # Dumps percentages for debugging purposes print "--percentages--\n"; foreach $lino (sort keys %exp) { print $lino."--".$exp{$lino}."/"; ($a)=$lino=~/^(\d+)\:/; print $tot{$a}." = ".$por{$lino}."%\n"; } print "\n\n\n"; } ########################################################################### # Open the XML dump, and create a new one removing the spikes: open(FICH,"<$tempfile") || die "$0: Cannot open $tempfile for reading: $!-$@"; open(FSAL,">$tempfile.xml") || die "$0: Cannot open $tempfile.xml for writing: $!-$@"; $linbak=''; $cont=0; while () { chomp; $linea=$_; $cdo=0; if ($linea=~/^(.*)/) { $tstamp=$1; } # Grab timestamp if ($linea=~/(.*)$/) { $tresto=$1; } # grab rest-of-line :-) if (/\s\d\.\d+e.(\d+)\s<\/v>/) { # are there DS's? @dump=split(/<\/v>/, $tresto); # split them if ($linbak ne '') { for ($lino=0;$lino<=$#dump-1;$lino++) { # for each DS: if ($dump[$lino]=~/\d\.\d+e.(\d+)\s/) { # grab number (and not a NaN) $a=$1*1; # and exponent $b=substr("0$lino",-2).":$1"; # calculate the max percentage of this DS if ($por{$b}< $LIMIT) { # if this line represents less than $LIMIT $linea=$tstamp.$linbak; # we dump it. $cdo=1; $tresto=$linbak; } } } } $linbak=$tresto; if ($cdo==1) { print "Chopping peak at $tstamp\n"; $cont++; } } print FSAL "$linea\n"; } close FICH; close FSAL; ########################################################################### # Cleanup and move new file to the place of original one # and original one gets backed up. if ($cont == 0) { print "No peaks found.!\n"; } else { rename($ARGV[0],"$ARGV[0].old"); $lino="rrdtool restore $tempfile.xml $ARGV[0]"; system($lino); die "$0: Unable to execute the rrdtool restore on $ARGV[0] - $! - $@\n" if $? != 0; } # cleans up the files created unlink("$tempfile"); unlink("$tempfile.xml");