Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[rrd-users] C API for rrdtool

1,015 views
Skip to first unread message

Fizza Hussain

unread,
Nov 27, 2013, 6:12:18 AM11/27/13
to
Hi,

I want to create and update the RRD database from a C code. For that purpose, I have included rrd.h file in my source code and have linked the C code against librrd library. These two steps are done perfectly. However, I am facing some difficulties in figuring out what arguments should I provide to the functions provided by C API? For example, rrd_create( ) function takes an int and a char string as its arguments. i.e. {int rrd_create(int , char **)}.


I have previously used rrdtool via CLI and am comfortable with its CLI commands rrdtool create test.rrd --start 90234 (and so on). Please guide me what should be the arguments to the rrd_create( ) function provided by C API.



Thanks,

Fizza Hussain

Chris Malton

unread,
Nov 27, 2013, 6:45:56 AM11/27/13
to
Hi Fizza,

On Wed, 27 Nov 2013 16:12:18 +0500, Fizza Hussain wrote:
> For example,
> rrd_create( ) function takes an int and a char string as its
> arguments. i.e. {int rrd_create(int , char **)}.

The full function signature is: int rrd_create(int argc, char **argv)

argc = Count of arguments
argv = Array of char* arguments

> I have previously used rrdtool via CLI and am comfortable with its
> CLI
> commands rrdtool create test.rrd --start 90234 (and so on). Please
> guide me what should be the arguments to the rrd_create( ) function
> provided by C API.

Simply pass the command line as you would to rrdtool, to the rrd_X
functions (if I remember rightly, you need to pass the "create",
"update" etc as well).

Hope that helps.

Regards,

Chris

_______________________________________________
rrd-users mailing list
rrd-...@lists.oetiker.ch
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users

Petteri Matilainen

unread,
Nov 27, 2013, 2:43:15 PM11/27/13
to
On 27.11.2013 13:12, Fizza Hussain wrote:
> Hi,
>
> I want to create and update the RRD database from a C code. For that
> purpose, I have included rrd.h file in my source code and have linked
> the C code against librrd library. These two steps are done perfectly.
> However, I am facing some difficulties in figuring out what arguments
> should I provide to the functions provided by C API? For example,
> rrd_create( ) function takes an int and a char string as its arguments.
> i.e. {int rrd_create(int , char **)}.
>
>
> I have previously used rrdtool via CLI and am comfortable with its CLI
> commands rrdtool create test.rrd --start 90234 (and so on). Please guide
> me what should be the arguments to the rrd_create( ) function provided
> by C API.
>
>
>
> Thanks,
>
> Fizza Hussain
>
>
> _______________________________________________
> rrd-users mailing list
> rrd-...@lists.oetiker.ch
> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
>

Hi Fizza,

The create function takes only 2 arguments: the count and the array of
pointers to the arguments. Among the first links in google I found this
example: http://permalink.gmane.org/gmane.comp.db.rrdtool.devel/894
There's an example on how to use the create function and many others.
Note that the examples are for an older version of rrdtool so you may
have to modify the code.

regards,

Pete

Fizza Hussain

unread,
Nov 28, 2013, 4:57:53 AM11/28/13
to
Hi!

I have written a C program which use RRD C API functions rrd_create(), rrd_update() and rrd_dump() to create, update and show the contents of the RRD database
. I want to fill the RRD database with the integers returned by C rand( ) function i.e. the random value generated by the rand( ) function is stored
against each timestamp.

Below is my code snippet:

char *updateparams[] = {
       "rrdupdate",
       "Flow1bytes.rrd",
       "???:Bytecounter[i]",
       NULL
    };


for (i=0; i < 50; i++)
{          
flow1.bytes= rand();
Bytecounter[i]=flow1.bytes;
rrd_update(3,updateparams);
}

Please guide me how can I access the timestamp variable and write it in the update parameter at the place marked by ???.

The code for creating the Flow1bytes.rrd database is this:

char *createparams[] = {
       "rrdcreate",
       "Flow1bytes.rrd",
       "--step=1",
       "DS:Bytecounter:COUNTER:1000:0:800",
       "RRA:AVERAGE:0.5:1:50",
       NULL
    };

rrd_create(5, createparams);


Thank you.



On Thu, Nov 28, 2013 at 11:01 AM, Fizza Hussain <12mseef...@seecs.edu.pk> wrote:
Thank you so much Petteri for your help..

I am definitely going to try this out..

Fizza Hussain

unread,
Nov 28, 2013, 8:55:03 AM11/28/13
to
I have found this information in a tutorial that 'N' is Now i.e. the current time. I think It can be used as the current timestamp variable (denoted by ??? in the code snippet).

I have now used that N in my code:

char *updateparams[] = {
       "rrdupdate",
       "Flow1bytes.rrd",
       "N:Bytecounter[i]",
       NULL
    };

However, the RRD database Flow1bytes.rrd is still not updated. All the values against each timestamp are are Unknown i.e. -nan.

1385646821: -nan
1385646822: -nan
1385646823: -nan
1385646824: -nan
1385646825: -nan
1385646826: -nan
1385646827: -nan
1385646828: -nan
1385646829: -nan

and so on...


Please suggest what is going wrong?

Tony Mountifield

unread,
Nov 28, 2013, 3:08:56 PM11/28/13
to
In article <CAOcjRXnATr1Qpu8rbjBT7_fsA4XaHANaCigTLe8qk6=Cr1...@mail.gmail.com>,
Fizza Hussain <12mseef...@seecs.edu.pk> wrote:
> Hi!
>
> I have written a C program which use RRD C API functions rrd_create(),
> rrd_update() and rrd_dump() to create, update and show the contents of the
> RRD database. I want to fill the RRD database with the integers returned by
> C rand( ) function i.e. the random value generated by the rand( ) function
> is stored against each timestamp.
>
> Below is my code snippet:
>
> char *updateparams[] = {
> "rrdupdate",
> "Flow1bytes.rrd",
> "???:Bytecounter[i]",
> NULL
> };
>
>
> for (i=0; i < 50; i++)
> {
> flow1.bytes= rand();
> Bytecounter[i]=flow1.bytes;
> rrd_update(3,updateparams);
> }
>
> Please guide me how can I access the timestamp variable and write it in the
> update parameter at the place marked by ???.

You need to have a buffer that you update. In your example above,
"???:Bytecounter[i]" is just a string, not a reference to the Bytecounter
array. Try this:

char buffer[32];

char *updateparams[] = {
"rrdupdate",
"Flow1bytes.rrd",
buffer,
NULL
};

for (i=0; i<50; i++)
{
timestamp = ...; /* get a timestamp from somewhere */
flow1.bytes = rand();
Bytecounter[i] = flow1.bytes; /* why two steps, and the storage in the array? */
snprintf(buffer, sizeof(buffer), "%d:%d", timestamp, Bytecounter[i]);
rrd_update(3,updateparams);
}

I realize that this is just a test example, but you should be aware that RRD
will not allow you to write multiple values to the same timestamp (even if that
timestamp is N). For testing, you could initialise timestamp outside the loop
and increment it within the loop.

Hope this is enough to get you started. It's really basic C programming, not RRD-specific.

Cheers
Tony
--
Tony Mountifield
Work: to...@softins.co.uk - http://www.softins.co.uk
Play: to...@mountifield.org - http://tony.mountifield.org

Fizza Hussain

unread,
Dec 2, 2013, 5:44:25 AM12/2/13
to

Hi,

The C API functions rrd_fetch ( ) and rrd_graph( ) both take 8 arguments, as per their declaration in the rrd.h file. This is how they are declared in rrd.h file:

int rrd_fetch( int, char **,time_t *,time_t *,unsigned long *,unsigned long *,char ***, rrd_value_t **);

int rrd_graph(int,char **,char ***,int *,int *,FILE *,double *,double *);

From what I know is that the first two arguments are the number of arguments and the array of char* arguments respectively.
What are the rest of the arguments for? I mean what should I pass in those arguments in order to use the function from a C code?



Thank you.


 


On Fri, Nov 29, 2013 at 12:28 PM, Fizza Hussain <12mseef...@seecs.edu.pk> wrote:
Thank you so much, Sir..
I has really helped me out.
0 new messages