[rrd-users] C API for rrdtool

Fizza Hussain 12mseefhussain at seecs.edu.pk
Mon Dec 2 11:44:25 CET 2013


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 <12mseefhussain at seecs.edu.pk
> wrote:

> Thank you so much, Sir..
> I has really helped me out.
>
>
> On Fri, Nov 29, 2013 at 1:08 AM, Tony Mountifield <tony at mountifield.org>wrote:
>
>> In article <CAOcjRXnATr1Qpu8rbjBT7_fsA4XaHANaCigTLe8qk6=
>> Cr1NeYQ at mail.gmail.com>,
>> Fizza Hussain <12mseefhussain at 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: tony at softins.co.uk - http://www.softins.co.uk
>> Play: tony at mountifield.org - http://tony.mountifield.org
>>
>> _______________________________________________
>> rrd-users mailing list
>> rrd-users at lists.oetiker.ch
>> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.oetiker.ch/pipermail/rrd-users/attachments/20131202/74f40ff2/attachment.htm 


More information about the rrd-users mailing list