1

Can anybody help me to find out how to call rrd_update_r function of the rrdtool c API from http://oss.oetiker.ch/rrdtool/index.en.html?

It was quite easy to call the non-threadsafe version of rrd_update, but this one is more tricky...

normal rrd_update:

  char *updateparams[] = {
        "rrdupdate",
        rrd_file,
        values,
        NULL
    };

    rrd_clear_error();
    result = rrd_update(3, updateparams); //argc is first arg

Because the programm has to run in a multithreaded environment I got several errors by not using the threadsafe functions! But it is not so easy to use rrd_update_r, because it requires a template too...

 int    rrd_update_r(const char *filename, const char *_template,
            int argc, const char **argv);

and I really have no idea how to create one...

    char *updateparams[] = {
        "rrdupdate",
        rrd_file,
        values,
        NULL
    };


    rrd_clear_error();
   result = rrd_update_r(rrd_file, NULL,3, updateparams);

does not work and produces the following error when executing it...

error: /var/tmp/rrds/1.rrd: expected timestamp not found in data source from rrdupdate

Hopefully someone can help me!

thx and br, roegi

roegi
  • 183
  • 1
  • 16
  • I guess you took a look at http://oss.oetiker.ch/rrdtool/prog/rrdthreads.en.html ? Unfortunately, it doesn't mention `rrd_update_r`. – evnu Jul 13 '11 at 17:07
  • Yes I took a look at rrdthreads.en.html, but rrd_update_r is mentioned there as a reference implementation to look at( "See rrd_update_r as an example"). – roegi Jul 13 '11 at 17:22

2 Answers2

1

Well, looking at the source code...

It appears that rrd_update_r does not want to see the "rrupdate" argument. So try just passing rrd_file and values as a 2-element argv.

Actually the source for rrd_update is not hard to read; you can find it in src/rrd_update.c. And rrd_update_r appears to be a much lower-level function that rrd_update itself calls. So this may not actually fix your underlying problem.

Nemo
  • 70,042
  • 10
  • 116
  • 153
  • So you mean just to use a char * updateparams[] = { rrd_file, values, NULL }; as 4th argument? Additionally a template seems to be required here as 2nd arg, but I have no clue what that should be and how to create it... On the rrdtool website there is always mentioned that _r functions are the threadsafe ones and that rrd_update is already implemted in rrd_update_r in a threadsafe way - so hopefully it was really done... – roegi Jul 13 '11 at 17:26
  • 1
    @roegi: As far as I can tell, the `template` parameter can be NULL. (Indeed, this is how `rrd_update` invokes `rrd_update_r` when the argv contains no `--template` argument.) – Nemo Jul 13 '11 at 17:42
  • ok that sounds great! I will try to execute it tomorrow morning again with rrd_update_r(rrd_file, NULL,2, updateparams); and char * updateparams[] = { rrd_file, values, NULL }; I think that the same error("expected timestamp not found in data source from rrdupdate") will occur - but hopefully you are right! – roegi Jul 13 '11 at 17:47
0

Now it is working! Nemo - thx for your help! It was not exactly your solution but it was a hint to the right direction!

It works with:

/*
rrd_file is a char * to "/var/tmp/1.rrd"
NULL says not to use a template
1 --> argc 
values is a char * to "N:value-1:value-2:.....:value-n"
*/

result = rrd_update_r(rrd_file, NULL, 1, (void *) &values); 
roegi
  • 183
  • 1
  • 16
  • the queue_thread_main function in this example uses rrd_update_r http://oss.oetiker.ch/rrdtool-trac/browser/trunk/program/src/rrd_daemon.c – roegi Jul 14 '11 at 10:57