<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Hello,<br>
<br>
Some Pieces of code, i use in C projet, they may can help you :<br>
<br>
<u>Creation :</u><br>
<br>
<span id="ctl00_cC_ucResEM_rE_ctl00_lblTarget"
class="ellipsis_text" direction="target"
keywords="quelque,part,quelque part" lang="1033">somewhere </span>in
a header :<br>
<br>
<u><span id="ctl00_cC_ucResEM_rE_ctl00_lblTarget"
class="ellipsis_text" direction="target"
keywords="quelque,part,quelque part" lang="1033">somewhere</span>.h</u>
:<br>
<br>
<font face="Courier New">#include [...]<br>
#include <inttypes.h> // this portable representation
doesn't </font><font face="Courier New"><font face="Courier
New">depend of</font> architecture<br>
<br>
#define MAX_LEN_RRD_ENTREE 128 // it's can be more or less,
depend of number of DS in your rra<br>
<br>
#define DSIFOUTO "DS:ifouto:DERIVE:120:0:U"<br>
#define DSIFINO "DS:ifino:DERIVE:120:0:U"<br>
#define DSIFINERRO "DS:ifinerro:DERIVE:120:0:U"<br>
#define DSIFINDISCO "DS:ifindisco:DERIVE:120:0:U"<br>
#define DSIFINUNKO "DS:ifinunko:DERIVE:120:0:U"<br>
#define DSIFOUTERRO "DS:ifouterro:DERIVE:120:0:U"<br>
#define DSIFOUTDISCO "DS:ifoutdisco:DERIVE:120:0:U"<br>
#define RRA_SERIE1
"RRA:AVERAGE:0.5:1:21600" <br>
#define RRA_SERIE2
"RRA:AVERAGE:0.5:60:17856" <br>
#define RRA_SERIE3
"RRA:AVERAGE:0.5:1440:26784" <br>
#define DS_SERIES
"ifouto:ifino:ifinerro:ifindisco:ifinunko:ifouterro:ifoutdisco"<br>
<br>
/** prototypes **/<br>
[...]</font><br>
<br>
<span id="ctl00_cC_ucResEM_rE_ctl00_lblTarget"
class="ellipsis_text" direction="target"
keywords="quelque,part,quelque part" lang="1033">somewhere </span>in
a source file :<br>
<br>
<u><span id="ctl00_cC_ucResEM_rE_ctl00_lblTarget"
class="ellipsis_text" direction="target"
keywords="quelque,part,quelque part" lang="1033">somewhere</span>.c
:</u><br>
<font face="Courier New">#include "path/to/<span
id="ctl00_cC_ucResEM_rE_ctl00_lblTarget" class="ellipsis_text"
direction="target" keywords="quelque,part,quelque part"
lang="1033">somewhere</span>.h"<br>
<br>
char *base_name_rrd = "pathtomyfile.rra";<br>
const char *argv[10] = { DSIFOUTO,
DSIFINO,DSIFINERRO,DSIFINDISCO,DSIFINUNKO,DSIFOUTERRO,DSIFOUTDISCO,
RRA_SERIE1,<br>
RRA_SERIE2,
RRA_SERIE3 };<br>
<br>
// For more dynamic creation you can use sprintf function with
pattern like this : "RRA:%s:%f:%i:%i:%i"<br>
// const char ** argv = (const char **) malloc(sizeof(char *) *
(nb_rra+ nd_ds));<br>
// and affect DS value from argv[0] to argv[(nb_rra+ nd_ds)-1]<br>
<br>
<br>
rrd_clear_error();<br>
int status = rrd_create_r(baserrd_name, step, timestamp_start,
argv);<br>
if (status != 0) {<br>
fprintf(stderr,"Can't create base [%s] :
%s\n",base_name_rrd,rrd_get_error());<br>
}<br>
// if dynamic free argv after creation (and others dynamics
allocate string ):<br>
// free(argv);</font><br>
<br>
<u>update :</u><br>
<br>
<span id="ctl00_cC_ucResEM_rE_ctl00_lblTarget"
class="ellipsis_text" direction="target"
keywords="quelque,part,quelque part" lang="1033">somewhere </span>in
a source file :<br>
<br>
<u><span id="ctl00_cC_ucResEM_rE_ctl00_lblTarget"
class="ellipsis_text" direction="target"
keywords="quelque,part,quelque part" lang="1033">somewhere2</span>.c
:</u><br>
<font face="Courier New">#include "path/to/<span
id="ctl00_cC_ucResEM_rE_ctl00_lblTarget" class="ellipsis_text"
direction="target" keywords="quelque,part,quelque part"
lang="1033">somewhere</span>.h"<br>
<br>
char ligne[MAX_LEN_RRD_ENTREE];<br>
const char ** argv = (const char **) malloc(sizeof(char *) *
(nb_update));<br>
int i = 0;<br>
for(;i<nb_update;i++){<br>
argv[i]=malloc(sizeof(char *)*MAX_LEN_RRD_ENTREE); // can be
optimised for using less memories ...<br>
sprintf(argv[i],
"%li:%"PRIu64":%"PRIu64":%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu32,
// see somewhere.h<br>
mydata[i].date_ts,<br>
mydata[i].ifHCoutoctects,<br>
mydata[i].ifHCinoctects,<br>
mydata[i].inErr,<br>
mydata[i].inDiscard,<br>
mydata[i].inUnkProtos,<br>
mydata[i].outErr,<br>
mydata[i].outDiscard);
// mydata is struct with collected data, it depend of what you
need to graph.<br>
}<br>
int status = rrd_update_r(base_rrd_name, DS_SERIES, 1, argv);<br>
if (status != 0) {<br>
fprintf("can't write update to base [%s]:
%s\n",base_rrd_name,rrd_get_error());<br>
}<br>
<br>
for(i=0;i<nb_update;i++){<br>
free(argv[i]);<br>
}<br>
free(argv);</font><br>
<br>
List of functions prototypes I use :<br>
<font face="Courier New"><br>
int rrd_create_r(const char *filename, unsigned long pdp_step,
time_t last_up, int argc, const char **argv);<br>
rrd_info_t *rrd_info_r(char * filename);<br>
int rrd_update_r(const char *filename,const char *_template,int
argc,const char **argv);<br>
int rrd_fetch_r (const char *filename,const char *cf,time_t
*start,time_t *end,unsigned long *step,unsigned long
*ds_cnt,char ***ds_namv,rrd_value_t **data);<br>
int rrd_dump_r(const char *filename,char *outname);<br>
time_t rrd_last_r (const char *filename);<br>
int rrd_lastupdate_r (const char *filename,time_t
*ret_last_update,unsigned long *ret_ds_count,char
***ret_ds_names,char ***ret_last_ds);<br>
time_t rrd_first_r(const char *filename,int rraindex);<br>
rrd_info_t *rrd_graph_v(int argc, char **argv)<br>
</font><br>
Dears,<br>
<br>
Yannick<br>
<br>
<br>
Le 02/12/2013 11:44, Fizza Hussain a écrit :<br>
</div>
<blockquote
cite="mid:CAOcjRXmEYaD3CWJhiKf6W6nzzAVYxno8wZSaP55Yk2OABQOd2Q@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
<div>Hi,<br>
<br>
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:<br>
<br>
<span style="font-family:courier new,monospace">int rrd_fetch(
int, char **,time_t *,time_t *,unsigned long *,unsigned long
*,char ***, rrd_value_t **);<br>
<br>
int rrd_graph(int,char **,char ***,int *,int *,FILE *,double
*,double *);<br>
<br>
</span></div>
<div><span style="font-family:courier new,monospace"><font
face="arial,helvetica,sans-serif">From what I know is that
the first two arguments are the number of arguments and
the array of char* arguments respectively.<br>
</font></span></div>
<div><span style="font-family:courier new,monospace"><font
face="arial,helvetica,sans-serif">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?<br>
<br>
<br>
<br>
</font></span></div>
<div><span style="font-family:courier new,monospace"><font
face="arial,helvetica,sans-serif">Thank you.<br>
</font></span></div>
<div><span style="font-family:courier new,monospace"><br>
<br>
</span></div>
<div><span style="font-family:courier new,monospace"> </span></div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Fri, Nov 29, 2013 at 12:28 PM,
Fizza Hussain <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:12mseefhussain@seecs.edu.pk"
target="_blank">12mseefhussain@seecs.edu.pk</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div>Thank you so much, Sir..<br>
</div>
I has really helped me out.<br>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">
<div>On Fri, Nov 29, 2013 at 1:08 AM, Tony Mountifield
<span dir="ltr"><<a moz-do-not-send="true"
href="mailto:tony@mountifield.org"
target="_blank">tony@mountifield.org</a>></span>
wrote:<br>
</div>
<div>
<div>
<blockquote class="gmail_quote" style="margin:0 0
0 .8ex;border-left:1px #ccc
solid;padding-left:1ex">In article
<CAOcjRXnATr1Qpu8rbjBT7_fsA4XaHANaCigTLe8qk6=<a
moz-do-not-send="true"
href="mailto:Cr1NeYQ@mail.gmail.com"
target="_blank">Cr1NeYQ@mail.gmail.com</a>>,<br>
<div>Fizza Hussain <<a moz-do-not-send="true"
href="mailto:12mseefhussain@seecs.edu.pk"
target="_blank">12mseefhussain@seecs.edu.pk</a>>
wrote:<br>
> Hi!<br>
><br>
> I have written a C program which use RRD
C API functions rrd_create(),<br>
> rrd_update() and rrd_dump() to create,
update and show the contents of the<br>
> RRD database. I want to fill the RRD
database with the integers returned by<br>
> C rand( ) function i.e. the random value
generated by the rand( ) function<br>
> is stored against each timestamp.<br>
><br>
> Below is my code snippet:<br>
><br>
> char *updateparams[] = {<br>
> "rrdupdate",<br>
> "Flow1bytes.rrd",<br>
> "???:Bytecounter[i]",<br>
> NULL<br>
> };<br>
><br>
><br>
> for (i=0; i < 50; i++)<br>
> {<br>
> flow1.bytes= rand();<br>
> Bytecounter[i]=flow1.bytes;<br>
> rrd_update(3,updateparams);<br>
> }<br>
><br>
> Please guide me how can I access the
timestamp variable and write it in the<br>
> update parameter at the place marked by
???.<br>
<br>
</div>
You need to have a buffer that you update. In
your example above,<br>
"???:Bytecounter[i]" is just a string, not a
reference to the Bytecounter<br>
array. Try this:<br>
<br>
char buffer[32];<br>
<div><br>
char *updateparams[] = {<br>
"rrdupdate",<br>
"Flow1bytes.rrd",<br>
</div>
buffer,<br>
<div> NULL<br>
};<br>
<br>
for (i=0; i<50; i++)<br>
{<br>
</div>
timestamp = ...; /* get a timestamp from
somewhere */<br>
flow1.bytes = rand();<br>
Bytecounter[i] = flow1.bytes; /* why
two steps, and the storage in the array? */<br>
snprintf(buffer, sizeof(buffer),
"%d:%d", timestamp, Bytecounter[i]);<br>
rrd_update(3,updateparams);<br>
}<br>
<br>
I realize that this is just a test example, but
you should be aware that RRD<br>
will not allow you to write multiple values to
the same timestamp (even if that<br>
timestamp is N). For testing, you could
initialise timestamp outside the loop<br>
and increment it within the loop.<br>
<br>
Hope this is enough to get you started. It's
really basic C programming, not RRD-specific.<br>
<br>
Cheers<br>
<span><font color="#888888">Tony<br>
--<br>
Tony Mountifield<br>
Work: <a moz-do-not-send="true"
href="mailto:tony@softins.co.uk"
target="_blank">tony@softins.co.uk</a> - <a
moz-do-not-send="true"
href="http://www.softins.co.uk"
target="_blank">http://www.softins.co.uk</a><br>
Play: <a moz-do-not-send="true"
href="mailto:tony@mountifield.org"
target="_blank">tony@mountifield.org</a> -
<a moz-do-not-send="true"
href="http://tony.mountifield.org"
target="_blank">http://tony.mountifield.org</a><br>
</font></span>
<div>
<div><br>
_______________________________________________<br>
rrd-users mailing list<br>
<a moz-do-not-send="true"
href="mailto:rrd-users@lists.oetiker.ch"
target="_blank">rrd-users@lists.oetiker.ch</a><br>
<a moz-do-not-send="true"
href="https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users"
target="_blank">https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users</a><br>
</div>
</div>
</blockquote>
</div>
</div>
</div>
<br>
</div>
</blockquote>
</div>
<br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
rrd-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rrd-users@lists.oetiker.ch">rrd-users@lists.oetiker.ch</a>
<a class="moz-txt-link-freetext" href="https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users">https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users</a>
</pre>
</blockquote>
<br>
</body>
</html>