[rrd-users] rrd_xport C usage

Olivier AUDRY olivier.audry at colt.net
Wed Apr 7 16:19:38 CEST 2010


hello

I'm replying to myself :). My question was stupid and I solved my issue sorry
for the mess. I hope my next question will be less stupid :).

my code is working know :

void    process_rrd(llist list, char *pattern) {

        int             rrd_ret,rows,xxsize;
        char            *s,*rrd_def;
        char            **params;
        elem            *tmp;
        time_t          start, end;
        regex_t         reg;
        struct tm       *t;
        rrd_value_t     **data;
        unsigned long   col_cnt;
        unsigned long   step;


        step            = 300;
        col_cnt         = 1;
        xxsize          = 0;
        params          = malloc( 8 * sizeof(char *));
        start           = end = time(NULL) - 604800;
        end             += 1209600 ;

        t               = localtime(&start);
        tmp             = list;

        rows            = (start - end) / step;

        rrd_def         = ":pct:AVERAGE VDEF:D2=used1,LSLSLOPE VDEF:H2=used1,LSLINT CDEF:avg2=used1,POP,D2,COUNT,*,H2,+ CDEF:abc2=avg2,90,100,LIMIT XPORT:abc2:'uhuh'";

        regcomp(&reg, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE);
        while(tmp != NULL) {
                regexec(&reg,tmp->filename,0,NULL,0);
                if (!regexec(&reg,tmp->filename,0,NULL,0)) {
                        rrd_clear_error();
                        printf("Processing %s\n", tmp->filename);
                        s = calloc((strlen("DEF:used1=./rrd/") + strlen(tmp->filename) + \
                                strlen(rrd_def)),  sizeof(char));

                        data = malloc (1 * rows * sizeof (rrd_value_t));

                        strcat(s,"DEF:used1=./rrd/");
                        strcat(s,tmp->filename);
                        strcat(s,rrd_def);

                        params[0] = "xport";
                        params[1] = s;
                        params[2] = NULL;

                        rrd_ret=rrd_xport(2, params, &xxsize, &start, &end, &step, &col_cnt, NULL, data);
                        if (rrd_test_error() != 0) {
                                printf ("RRD ERROR on %s : %s\n", tmp->filename, rrd_get_error()); }
                        else { printf ("ok :%s\n",tmp->filename); }
                        free(s);
                }
                tmp = tmp->nxt;
        }
        regfree(&reg);
}

But rrd rise this error :

RRD ERROR on disk,home.rrd : Cannot parse CF in 'DEF:used1=./rrd/disk,home.rrd:pct:AVERAGE VDEF:D2=used1,LSLSLOPE VDEF:H2=used1,LSLINT CDEF:avg2=used1,POP,D2,COUNT,*,H2,+ CDEF:abc2=avg2,90,100,LIMIT XPORT:abc2:'uhuh''

Ok. But if I call rrdtool with this params, it's working ...

rrdtool xport DEF:used1=./rrd/disk,usr.rrd:pct:AVERAGE VDEF:D2=used1,LSLSLOPE VDEF:H2=used1,LSLINT CDEF:avg2=used1,POP,D2,COUNT,*,H2,+ CDEF:abc2=avg2,90,100,LIMIT XPORT:used1:'uhuh'

Any suggestion ?

thx for your help

oau

On Mon, Mar 29, 2010 at 05:13:06PM +0200, Olivier AUDRY wrote:
> hello
> 
> here is my very simple code to try to use rrd_xport. Some one can help me 
> to understand why I have a segfault on the rrd_xport call ?
> 
>         int             optind,opterr,rows,xxsize;
>         char            *s;
>         char            **params;
>         elem            *tmp;
>         time_t          start, end;
>         regex_t         reg;
>         struct tm       *t;
>         rrd_value_t     **data;
>         unsigned long   col_cnt;
>         unsigned long   step;
> 
> 
>         step            = 300;
>         col_cnt         = 1;
>         xxsize          = 0;
>         params          = malloc( 8 * sizeof(char *));
>         start           = end = time(NULL) - 604800;
>         end             += 1209600 ;
> 
>         t               = localtime(&start);
>         tmp             = list;
> 
>         rows            = (start - end) / step;
> 
>         regcomp(&reg, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE);
>         while(tmp != NULL) {
>                 regexec(&reg,tmp->filename,0,NULL,0);
>                 if (!regexec(&reg,tmp->filename,0,NULL,0)) {
>                         optind = opterr = 0;
>                         rrd_clear_error();
>                         printf("Processing %s\n", tmp->filename);
>                         s = calloc((strlen("DEF:used1=./rrd/lmwbs-ws01/") + strlen(tmp->filename) + \
>                                 strlen(":pct:AVERAGE")),  sizeof(char));
> 
>                         data = malloc (1 * rows * sizeof (rrd_value_t));
> 
>                         strcat(s,"DEF:used1=./rrd/lmwbs-ws01/");
>                         strcat(s,tmp->filename);
>                         strcat(s,":pct:AVERAGE");
> 
>                         params[0] = "xport";
>                         params[1] = s;
>                         params[2] = "VDEF:D2=used1,LSLSLOPE";
>                         params[3] = "VDEF:H2=used1,LSLINT";
>                         params[4] = "CDEF:avg2=used1,POP,D2,COUNT,*,H2,+";
>                         params[5] = "CDEF:abc2=avg2,90,100,LIMIT";
>                         params[6] = "XPORT:abc2:'uhuh'";
>                         params[7] = NULL;
> 
>                         rrd_xport(8, params, &xxsize, &start, &end, &step, &col_cnt, NULL, data);
>                         free(s);
>                 }
>                 tmp = tmp->nxt;
>         }
>         regfree(&reg);
> 
> thx for your help.
> 
> oau
> 
> _______________________________________________
> rrd-users mailing list
> rrd-users at lists.oetiker.ch
> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users



More information about the rrd-users mailing list