parsial group points are now skipped
Costa Tsaousis (ktsaou) committed
Apr 26, 2014 at 07:02 UTC
d8816979594b7c5c6e632f278c70b2c467226a09
1 file changed
+20
-10
netdata.c
+20
-10
@@ -1130,7 +1130,7 @@ long double rrd_stats_dimension_get(RRD_DIMENSION *rd, size_t position)
1130
return(0);
1131
}
1132
1133
-unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, size_t entries_to_show, size_t group_count, int group_method, time_t after, time_t before)
1133
+unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, size_t entries_to_show, size_t group, int group_method, time_t after, time_t before)
1134
{
1135
pthread_mutex_lock(&st->mutex);
1136
@@ -1152,8 +1152,8 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1152
1153
// check the options
1154
if(entries_to_show < 1) entries_to_show = 1;
1155
- if(group_count < 1) group_count = 1;
1156
- // if(group_count > st->entries / 20) group_count = st->entries / 20;
1155
+ if(group < 1) group = 1;
1156
+ // if(group > st->entries / 20) group = st->entries / 20;
1157
1158
long printed = 0; // the lines of JSON data we have generated so far
1159
@@ -1188,9 +1188,9 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1188
1189
// temporary storage to keep track of group values and counts
1190
long double group_values[dimensions];
1191
- int group_counts[dimensions];
1191
+ int group_count = 0;
1192
for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++)
1193
- group_values[c] = group_counts[c] = 0;
1193
+ group_values[c] = 0;
1194
1195
// print the labels
1196
wb->bytes += sprintf(&wb->buffer[wb->bytes], "{\n %scols%s:\n [\n", kq, kq);
@@ -1234,7 +1234,7 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1234
normal_annotation[200] = '\0';
1235
1236
// to allow grouping on the same values, we need a pad
1237
- long pad = before % group_count;
1237
+ long pad = before % group;
1238
1239
// checks for debuging
1240
if(before < after)
@@ -1260,11 +1260,20 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1260
// find how much usec since the previous entry
1261
usec = usecdiff(&st->times[t], &st->times[lt]);
1262
1263
- if(((count - pad) % group_count) == 0) {
1263
+ if(((count - pad) % group) == 0) {
1264
if(printed >= entries_to_show) {
1265
// debug(D_RRD_STATS, "Already printed all rows. Stopping.");
1266
break;
1267
}
1268
+
1269
+ if(group_count != (group - 1)) {
1270
+ // this is an incomplete group, skip it.
1271
+ for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++)
1272
+ group_values[c] = 0;
1273
+
1274
+ group_count = 0;
1275
+ continue;
1276
+ }
1277
1278
// check if we may exceed the buffer provided
1279
web_buffer_increase(wb, line_size);
@@ -1290,6 +1299,7 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1299
}
1300
}
1301
1302
+ group_count++;
1303
for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
1304
long double oldvalue, value; // temp variable for storing data values
1305
@@ -1325,7 +1335,6 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1335
// annotation_add(my_annotations, rd->name, "%s = %0.1lf", value);
1336
// }
1337
1328
- group_counts[c]++;
1338
switch(group_method) {
1339
case GROUP_MAX:
1340
if(abs(value) > abs(group_values[c])) group_values[c] = value;
@@ -1334,18 +1343,19 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, siz
1343
default:
1344
case GROUP_AVERAGE:
1345
group_values[c] += value;
1337
- if(print_this) group_values[c] /= group_counts[c];
1346
+ if(print_this) group_values[c] /= group_count;
1347
break;
1348
}
1349
1350
if(print_this) {
1351
print_values[c] = group_values[c];
1352
group_values[c] = 0;
1344
- group_counts[c] = 0;
1353
}
1354
}
1355
1356
if(print_this) {
1357
+ group_count = 0;
1358
+
1359
if(annotate_reset) {
1360
annotation_count++;
1361
strcpy(&wb->buffer[wb->bytes], overflow_annotation);