X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_fetch_libdbi.c;h=71a6bcac8eb7e89e6370e9ae9fefe620e2aa9064;hb=e99b152422682f6bf2b501c75f32d4584a60249c;hp=7ca809e34f613193ddc04ae97abaaccdaaf84c42;hpb=46a2db0465372eae273b1ff827e465a779339198;p=rrdtool.git diff --git a/src/rrd_fetch_libdbi.c b/src/rrd_fetch_libdbi.c index 7ca809e..71a6bca 100644 --- a/src/rrd_fetch_libdbi.c +++ b/src/rrd_fetch_libdbi.c @@ -389,6 +389,7 @@ rrd_fetch_fn_libdbi( unsigned long minstepsize=300; /* by default assume unixtimestamp */ int isunixtime=1; + long gmt_offset=0; /* the result-set */ long r_timestamp,l_timestamp,d_timestamp; double r_value,l_value,d_value; @@ -401,6 +402,7 @@ rrd_fetch_fn_libdbi( char where[10240]; table_help.conn=NULL; table_help.where=where; + table_help.filename=filename; /* some loop variables */ int i=0; @@ -458,7 +460,13 @@ rrd_fetch_fn_libdbi( return -1; } /* if we have leading '*', then we have a TIMEDATE Field*/ - if (table_help.timestamp[0]=='*') { isunixtime=0; table_help.timestamp++; } + if (table_help.timestamp[0]=='*') { + struct tm tm; + time_t t=time(NULL); + localtime_r(&t,&tm); + gmt_offset=tm.tm_gmtoff; + isunixtime=0; table_help.timestamp++; + } /* hex-unescape the value */ if(_inline_unescape(table_help.timestamp)) { return -1; } @@ -564,7 +572,7 @@ rrd_fetch_fn_libdbi( } /* allocate memory for resultset (with the following columns: min,avg,max,count,sigma) */ - i=rows * sizeof(rrd_value_t)*(*ds_cnt); + i=(rows+1) * sizeof(rrd_value_t)*(*ds_cnt); if (((*data) = malloc(i))==NULL){ /* and return error */ rrd_set_error("malloc failed for %i bytes",i); @@ -584,6 +592,7 @@ rrd_fetch_fn_libdbi( while((r_status=_sql_fetchrow(&table_help,&r_timestamp,&r_value,derive))>0) { /* processing of value */ /* calculate index for the timestamp */ + r_timestamp-=gmt_offset; idx=(r_timestamp-(*start))/(*step); /* some out of bounds checks on idx */ if (idx<0) { idx=0;} @@ -614,7 +623,7 @@ rrd_fetch_fn_libdbi( (*data)[idx*(*ds_cnt)+1]=r_value; /* AVG */ (*data)[idx*(*ds_cnt)+2]=r_value; /* MAX */ (*data)[idx*(*ds_cnt)+3]=1; /* COUNT */ - (*data)[idx*(*ds_cnt)+4]=r_value; /* SIGMA */ + (*data)[idx*(*ds_cnt)+4]=r_value*r_value; /* SIGMA */ } else { /* MIN */ if ((*data)[idx*(*ds_cnt)+0]>r_value) { (*data)[idx*(*ds_cnt)+0]=r_value; } @@ -651,6 +660,30 @@ rrd_fetch_fn_libdbi( } } + /* Fill in missing values */ + fillmissing/=(*step);/* Convert from seconds to steps */ + if (fillmissing>0) { + int copy_left=fillmissing; + for(idx=1;idx0) { + /* But we can copy from previous */ + int idx_p=idx-1; + (*data)[idx*(*ds_cnt)+0]=(*data)[idx_p*(*ds_cnt)+0]; + (*data)[idx*(*ds_cnt)+1]=(*data)[idx_p*(*ds_cnt)+1]; + (*data)[idx*(*ds_cnt)+2]=(*data)[idx_p*(*ds_cnt)+2]; + (*data)[idx*(*ds_cnt)+3]=(*data)[idx_p*(*ds_cnt)+3]; + (*data)[idx*(*ds_cnt)+4]=(*data)[idx_p*(*ds_cnt)+4]; + copy_left--; + } + }else{ + copy_left=fillmissing; + } + } + } + /* and return OK */ return 0; }