Configuring the Serial port for the Javelin Terminal »

Adding a column to an existing RRD database...

23/04/09 | par jmspaggi [mail] | Catégories: Non catégorisé

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




Permalink

6 commentaires

Commentaire de: ilConsigliere [Visiteur]
ilConsigliereIt works, but I think you have forgotten to define the new column beforse the rra tag
28/12/09 @ 06:06
Commentaire de: jmspaggi [Membre] Email
You're right!

Thanks for highlighting that.

It should have been done by something like that first:


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



to create the eau2.rd, then editing the file by adding <ds> tag. Your dump file should already contain something like:


<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>


so you should add that 2 times with the new fields name.


<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>



JM

07/01/10 @ 16:50
Commentaire de: Marcus [Visiteur]
Marcus#!/usr/bin/perl

use strict;
use warnings;

use RRD::Simple();

my $rrd_file = "./orig.rrd";
my $rrd = RRD::Simple->new();

print "Processing $rrd_file...";
$rrd->add_source($rrd_file, 'APACHE2' => 'GAUGE');
print " ok.\n";
13/02/11 @ 19:40
Commentaire de: Jean-Marc [Visiteur]
Jean-MarcWow! I haven't try that, but sound way easier!

Thanks for sharing. If anyone can test and provide a feedback, it's welcome.

JM
15/02/11 @ 15:36
Commentaire de: marta [Visiteur]
martathanks!! it works fine :)
29/06/11 @ 04:12
Commentaire de: Santiago [Visiteur]
SantiagoThanks! This article helped me a lot!!!
06/10/11 @ 17:23
March 2024
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
          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            

Statistiques

Free counter and web stats

Search

XML Feeds

blog software