hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/usr/bin/env perl
$file=shift @ARGV;
$arg=shift @ARGV;
if (! defined $file) {
print "
usage: $0 file.rrd [c|u|z]
option may be:
c cut spikes down to new maximum value
u set spikes to unknown
z zero spikes
";
exit 1;
}
if ( (! defined $arg) || ($arg !~ /^[cuz]$/) ) { $arg=""; }
open INPUT,"rrdtool dump $file|";
if ($arg ne "") { open OUTPUT,">$file.xml"; }
while (<INPUT>) {
$change=0;
if (index($_,"<name>") >= 0) {
(undef,$val,undef)=split;
print "Found row: $val\n";
push @NAME,$val;
}
if (index($_,"<max>") >= 0) {
(undef,$val,undef)=split;
$val*=1;
push @MAX,$val;
print "Maximum : $val\n\n";
}
if (index($_,"<row>") >= 0) {
(undef,$date,$time,$zone,undef,$seconds,undef,undef,@values)=split;
$row=0;
foreach $max (@MAX) {
$value=$values[2*$row];
if ($value > $max) {
$change=1;
print "$date $time: $NAME[$row] $value > $max\n";
if ($arg eq "c") { $values[2*$row]=sprintf "%16e",$max; }
if ($arg eq "u") { $values[2*$row]="NaN"; }
if ($arg eq "z") { $values[2*$row]="0.0000000000e+00"; }
}
$row++;
}
if ($arg ne "") {
if ($change>0) {
($intro)=split /\</;
$line="$intro<!-- $date $time $zone / $seconds --> <row><v> ".join(" ",@values)."\n";
}
}
}
if ($arg ne "") {
if ($change>0) { print OUTPUT $line; }
else { print OUTPUT $_; }
}
}
close INPUT;
if ($arg ne "") {
close OUTPUT;
print "rebuilding database...\n";
system "rrdtool restore $file.xml $file.nospike";
}