cedlecomte / RTG2

Realtime Traffic Grapher 2
GNU General Public License v2.0
11 stars 9 forks source link

rtgplot error in db_populate #16

Open cedlecomte opened 10 years ago

cedlecomte commented 10 years ago

From verhei...@gmail.com on July 15, 2010 05:06:22

What steps will reproduce the problem? 1. run rtgplot from the commandline 2. 3. What is the expected output? What do you see instead? rtgplot reports that no Data Points are found, but also mentions that 22 Data Points are available What version of the product are you using? On what operating system? RTG 0.9.4-18 on CentOS 5.4 (Final) Please provide any additional information below. When rtgplot is executed from the commandline, I get the following result:

RTGplot version 0.9.0. Using RTG config file [/usr/local/rtg/etc/rtg.conf].

Creating 570 by 230 image (create_graph). Initializing colors (init_colors). Drawing image grid (draw_grid). Populating (populate). Query String: SELECT counter, UNIX_TIMESTAMP(dtime) FROM data WHERE dtime>FROM_UNIXTIME(1279093116) AND dtime <=FROM_UNIXTIME(1279099716) AND id=26786 ORDER BY dtime No Data Points 22. Populating (populate). Query String: SELECT counter, dtime FROM data WHERE id=26786 ORDER BY dtime DESC LIMIT 2

Segmentation fault

rtgplot reports that No Data Points are found, but still reports a number of 22. When the query is executed on the mysql comand line it finds 22 results. So although rtgplot finds 22 results is still reports No Data Points found.

The error is reported by the ' populate' function in rtgplot. This function checks the variable 'stat', if this is 'FALSE' the No Data Points error is reported.

The 'stat' variable is set by the db_populate function in librtgmysql.c. In this function the variable stat is initialized and if the code is executed correctly stat is returned. But I cannot see where the 'stat' variable is set.

I changed the db_populate function in librtgmysql.c as follows:

int __db_populate(char _query, data_obj_t DO) { data_t new = NULL; data_t last = NULL; data_t _data = &(DO->data); int stat; MYSQL mysql = getmysql(); int res; MYSQL_RES *result; MYSQL_ROW row;

stat = 0;
res = mysql_real_query(&mysql, query, strlen(query));

if (res != 0) {
    debug(LOW, "MySQL error: &#37;s\n", mysql_error(&mysql));

// return FALSE; return stat; } else { stat = 1; result = mysql_store_result(&mysql); }

while ((row = mysql_fetch_row(result))) {
    if ((new = (data_t *) malloc(sizeof(data_t))) == NULL)
        debug(LOW, "  Fatal malloc error in populate.\n");

ifdef HAVE_STRTOLL

    new->counter = strtoll(row[0], NULL, 0);

else

    new->counter = strtol(row[0], NULL, 0);

endif

    new->timestamp = atoi(row[1]);
    new->next = NULL;
    (DO->datapoints)++;
    if (new->counter > DO->counter_max)
        DO->counter_max = new->counter;
    if (*data != NULL) {
        last->next = new;
        last = new;
    } else {
        DO->dataBegin = new->timestamp;
        *data = new;
        last = new;
    }
}

return stat;

}

on line 11 I assign '0' or 'false' to the 'stat' variable. If the mysql query fails, 'stat' which still has the value '0' is returned (line 17). If the query is succesfull 'stat' is assigned the value '1' on line 19 which is returned at the end of the function.

I now get the following output from rtgplot:

RTGplot version 0.9.0. Using RTG config file [/usr/local/rtg/etc/rtg.conf]. Loaded database driver librtgmysql.so Mysql connected, thread: 3

Creating 570 by 230 image (create_graph). Initializing colors (init_colors). Drawing image grid (draw_grid). Populating (populate). Query String: SELECT counter, UNIX_TIMESTAMP(dtime) FROM data WHERE UNIX_TIMESTAMP(dtime)>1279093116 AND UNIX_TIMESTAMP(dtime) <= 1279099716 AND id=26786 ORDER BY dtime 22 Data Points Calc rate (calculate_rate). [row0=1920][row1=1279093715][elapsed secs=300][rate=6.400 bps] [row0=1920][row1=1279094016][elapsed secs=301][rate=6.379 bps] [row0=1920][row1=1279094316][elapsed secs=300][rate=6.400 bps] [row0=1920][row1=1279094616][elapsed secs=300][rate=6.400 bps] [row0=1920][row1=1279094916][elapsed secs=300][rate=6.400 bps] [row0=1920][row1=1279095216][elapsed secs=300][rate=6.400 bps] [row0=1920][row1=1279095516][elapsed secs=300][rate=6.400 bps] [row0=1920][row1=1279095816][elapsed secs=300][rate=6.400 bps] [row0=1920][row1=1279096115][elapsed secs=299][rate=6.421 bps] [row0=1984][row1=1279096415][elapsed secs=300][rate=6.613 bps] [row0=1920][row1=1279096716][elapsed secs=301][rate=6.379 bps] [row0=1920][row1=1279097015][elapsed secs=299][rate=6.421 bps] [row0=1856][row1=1279097315][elapsed secs=300][rate=6.187 bps] [row0=1984][row1=1279097615][elapsed secs=300][rate=6.613 bps] [row0=1792][row1=1279097915][elapsed secs=300][rate=5.973 bps] [row0=1920][row1=1279098215][elapsed secs=300][rate=6.400 bps] [row0=1920][row1=1279098516][elapsed secs=301][rate=6.379 bps] [row0=1920][row1=1279098815][elapsed secs=299][rate=6.421 bps] [row0=1920][row1=1279099116][elapsed secs=301][rate=6.379 bps] [row0=1920][row1=1279099416][elapsed secs=300][rate=6.400 bps] [row0=1920][row1=1279099716][elapsed secs=300][rate=6.400 bps] Normalize (normalize). X-Max = 6600 Y-Max = 6.944 X-units = 86400 Y-units = 1 XPixels/Sec = 0.075758 YPixels/Bit = 21.6013832092 Timeoffset = 1279093116 TS=1279093415 T=299 X=23 R=6.400 RN=6.40000 Y=138 F=1 TS=1279093715 T=599 X=45 R=6.400 RN=6.40000 Y=138 F=1 TS=1279094016 T=900 X=68 R=6.379 RN=6.37874 Y=138 F=1 TS=1279094316 T=1200 X=91 R=6.400 RN=6.40000 Y=138 F=1 TS=1279094616 T=1500 X=114 R=6.400 RN=6.40000 Y=138 F=1 TS=1279094916 T=1800 X=136 R=6.400 RN=6.40000 Y=138 F=1 TS=1279095216 T=2100 X=159 R=6.400 RN=6.40000 Y=138 F=1 TS=1279095516 T=2400 X=182 R=6.400 RN=6.40000 Y=138 F=1 TS=1279095816 T=2700 X=205 R=6.400 RN=6.40000 Y=138 F=1 TS=1279096115 T=2999 X=227 R=6.421 RN=6.42140 Y=139 F=1 TS=1279096415 T=3299 X=250 R=6.613 RN=6.61333 Y=143 F=1 TS=1279096716 T=3600 X=273 R=6.379 RN=6.37874 Y=138 F=1 TS=1279097015 T=3899 X=295 R=6.421 RN=6.42140 Y=139 F=1 TS=1279097315 T=4199 X=318 R=6.187 RN=6.18667 Y=134 F=1 TS=1279097615 T=4499 X=341 R=6.613 RN=6.61333 Y=143 F=1 TS=1279097915 T=4799 X=364 R=5.973 RN=5.97333 Y=129 F=1 TS=1279098215 T=5099 X=386 R=6.400 RN=6.40000 Y=138 F=1 TS=1279098516 T=5400 X=409 R=6.379 RN=6.37874 Y=138 F=1 TS=1279098815 T=5699 X=432 R=6.421 RN=6.42140 Y=139 F=1 TS=1279099116 T=6000 X=455 R=6.379 RN=6.37874 Y=138 F=1 TS=1279099416 T=6300 X=477 R=6.400 RN=6.40000 Y=138 F=1 TS=1279099716 T=6600 X=500 R=6.400 RN=6.40000 Y=138 F=1 Plotting legend (plot_legend). Plotting line. Sk...

Original issue: http://code.google.com/p/rtg2/issues/detail?id=16

cedlecomte commented 10 years ago

From verhei...@gmail.com on July 15, 2010 04:27:05

Correction:

'stat = 1;' should be set later in the function:

int __db_populate(char _query, data_obj_t DO) { data_t new = NULL; data_t last = NULL; data_t _data = &(DO->data); int stat; MYSQL mysql = getmysql(); int res; MYSQL_RES *result; MYSQL_ROW row;

stat = 0;
res = mysql_real_query(&mysql, query, strlen(query));

if (res != 0) {
    debug(LOW, "MySQL error: %s\n", mysql_error(&mysql));

// return FALSE; return stat; } else { result = mysql_store_result(&mysql); }

while ((row = mysql_fetch_row(result))) {
    if ((new = (data_t *) malloc(sizeof(data_t))) == NULL)
        debug(LOW, "  Fatal malloc error in populate.\n");

    stat = 1;

ifdef HAVE_STRTOLL

    new->counter = strtoll(row[0], NULL, 0);

else

    new->counter = strtol(row[0], NULL, 0);

endif

    new->timestamp = atoi(row[1]);
    new->next = NULL;
    (DO->datapoints)++;
    if (new->counter > DO->counter_max)
        DO->counter_max = new->counter;
    if (*data != NULL) {
        last->next = new;
        last = new;
    } else {
        DO->dataBegin = new->timestamp;
        *data = new;
        last = new;
    }
}
return stat;

}

cedlecomte commented 10 years ago

From verhei...@gmail.com on September 21, 2010 07:06:39

I am currently using rtgplot via cgi and am not experiencing this problem.