fix for panning starting always from the end of the chart data
Costa Tsaousis (ktsaou) committed
Oct 25, 2015 at 17:12 UTC
140854d5eeba61dfa22980b12240157d5ae4eaa1
1 file changed
+22
-22
src/rrd2json.c
+22
-22
@@ -608,6 +608,8 @@ unsigned long rrd_stats_json(int type, RRDSET *st, struct web_buffer *wb, int en
608
if(before == 0 || before > time_init) before = time_init;
609
if(after == 0) after = rrdset_first_entry_t(st);
610
611
+ before -= before % group;
612
+ after -= after % group;
613
614
// ---
615
@@ -724,39 +726,48 @@ unsigned long rrd_stats_json(int type, RRDSET *st, struct web_buffer *wb, int en
726
int annotate_reset = 0;
727
int annotation_count = 0;
728
727
- // to allow grouping on the same values, we need a pad
728
- long pad = before % group;
729
-
729
// the minimum line length we expect
730
int line_size = 4096 + (dimensions * 200);
731
733
- time_t now = time_init;
734
-
732
long t = rrdset_time2slot(st, before),
733
stop_at_t = rrdset_time2slot(st, after),
734
stop_now = 0;
735
736
+ time_t now = rrdset_slot2time(st, t), dt = st->update_every;
737
+
738
long count = 0, printed = 0, group_count = 0;
739
last_timestamp = 0;
740
742
- for(; !stop_now ; now -= st->update_every, t--) {
741
+ if(st->debug) debug(D_RRD_STATS, "%s: REQUEST after:%lu before:%lu, points:%d, group:%d, CHART cur:%ld first: %lu last:%lu, CALC start_t:%ld, stop_t:%ld"
742
+ , st->id
743
+ , after
744
+ , before
745
+ , entries_to_show
746
+ , group
747
+ , st->current_entry
748
+ , rrdset_first_entry_t(st)
749
+ , rrdset_last_entry_t(st)
750
+ , t
751
+ , stop_at_t
752
+ );
753
+
754
+ for(; !stop_now ; now -= dt, t--) {
755
if(t < 0) t = st->entries - 1;
756
if(t == stop_at_t) stop_now = 1;
757
758
int print_this = 0;
759
748
- if(st->debug) {
749
- debug(D_RRD_STATS, "%s t = %ld, count = %ld, group_count = %ld, printed = %ld, now = %lu, %s %s"
760
+ if(st->debug) debug(D_RRD_STATS, "%s t = %ld, count = %ld, group_count = %ld, printed = %ld, now = %lu, %s %s"
761
, st->id
762
, t
763
, count + 1
764
, group_count + 1
765
, printed
766
, now
756
- , (((count + 1 - pad) % group) == 0)?"PRINT":" - "
767
+ , (group_count + 1 == group)?"PRINT":" - "
768
, (now >= after && now <= before)?"RANGE":" - "
769
);
759
- }
770
+
771
772
// make sure we return data in the proper time range
773
if(now > before) continue;
@@ -769,23 +780,12 @@ unsigned long rrd_stats_json(int type, RRDSET *st, struct web_buffer *wb, int en
780
group_count++;
781
782
// check if we have to print this now
772
- if(((count - pad) % group) == 0) {
783
+ if(group_count == group) {
784
if(printed >= entries_to_show) {
785
// debug(D_RRD_STATS, "Already printed all rows. Stopping.");
786
break;
787
}
788
778
- if(group_count != group) {
779
- // this is an incomplete group, skip it.
780
- for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
781
- group_values[c] = 0;
782
- found_non_existing[c] = 0;
783
- }
784
-
785
- group_count = 0;
786
- continue;
787
- }
788
-
789
// check if we may exceed the buffer provided
790
web_buffer_increase(wb, line_size);
791