libcollectdclient: don't close socket twice
[collectd.git] / contrib / add_rra.sh
1 #!/bin/bash
2
3 INPUT=$1
4 OUTPUT=$2
5
6 if [ -z "$INPUT" -o -z "$OUTPUT" ]
7 then
8         cat <<USAGE
9 Usage: $0 <input> <output>
10 USAGE
11         exit 1
12 fi
13
14 if [ ! -e "$INPUT" ]
15 then
16         echo "No such file: $INPUT"
17         exit 1
18 fi
19
20 if [ -e "$OUTPUT" ]
21 then
22         echo "File exists: $OUTPUT"
23         exit 1
24 fi
25
26 NUM_DS=0
27 rrdtool dump "$INPUT" | while read LINE
28 do
29         echo "$LINE"
30
31         if [ "$LINE" = "<ds>" ]
32         then
33                 NUM_DS=$(($NUM_DS + 1))
34         fi
35         
36         if [ "$LINE" = "<!-- Round Robin Archives -->" ]
37         then
38                 for CF in MIN MAX AVERAGE
39                 do
40                         cat <<RRA
41         <rra>
42                 <cf> $CF </cf>
43                 <pdp_per_row> 1 </pdp_per_row>
44                 <xff> 0.0000000000e+00 </xff>
45
46                 <cdp_prep>
47 RRA
48                         for ((i=0; i < $NUM_DS; i++))
49                         do
50                                 echo "                  <ds><value> NaN </value>  <unknown_datapoints> 1 </unknown_datapoints></ds>"
51                         done
52                         echo "          </cdp_prep>"
53                         echo "          <database>"
54
55                         DS_VALUES=`for ((i=0; i < $NUM_DS; i++)); do echo -n "<v> NaN </v>"; done`
56                         for ((i=0; i < 2200; i++))
57                         do
58                                 echo "                  <!-- $i --> <row>$DS_VALUES</row>"
59                         done
60                         echo "          </database>"
61                         echo "  </rra>"
62                 done
63         fi
64 done >"$OUTPUT.xml"
65
66 rrdtool restore "$OUTPUT.xml" "$OUTPUT" -r >/dev/null
67 rm -f "$OUTPUT.xml"