+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <pthread.h>
#include <sys/time.h>
#include <stdlib.h>
if(group <= 0) group = 1;
if(duration / group > points) group++;
- // align timestamps to group
- before -= before % group;
- after -= after % group;
- duration = before - after;
-
// error("NEW: points=%d after=%d before=%d group=%d, duration=%d", points, after, before, group, duration);
// Now we have:
add_this = 0,
stop_now = 0;
+ // align to group for proper panning of data
+ t -= t % group;
+
time_t now = rrdset_slot2time(st, t),
dt = st->update_every,
group_start_t = 0;
return NULL;
}
-unsigned long rrd_stats_json(int type, RRDSET *st, struct web_buffer *wb, int entries_to_show, int group, int group_method, time_t after, time_t before, int only_non_zero)
+unsigned long rrd_stats_json(int type, RRDSET *st, struct web_buffer *wb, int points, int group, int group_method, time_t after, time_t before, int only_non_zero)
{
int c;
pthread_rwlock_rdlock(&st->rwlock);
// -------------------------------------------------------------------------
// validate the parameters
- if(entries_to_show < 1) entries_to_show = 1;
+ if(points < 1) points = 1;
if(group < 1) group = 1;
- time_t time_init = rrdset_last_entry_t(st);
-
- if(before == 0 || before > time_init) before = time_init;
- if(after == 0) after = rrdset_first_entry_t(st);
-
+ if(before == 0 || before > rrdset_last_entry_t(st)) before = rrdset_last_entry_t(st);
+ if(after == 0 || after < rrdset_first_entry_t(st)) after = rrdset_first_entry_t(st);
// ---
// -------------------------------------------------------------------------
- // checks for debuging
+ // checks for debugging
if(st->debug) {
debug(D_RRD_STATS, "%s first_entry_t = %lu, last_entry_t = %lu, duration = %lu, after = %lu, before = %lu, duration = %lu, entries_to_show = %lu, group = %lu"
, after
, before
, before - after
- , entries_to_show
+ , points
, group
);
int annotate_reset = 0;
int annotation_count = 0;
- // to allow grouping on the same values, we need a pad
- long pad = before % group;
-
// the minimum line length we expect
int line_size = 4096 + (dimensions * 200);
- time_t now = time_init;
-
long t = rrdset_time2slot(st, before),
stop_at_t = rrdset_time2slot(st, after),
stop_now = 0;
+ t -= t % group;
+
+ time_t now = rrdset_slot2time(st, t),
+ dt = st->update_every;
+
long count = 0, printed = 0, group_count = 0;
last_timestamp = 0;
- for(; !stop_now ; now -= st->update_every, t--) {
+ 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"
+ , st->id
+ , after
+ , before
+ , points
+ , group
+ , st->current_entry
+ , rrdset_first_entry_t(st)
+ , rrdset_last_entry_t(st)
+ , t
+ , stop_at_t
+ );
+
+ for(; !stop_now ; now -= dt, t--) {
if(t < 0) t = st->entries - 1;
if(t == stop_at_t) stop_now = 1;
int print_this = 0;
- if(st->debug) {
- debug(D_RRD_STATS, "%s t = %ld, count = %ld, group_count = %ld, printed = %ld, now = %lu, %s %s"
+ if(st->debug) debug(D_RRD_STATS, "%s t = %ld, count = %ld, group_count = %ld, printed = %ld, now = %lu, %s %s"
, st->id
, t
, count + 1
, group_count + 1
, printed
, now
- , (((count + 1 - pad) % group) == 0)?"PRINT":" - "
+ , (group_count + 1 == group)?"PRINT":" - "
, (now >= after && now <= before)?"RANGE":" - "
);
- }
+
// make sure we return data in the proper time range
if(now > before) continue;
group_count++;
// check if we have to print this now
- if(((count - pad) % group) == 0) {
- if(printed >= entries_to_show) {
+ if(group_count == group) {
+ if(printed >= points) {
// debug(D_RRD_STATS, "Already printed all rows. Stopping.");
break;
}
- if(group_count != group) {
- // this is an incomplete group, skip it.
- for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
- group_values[c] = 0;
- found_non_existing[c] = 0;
- }
-
- group_count = 0;
- continue;
- }
-
// check if we may exceed the buffer provided
web_buffer_increase(wb, line_size);