In article <CAOcjRXnATr1Qpu8rbjBT7_fsA4XaHANaCigTLe8qk6=cr1n...@mail.gmail.com>,
Fizza Hussain <12mseefhuss...@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: t...@softins.co.uk - http://www.softins.co.uk
Play: t...@mountifield.org - http://tony.mountifield.org

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

Reply via email to