/*****************************************************************************
- * RRDtool 1.2rc8 Copyright by Tobi Oetiker, 1997-2005
+ * RRDtool 1.2.17 Copyright by Tobi Oetiker, 1997-2006
*****************************************************************************
* rrd_fetch.c read date from an rrd to use for further processing
*****************************************************************************
struct rrd_time_value start_tv, end_tv;
char *parsetime_error = NULL;
+ optind = 0; opterr = 0; /* initialize getopt */
/* init start and end time */
parsetime("end-24h", &start_tv);
FILE *in_file;
time_t cal_start,cal_end, rra_start_time,rra_end_time;
long best_full_rra=0, best_part_rra=0, chosen_rra=0, rra_pointer=0;
- long best_step_diff=0, tmp_step_diff=0, tmp_match=0, best_match=0;
+ long best_full_step_diff=0, best_part_step_diff=0, tmp_step_diff=0, tmp_match=0, best_match=0;
long full_match, rra_base;
long start_offset, end_offset;
int first_full = 1;
int first_part = 1;
rrd_t rrd;
rrd_value_t *data_ptr;
- unsigned long rows = (*end - *start) / *step;
+ unsigned long rows;
#ifdef DEBUG
fprintf(stderr,"Entered rrd_fetch_fn() searching for the best match\n");
-fprintf(stderr,"Looking for: start %10lu end %10lu step %5lu rows %lu\n",
- *start,*end,*step,rows);
+fprintf(stderr,"Looking for: start %10lu end %10lu step %5lu\n",
+ *start,*end,*step);
#endif
if(rrd_open(filename,&in_file,&rrd, RRD_READONLY)==-1)
tmp_step_diff = labs(*step - (rrd.stat_head->pdp_step
* rrd.rra_def[i].pdp_cnt));
/* best full match */
- if(cal_end >= *end
+ if(cal_end + (rrd.stat_head->pdp_step * rrd.rra_def[i].pdp_cnt) >= *end
&& cal_start <= *start){
- if (first_full || (tmp_step_diff < best_step_diff)){
+ if (first_full || (tmp_step_diff < best_full_step_diff)){
first_full=0;
- best_step_diff = tmp_step_diff;
+ best_full_step_diff = tmp_step_diff;
best_full_rra=i;
#ifdef DEBUG
fprintf(stderr,"best full match so far\n");
if (first_part ||
(best_match < tmp_match) ||
(best_match == tmp_match &&
- tmp_step_diff < best_step_diff)){
+ tmp_step_diff < best_part_step_diff)){
#ifdef DEBUG
fprintf(stderr,"best partial so far\n");
#endif
first_part=0;
best_match = tmp_match;
- best_step_diff = tmp_step_diff;
+ best_part_step_diff = tmp_step_diff;
best_part_rra =i;
} else {
#ifdef DEBUG
/* set the wish parameters to their real values */
*step = rrd.stat_head->pdp_step * rrd.rra_def[chosen_rra].pdp_cnt;
*start -= (*start % *step);
- if (*end % *step) *end += (*step - *end % *step);
- rows = (*end - *start) / *step;
+ *end += (*step - *end % *step);
+ rows = (*end - *start) / *step + 1;
#ifdef DEBUG
fprintf(stderr,"We found: start %10lu end %10lu step %5lu rows %lu\n",