jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [tools/] [rrdspikes.pl] - Blame information for rev 10

 

Line No. Rev Author Line
11simandl#!/usr/bin/env perl
2 
3$file=shift @ARGV;
4$arg=shift @ARGV;
5 
6if (! defined $file) {
7 print "
8usage: $0 file.rrd [c|u|z]
9 
10option 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 
19if ( (! defined $arg) || ($arg !~ /^[cuz]$/) ) { $arg=""; }
20 
21open INPUT,"rrdtool dump $file|";
22 
23if ($arg ne "") { open OUTPUT,">$file.xml"; }
24 
25while (<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 
71close INPUT;
72 
73if ($arg ne "") {
74 close OUTPUT;
75 
76 print "rebuilding database...\n";
77 system "rrdtool restore $file.xml $file.nospike";
78 }
79 

Powered by WebSVN 2.2.1