| 1 | 1 | simandl | #!/usr/bin/env perl |
| 2 | | | |
| 3 | | | $file=shift @ARGV; |
| 4 | | | $arg=shift @ARGV; |
| 5 | | | |
| 6 | | | if (! defined $file) { |
| 7 | | | print " |
| 8 | | | usage: $0 file.rrd [c|u|z] |
| 9 | | | |
| 10 | | | option may be: |
| 11 | | | c cut spikes down to new maximum value |
| 12 | | | u set spikes to unknown |
| 13 | | | z zero spikes |
| 14 | | | |
| 15 | | | "; |
| 16 | | | exit 1; |
| 17 | | | } |
| 18 | | | |
| 19 | | | if ( (! defined $arg) || ($arg !~ /^[cuz]$/) ) { $arg=""; } |
| 20 | | | |
| 21 | | | open INPUT,"rrdtool dump $file|"; |
| 22 | | | |
| 23 | | | if ($arg ne "") { open OUTPUT,">$file.xml"; } |
| 24 | | | |
| 25 | | | while (<INPUT>) { |
| 26 | | | |
| 27 | | | $change=0; |
| 28 | | | |
| 29 | | | if (index($_,"<name>") >= 0) { |
| 30 | | | (undef,$val,undef)=split; |
| 31 | | | print "Found row: $val\n"; |
| 32 | | | push @NAME,$val; |
| 33 | | | } |
| 34 | | | |
| 35 | | | if (index($_,"<max>") >= 0) { |
| 36 | | | (undef,$val,undef)=split; |
| 37 | | | $val*=1; |
| 38 | | | push @MAX,$val; |
| 39 | | | print "Maximum : $val\n\n"; |
| 40 | | | } |
| 41 | | | |
| 42 | | | if (index($_,"<row>") >= 0) { |
| 43 | | | (undef,$date,$time,$zone,undef,$seconds,undef,undef,@values)=split; |
| 44 | | | $row=0; |
| 45 | | | foreach $max (@MAX) { |
| 46 | | | $value=$values[2*$row]; |
| 47 | | | if ($value > $max) { |
| 48 | | | $change=1; |
| 49 | | | print "$date $time: $NAME[$row] $value > $max\n"; |
| 50 | | | if ($arg eq "c") { $values[2*$row]=sprintf "%16e",$max; } |
| 51 | | | if ($arg eq "u") { $values[2*$row]="NaN"; } |
| 52 | | | if ($arg eq "z") { $values[2*$row]="0.0000000000e+00"; } |
| 53 | | | } |
| 54 | | | $row++; |
| 55 | | | } |
| 56 | | | |
| 57 | | | if ($arg ne "") { |
| 58 | | | if ($change>0) { |
| 59 | | | ($intro)=split /\</; |
| 60 | | | $line="$intro<!-- $date $time $zone / $seconds --> <row><v> ".join(" ",@values)."\n"; |
| 61 | | | } |
| 62 | | | } |
| 63 | | | } |
| 64 | | | |
| 65 | | | if ($arg ne "") { |
| 66 | | | if ($change>0) { print OUTPUT $line; } |
| 67 | | | else { print OUTPUT $_; } |
| 68 | | | } |
| 69 | | | } |
| 70 | | | |
| 71 | | | close INPUT; |
| 72 | | | |
| 73 | | | if ($arg ne "") { |
| 74 | | | close OUTPUT; |
| 75 | | | |
| 76 | | | print "rebuilding database...\n"; |
| 77 | | | system "rrdtool restore $file.xml $file.nospike"; |
| 78 | | | } |
| 79 | | | |