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