On Wed, Sep 07, 2005 at 11:26:44AM -0700, Steve wrote:
Hi Steve.
> Hi,
>  
> Is there any documentation of the rrdtool-API?
Uhhh... I think there is no documentation  available.
But for the non-threaded functions I have some knowledge
in /dev/brain :)

> I would like to update RRD from a C program.
Thats really easy ...

The update function is declared as:

int rrd_update(int rrd_argc, char **rrd_argv);

Similar to the usual main-Function inside a normal program
int is the number of arguments (ala argc) and char ** (ala argv)
is a an array of char * .

The array rrd_argv contains rrd_argc elements (from 0..rrd_argc-1)
and the element rrd_argv[rrd_argc] _MUST_ be NULL.

The function does not care about rrd_argv[0] so it can be anything
(but not NULL). I recommend that you put the name of the function
("update" in this case) that uses this array in this field.

There is no difference calling the update function from command line
(via rrdtool update ... ) or from a C program. The parameters for
this routine are the same as described in the manual page for rrdupdate.

So lets assume I want to update the file test.rrd (located in my $HOME)
with the value N:1:1:1 (it holds three DS). All I have to do is to
construct the array rrd_argv and set rrd_argc. 

The commandline from a shell would look like:

[EMAIL PROTECTED] ~ # rrdtool update /home/maus/test.rrd N:1:1:1

and so the corresponding structures in the API-Call will:

rrd_argv[0]=update
rrd_argv[1]=/home/maus/test.rrd
rrd_argv[2]=N:1:1:1
rrd_argv[3]=NULL

rrd_argc=3

Then call:

int rrd_ret=rrd_update(rrd_argc,rrd_argv);

rrd_ret is 0 on success

It is a good advice to call rrd_clear_error() before you call rrd_update to
possible errors. You can also test for errors using the function 
rrd_test_error()
-a return value of 0 means no error. A string describing the error can be 
obtained
by calling rrd_get_error().

PITFALLS AND COMMON PROBLEMS:

A lot of obscure problems arise if you forget about the variables optind and 
opterr.
These variables are declared in the getopt headerfile (used for parsing the 
options)
as _global_ ! So you have to set these variables back to 0 _before_ you call any
rrd_* function in your program.

Final code snippet:

So finally your update of a rrd-database from your C program would look like:

[... snipp ...]

/* Code that fills rrd_argv and sets rrd_argc to the correct values */
optind=0;opterr=0;
rrd_clear_error();
rrd_ret=rrd_update(rrd_argc,rrd_argv);

if (rrd_test_error()!=0)
{
  /* Handle error condition */

}

[... snipp ...]

Easy, isn't it?

Hope that helps.

Andreas.

P.S.: Same procedure applies to 
rrd_create,rrd_restore,rrd_dump,rrd_tune,rrd_last and rrd_resize

-- 
Dipl.-Ing. Andreas Maus             science+computing ag
System Administration               Hagellocher Weg 71-75
mail: [EMAIL PROTECTED]   72070 Tuebingen, Germany
tel.: +49 7071 9457 456             www.science-computing.de

-- Binary/unsupported file stripped by Ecartis --
-- Err : No filename to use for decode, file stripped.
-- Type: application/pgp-signature


--
Unsubscribe mailto:[EMAIL PROTECTED]
Help        mailto:[EMAIL PROTECTED]
Archive     http://lists.ee.ethz.ch/rrd-users
WebAdmin    http://lists.ee.ethz.ch/lsg2.cgi

Reply via email to