<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 &lt;inttypes.h&gt; // 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&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "DS:ifouto:DERIVE:120:0:U"<br>
        #define DSIFINO &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "DS:ifino:DERIVE:120:0:U"<br>
        #define DSIFINERRO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "DS:ifinerro:DERIVE:120:0:U"<br>
        #define DSIFINDISCO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; "DS:ifindisco:DERIVE:120:0:U"<br>
        #define DSIFINUNKO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; "DS:ifinunko:DERIVE:120:0:U"<br>
        #define DSIFOUTERRO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; "DS:ifouterro:DERIVE:120:0:U"<br>
        #define DSIFOUTDISCO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "DS:ifoutdisco:DERIVE:120:0:U"<br>
        #define RRA_SERIE1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
        "RRA:AVERAGE:0.5:1:21600"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
        #define RRA_SERIE2&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
        "RRA:AVERAGE:0.5:60:17856"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
        #define RRA_SERIE3&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
        "RRA:AVERAGE:0.5:1440:26784"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
        #define DS_SERIES&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
        "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>
        &nbsp;const char *argv[10] = { DSIFOUTO,
        DSIFINO,DSIFINERRO,DSIFINDISCO,DSIFINUNKO,DSIFOUTERRO,DSIFOUTDISCO,
        RRA_SERIE1,<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>
        &nbsp;rrd_clear_error();<br>
        &nbsp;int status = rrd_create_r(baserrd_name, step, timestamp_start,
        argv);<br>
        &nbsp;if (status != 0) {<br>
        &nbsp;&nbsp;&nbsp;&nbsp; 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&lt;nb_update;i++){<br>
        &nbsp;&nbsp;&nbsp; argv[i]=malloc(sizeof(char *)*MAX_LEN_RRD_ENTREE); // can be
        optimised for using less memories ...<br>
        &nbsp;&nbsp;&nbsp;&nbsp; sprintf(argv[i],
        "%li:%"PRIu64":%"PRIu64":%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu32":%"PRIu32,
        // see somewhere.h<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mydata[i].date_ts,<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        mydata[i].ifHCoutoctects,<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mydata[i].ifHCinoctects,<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mydata[i].inErr,<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mydata[i].inDiscard,<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mydata[i].inUnkProtos,<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mydata[i].outErr,<br>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 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>
        &nbsp;&nbsp; fprintf("can't write update to base [%s]:
        %s\n",base_rrd_name,rrd_get_error());<br>
        }<br>
        <br>
        for(i=0;i&lt;nb_update;i++){<br>
        &nbsp;&nbsp;&nbsp; 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,&nbsp; int argc,&nbsp; 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 &eacute;crit&nbsp;:<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">&nbsp;</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">&lt;<a moz-do-not-send="true"
                href="mailto:12mseefhussain@seecs.edu.pk"
                target="_blank">12mseefhussain@seecs.edu.pk</a>&gt;</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">&lt;<a moz-do-not-send="true"
                        href="mailto:tony@mountifield.org"
                        target="_blank">tony@mountifield.org</a>&gt;</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
                        &lt;CAOcjRXnATr1Qpu8rbjBT7_fsA4XaHANaCigTLe8qk6=<a
                          moz-do-not-send="true"
                          href="mailto:Cr1NeYQ@mail.gmail.com"
                          target="_blank">Cr1NeYQ@mail.gmail.com</a>&gt;,<br>
                        <div>Fizza Hussain &lt;<a moz-do-not-send="true"
                            href="mailto:12mseefhussain@seecs.edu.pk"
                            target="_blank">12mseefhussain@seecs.edu.pk</a>&gt;
                          wrote:<br>
                          &gt; Hi!<br>
                          &gt;<br>
                          &gt; I have written a C program which use RRD
                          C API functions rrd_create(),<br>
                          &gt; rrd_update() and rrd_dump() to create,
                          update and show the contents of the<br>
                          &gt; RRD database. I want to fill the RRD
                          database with the integers returned by<br>
                          &gt; C rand( ) function i.e. the random value
                          generated by the rand( ) function<br>
                          &gt; is stored against each timestamp.<br>
                          &gt;<br>
                          &gt; Below is my code snippet:<br>
                          &gt;<br>
                          &gt; char *updateparams[] = {<br>
                          &gt; &nbsp; &nbsp; &nbsp; &nbsp;"rrdupdate",<br>
                          &gt; &nbsp; &nbsp; &nbsp; &nbsp;"Flow1bytes.rrd",<br>
                          &gt; &nbsp; &nbsp; &nbsp; &nbsp;"???:Bytecounter[i]",<br>
                          &gt; &nbsp; &nbsp; &nbsp; &nbsp;NULL<br>
                          &gt; &nbsp; &nbsp; };<br>
                          &gt;<br>
                          &gt;<br>
                          &gt; for (i=0; i &lt; 50; i++)<br>
                          &gt; {<br>
                          &gt; flow1.bytes= rand();<br>
                          &gt; Bytecounter[i]=flow1.bytes;<br>
                          &gt; rrd_update(3,updateparams);<br>
                          &gt; }<br>
                          &gt;<br>
                          &gt; Please guide me how can I access the
                          timestamp variable and write it in the<br>
                          &gt; 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>
                          &nbsp; &nbsp; &nbsp; &nbsp; "rrdupdate",<br>
                          &nbsp; &nbsp; &nbsp; &nbsp; "Flow1bytes.rrd",<br>
                        </div>
                        &nbsp; &nbsp; &nbsp; &nbsp; buffer,<br>
                        <div>&nbsp; &nbsp; &nbsp; &nbsp; NULL<br>
                          };<br>
                          <br>
                          for (i=0; i&lt;50; i++)<br>
                          {<br>
                        </div>
                        &nbsp; &nbsp; &nbsp; &nbsp; timestamp = ...; /* get a timestamp from
                        somewhere */<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; flow1.bytes = rand();<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; Bytecounter[i] = flow1.bytes; &nbsp; /* why
                        two steps, and the storage in the array? */<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; snprintf(buffer, sizeof(buffer),
                        "%d:%d", timestamp, Bytecounter[i]);<br>
                        &nbsp; &nbsp; &nbsp; &nbsp; 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>