Configuring the Serial port for the Javelin Terminal » |
If you are like me and looking for a way to add a nex column to an existing RRD database, maybe you are going to spend a lot of time on google to look for it.
Unable to find any solution, I tried with some basic tools (RRDDump, RRDRestore, replace, etc.) and I was able to find a way to do so. So I'm sharing what I found in case that can help you.
I have initialy created a database to store the temperature of the water inside my water tank. With this script.
rrdtool create eau.rrd --start 1202484376 \
DS:HWH:GAUGE:288:U:U \
RRA:AVERAGE:0.5:1:12 \
RRA:AVERAGE:0.5:1:288 \
RRA:AVERAGE:0.5:1:2016 \
RRA:AVERAGE:0.5:1:8928 \
RRA:AVERAGE:0.5:1:105408 \
RRA:AVERAGE:0.5:1:316224
HWH for Hot Water High, because I thought also about adding a sensor on the bottom of the tank. Which I did. So now, I want to have HWH, HWL and Room for the room temperature.
First, stop your cronjob which is feeding your source. Then, export your data to an XML file and at the same time, add the numbers of new columns you want. In the example below, I'm adding 2 new columns. The "replace" tool is available in the MYSQL package.
rrdtool dump eau.rrd | replace "</v></row>" "</v><v> NaN </v><v> NaN </v></row>" > eau.xml
This is going to generate the XML file with the new columns blank.
Now, you have to edit the XML file to update some more fields.
So in the eau.xml file, search for each cdp_prep section.
Your section should look like:
<cdp_prep> <ds> <primary_value> 0,0000000000e+00 </primary_value> <secondary_value> 0,0000000000e+00 </secondary_value> <value> NaN </value> <unknown_datapoints> 0 </unknown_datapoints> </ds> </cdp_prep>
So simply duplicate the ds section for each value you want to add.
For me, which want to add 2 values, the result is:
<cdp_prep> <ds> <primary_value> 0,0000000000e+00 </primary_value> <secondary_value> 0,0000000000e+00 </secondary_value> <value> NaN </value> <unknown_datapoints> 0 </unknown_datapoints> </ds> <ds> <primary_value> 0,0000000000e+00 </primary_value> <secondary_value> 0,0000000000e+00 </secondary_value> <value> NaN </value> <unknown_datapoints> 0 </unknown_datapoints> </ds> <ds> <primary_value> 0,0000000000e+00 </primary_value> <secondary_value> 0,0000000000e+00 </secondary_value> <value> NaN </value> <unknown_datapoints> 0 </unknown_datapoints> </ds> </cdp_prep>
You have to do that for each cdp_prep section and not only for the first one.
Then, you "simply" have to reload those data in a new dabatase.
rrdtool restore eau.xml eau2.rrd
And voila. You have your new database with your 2 new columns.
Enjoy.
JM
rrdtool create eau2.rrd --start 1202484376 \
DS:HWH:GAUGE:288:U:U \
DS:HWL:GAUGE:288:U:U \
DS:ROOM:GAUGE:288:U:U \
RRA:AVERAGE:0.5:1:12 \
RRA:AVERAGE:0.5:1:288 \
RRA:AVERAGE:0.5:1:2016 \
RRA:AVERAGE:0.5:1:8928 \
RRA:AVERAGE:0.5:1:105408 \
RRA:AVERAGE:0.5:1:316224
<ds>
<name> HWH </name>
<type> GAUGE </type>
<minimal_heartbeat> 288 </minimal_heartbeat>
<min> NaN </min>
<max> NaN </max>
<!-- PDP Status -->
<last_ds> 55 </last_ds>
<value> 1.0130448955e+04 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
<ds>
<name> HWL </name>
<type> GAUGE </type>
<minimal_heartbeat> 288 </minimal_heartbeat>
<min> NaN </min>
<max> NaN </max>
<!-- PDP Status -->
<last_ds> 53.5 </last_ds>
<value> 9.8541639835e+03 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
<ds>
<name> ROOM </name>
<type> GAUGE </type>
<minimal_heartbeat> 288 </minimal_heartbeat>
<min> NaN </min>
<max> NaN </max>
<!-- PDP Status -->
<last_ds> -19.5 </last_ds>
<value> -3.5917046295e+03 </value>
<unknown_sec> 0 </unknown_sec>
</ds>