12 #define HOSTNAME_MAX 1024
13 char *hostname = "unknown";
15 unsigned long rrd_stats_one_json(RRDSET *st, char *options, struct web_buffer *wb)
17 time_t now = time(NULL);
19 pthread_rwlock_rdlock(&st->rwlock);
21 web_buffer_snprintf(wb, 65536,
23 "\t\t\t\"id\": \"%s\",\n"
24 "\t\t\t\"name\": \"%s\",\n"
25 "\t\t\t\"type\": \"%s\",\n"
26 "\t\t\t\"family\": \"%s\",\n"
27 "\t\t\t\"title\": \"%s\",\n"
28 "\t\t\t\"priority\": %ld,\n"
29 "\t\t\t\"enabled\": %d,\n"
30 "\t\t\t\"units\": \"%s\",\n"
31 "\t\t\t\"url\": \"/data/%s/%s\",\n"
32 "\t\t\t\"chart_type\": \"%s\",\n"
33 "\t\t\t\"counter\": %ld,\n"
34 "\t\t\t\"entries\": %ld,\n"
35 "\t\t\t\"first_entry_t\": %lu,\n"
36 "\t\t\t\"last_entry\": %ld,\n"
37 "\t\t\t\"last_entry_t\": %lu,\n"
38 "\t\t\t\"last_entry_secs_ago\": %lu,\n"
39 "\t\t\t\"update_every\": %d,\n"
40 "\t\t\t\"isdetail\": %d,\n"
41 "\t\t\t\"usec_since_last_update\": %llu,\n"
42 "\t\t\t\"collected_total\": " TOTAL_NUMBER_FORMAT ",\n"
43 "\t\t\t\"last_collected_total\": " TOTAL_NUMBER_FORMAT ",\n"
44 "\t\t\t\"dimensions\": [\n"
53 , st->name, options?options:""
54 , rrdset_type_name(st->chart_type)
57 , rrdset_first_entry_t(st)
58 , rrdset_last_slot(st)
59 , rrdset_last_entry_t(st)
60 , (now < rrdset_last_entry_t(st)) ? (time_t)0 : now - rrdset_last_entry_t(st)
63 , st->usec_since_last_update
65 , st->last_collected_total
68 unsigned long memory = st->memsize;
71 for(rd = st->dimensions; rd ; rd = rd->next) {
73 memory += rd->memsize;
75 web_buffer_snprintf(wb, 4096,
77 "\t\t\t\t\t\"id\": \"%s\",\n"
78 "\t\t\t\t\t\"name\": \"%s\",\n"
79 "\t\t\t\t\t\"entries\": %ld,\n"
80 "\t\t\t\t\t\"isHidden\": %d,\n"
81 "\t\t\t\t\t\"algorithm\": \"%s\",\n"
82 "\t\t\t\t\t\"multiplier\": %ld,\n"
83 "\t\t\t\t\t\"divisor\": %ld,\n"
84 "\t\t\t\t\t\"last_entry_t\": %lu,\n"
85 "\t\t\t\t\t\"collected_value\": " COLLECTED_NUMBER_FORMAT ",\n"
86 "\t\t\t\t\t\"calculated_value\": " CALCULATED_NUMBER_FORMAT ",\n"
87 "\t\t\t\t\t\"last_collected_value\": " COLLECTED_NUMBER_FORMAT ",\n"
88 "\t\t\t\t\t\"last_calculated_value\": " CALCULATED_NUMBER_FORMAT ",\n"
89 "\t\t\t\t\t\"memory\": %lu\n"
94 , (rd->flags & RRDDIM_FLAG_HIDDEN)?1:0
95 , rrddim_algorithm_name(rd->algorithm)
98 , rd->last_collected_time.tv_sec
100 , rd->calculated_value
101 , rd->last_collected_value
102 , rd->last_calculated_value
108 web_buffer_snprintf(wb, 200,
110 "\t\t\t\"memory\" : %lu\n"
115 pthread_rwlock_unlock(&st->rwlock);
119 #define RRD_GRAPH_JSON_HEADER "{\n\t\"charts\": [\n"
120 #define RRD_GRAPH_JSON_FOOTER "\n\t]\n}\n"
122 void rrd_stats_graph_json(RRDSET *st, char *options, struct web_buffer *wb)
124 web_buffer_snprintf(wb, sizeof(RRD_GRAPH_JSON_HEADER), RRD_GRAPH_JSON_HEADER);
125 rrd_stats_one_json(st, options, wb);
126 web_buffer_snprintf(wb, sizeof(RRD_GRAPH_JSON_FOOTER), RRD_GRAPH_JSON_FOOTER);
129 void rrd_stats_all_json(struct web_buffer *wb)
131 unsigned long memory = 0;
135 web_buffer_snprintf(wb, sizeof(RRD_GRAPH_JSON_HEADER), RRD_GRAPH_JSON_HEADER);
137 pthread_rwlock_rdlock(&rrdset_root_rwlock);
138 for(st = rrdset_root, c = 0; st ; st = st->next) {
140 if(c) web_buffer_strcat(wb, ",\n");
141 memory += rrd_stats_one_json(st, NULL, wb);
145 pthread_rwlock_unlock(&rrdset_root_rwlock);
147 web_buffer_snprintf(wb, 4096, "\n\t],\n"
148 "\t\"hostname\": \"%s\",\n"
149 "\t\"update_every\": %d,\n"
150 "\t\"history\": %d,\n"
151 "\t\"memory\": %lu\n"
155 , rrd_default_history_entries
162 // ----------------------------------------------------------------------------
165 #define RRDR_EMPTY 0x01
166 #define RRDR_RESET 0x02
167 #define RRDR_HIDDEN 0x04
168 #define RRDR_NONZERO 0x08
171 typedef struct rrdresult {
172 RRDSET *st; // the chart this result refers to
174 int d; // the number of dimensions
175 int n; // the number of values in the arrays
177 uint8_t *od; // the options for the dimensions
179 time_t *t; // array of n timestamps
180 calculated_number *v; // array n x d values
181 uint8_t *o; // array n x d options
183 int c; // current line ( 0 ~ n )
185 int has_st_lock; // if st is read locked by us
188 static void rrdr_dump(RRDR *r)
193 fprintf(stderr, "\nCHART %s (%s)\n", r->st->id, r->st->name);
195 for(c = 0, d = r->st->dimensions; d ;c++, d = d->next) {
196 fprintf(stderr, "DIMENSION %s (%s), %s%s%s%s\n"
199 , (r->od[c] & RRDR_EMPTY)?"EMPTY ":""
200 , (r->od[c] & RRDR_RESET)?"RESET ":""
201 , (r->od[c] & RRDR_HIDDEN)?"HIDDEN ":""
202 , (r->od[c] & RRDR_NONZERO)?"NONZERO ":""
207 fprintf(stderr, "RRDR does not have any values in it.\n");
211 fprintf(stderr, "RRDR includes %d values in it:\n", r->c + 1);
213 // for each line in the array
214 for(i = 0; i <= r->c ;i++) {
215 calculated_number *cn = &r->v[ i * r->d ];
216 uint8_t *co = &r->o[ i * r->d ];
218 // print the id and the timestamp of the line
219 fprintf(stderr, "%ld %ld ", i + 1, r->t[i]);
221 // for each dimension
222 for(c = 0, d = r->st->dimensions; d ;c++, d = d->next) {
223 if(unlikely(r->od[c] & RRDR_HIDDEN)) continue;
224 if(unlikely(!(r->od[c] & RRDR_NONZERO))) continue;
226 if(co[c] & RRDR_EMPTY)
227 fprintf(stderr, "null ");
229 fprintf(stderr, CALCULATED_NUMBER_FORMAT " %s%s%s%s "
231 , (co[c] & RRDR_EMPTY)?"E":" "
232 , (co[c] & RRDR_RESET)?"R":" "
233 , (co[c] & RRDR_HIDDEN)?"H":" "
234 , (co[c] & RRDR_NONZERO)?"N":" "
238 fprintf(stderr, "\n");
242 inline static calculated_number *rrdr_line_values(RRDR *r)
244 return &r->v[ r->c * r->d ];
247 inline static uint8_t *rrdr_line_options(RRDR *r)
249 return &r->o[ r->c * r->d ];
252 inline static int rrdr_line_init(RRDR *r, time_t t)
255 if(unlikely(r->c >= r->n)) {
266 inline static void rrdr_lock_rrdset(RRDR *r) {
268 error("NULL value given!");
272 pthread_rwlock_rdlock(&r->st->rwlock);
276 inline static void rrdr_unlock_rrdset(RRDR *r) {
278 error("NULL value given!");
282 if(likely(r->has_st_lock)) {
283 pthread_rwlock_unlock(&r->st->rwlock);
288 inline static void rrdr_free(RRDR *r)
291 error("NULL value given!");
295 rrdr_unlock_rrdset(r);
296 if(likely(r->t)) free(r->t);
297 if(likely(r->v)) free(r->v);
298 if(likely(r->o)) free(r->o);
299 if(likely(r->od)) free(r->od);
303 static RRDR *rrdr_create(RRDSET *st, int n)
306 error("NULL value given!");
310 RRDR *r = calloc(1, sizeof(RRDR));
311 if(unlikely(!r)) goto cleanup;
318 for(rd = st->dimensions ; rd ; rd = rd->next) r->d++;
321 r->t = malloc(n * sizeof(time_t));
322 if(unlikely(!r->t)) goto cleanup;
324 r->t = malloc(n * sizeof(time_t));
325 if(unlikely(!r->t)) goto cleanup;
327 r->v = malloc(n * r->d * sizeof(calculated_number));
328 if(unlikely(!r->v)) goto cleanup;
330 r->o = malloc(n * r->d * sizeof(uint8_t));
331 if(unlikely(!r->o)) goto cleanup;
333 r->od = calloc(r->d, sizeof(uint8_t));
334 if(unlikely(!r->od)) goto cleanup;
341 error("Cannot allocate memory");
342 if(likely(r)) rrdr_free(r);
346 RRDR *rrd2rrdr(RRDSET *st, long points, time_t after, time_t before, int group_method)
348 int debug = st->debug;
350 time_t first_entry_t = rrdset_first_entry_t(st);
351 time_t last_entry_t = rrdset_last_entry_t(st);
353 // allow relative for before and after
354 if(before <= st->update_every * st->entries) before = last_entry_t + before;
355 if(after <= st->update_every * st->entries) after = last_entry_t + after;
357 // make sure they are within our timeframe
358 if(before > last_entry_t) before = last_entry_t;
359 if(before < first_entry_t) before = first_entry_t;
361 if(after > last_entry_t) after = last_entry_t;
362 if(after < first_entry_t) after = first_entry_t;
364 // check if they are upside down
371 // the duration of the chart
372 time_t duration = before - after;
373 if(duration <= 0) return NULL;
375 // check the required points
376 if(points > duration / st->update_every) points = 0;
377 if(points <= 0) points = duration / st->update_every;
379 // calculate proper grouping of source data
380 long group = duration / points;
381 if(group <= 0) group = 1;
382 if(duration / group > points) group++;
384 // error("NEW: points=%d after=%d before=%d group=%d, duration=%d", points, after, before, group, duration);
387 // before = the end time of the calculation
388 // after = the start time of the calculation
389 // duration = the duration of the calculation
390 // group = the number of source points to aggregate / group together
391 // method = the method of grouping source points
392 // points = the number of points to generate
395 // -------------------------------------------------------------------------
396 // initialize our result set
398 RRDR *r = rrdr_create(st, points);
405 // find how many dimensions we have
406 long dimensions = r->d;
409 // -------------------------------------------------------------------------
410 // checks for debugging
412 if(debug) debug(D_RRD_STATS, "INFO %s first_t: %lu, last_t: %lu, all_duration: %lu, after: %lu, before: %lu, duration: %lu, points: %ld, group: %ld"
416 , last_entry_t - first_entry_t
425 // -------------------------------------------------------------------------
426 // temp arrays for keeping values per dimension
428 calculated_number group_values[dimensions]; // keep sums when grouping
429 long group_counts[dimensions]; // keep the number of values added to group_values
430 uint8_t group_options[dimensions];
431 uint8_t found_non_zero[dimensions];
437 for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
440 group_options[c] = 0;
441 found_non_zero[c] = 0;
445 // -------------------------------------------------------------------------
448 long t = rrdset_time2slot(st, before), // rrdset_last_slot(st),
449 stop_at_t = rrdset_time2slot(st, after),
455 // align to group for proper panning of data
458 time_t now = rrdset_slot2time(st, t),
459 dt = st->update_every,
462 if(debug) debug(D_RRD_STATS, "BEGIN %s after_t: %lu (stop slot %ld), before_t: %lu (start slot %ld), start_t(now): %lu"
471 for( ; !stop_now ; now -= dt, t--) {
472 if(unlikely(t < 0)) c = st->entries - 1;
473 if(t == stop_at_t) stop_now = 1;
475 if(debug) debug(D_RRD_STATS, "ROW %s c: %ld, group_count: %ld, added: %ld, now: %lu, %s %s"
481 , (group_count + 1 == group)?"PRINT":" - "
482 , (now >= after && now <= before)?"RANGE":" - "
485 // make sure we return data in the proper time range
486 if(unlikely(now > before)) continue;
487 if(unlikely(now < after)) break;
489 if(group_count == 0) group_start_t = now;
492 if(unlikely(group_count == group)) {
493 if(unlikely(added >= points)) break;
497 // do the calculations
498 for(rd = st->dimensions, c = 0 ; likely(rd && c < dimensions) ; rd = rd->next, c++) {
499 storage_number n = rd->values[t];
500 if(unlikely(!does_storage_number_exist(n))) continue;
504 calculated_number value = unpack_storage_number(n);
506 group_options[c] |= RRDR_NONZERO;
507 found_non_zero[c] = 1;
510 if(unlikely(did_storage_number_reset(n)))
511 group_options[c] |= RRDR_RESET;
513 switch(group_method) {
515 if(unlikely(abs(value) > abs(group_values[c])))
516 group_values[c] = value;
522 group_values[c] += value;
528 if(unlikely(add_this)) {
529 if(!rrdr_line_init(r, group_start_t)) break;
531 calculated_number *cn = rrdr_line_values(r);
532 uint8_t *co = rrdr_line_options(r);
534 for(rd = st->dimensions, c = 0 ; likely(rd && c < dimensions) ; rd = rd->next, c++) {
536 // update the dimension options
537 if(found_non_zero[c]) r->od[c] |= RRDR_NONZERO;
538 if(rd->flags & RRDDIM_FLAG_HIDDEN) r->od[c] |= RRDR_HIDDEN;
540 // store the specific point options
541 co[c] = group_options[c];
544 if(group_counts[c] == 0) {
548 else if(unlikely(group_method == GROUP_AVERAGE)) {
549 cn[c] = group_values[c] / group_counts[c];
552 cn[c] = group_values[c];
555 // reset them for the next loop
558 group_options[c] = 0;
572 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)
575 pthread_rwlock_rdlock(&st->rwlock);
578 // -------------------------------------------------------------------------
579 // switch from JSON to google JSON
584 case DATASOURCE_GOOGLE_JSON:
585 case DATASOURCE_GOOGLE_JSONP:
590 case DATASOURCE_JSON:
596 // -------------------------------------------------------------------------
597 // validate the parameters
599 if(points < 1) points = 1;
600 if(group < 1) group = 1;
602 if(before == 0 || before > rrdset_last_entry_t(st)) before = rrdset_last_entry_t(st);
603 if(after == 0 || after < rrdset_first_entry_t(st)) after = rrdset_first_entry_t(st);
607 // our return value (the last timestamp printed)
608 // this is required to detect re-transmit in google JSONP
609 time_t last_timestamp = 0;
612 // -------------------------------------------------------------------------
613 // find how many dimensions we have
617 for( rd = st->dimensions ; rd ; rd = rd->next) dimensions++;
619 pthread_rwlock_unlock(&st->rwlock);
620 web_buffer_strcat(wb, "No dimensions yet.");
625 // -------------------------------------------------------------------------
626 // prepare various strings, to speed up the loop
628 char overflow_annotation[201]; snprintf(overflow_annotation, 200, ",{%sv%s:%sRESET OR OVERFLOW%s},{%sv%s:%sThe counters have been wrapped.%s}", kq, kq, sq, sq, kq, kq, sq, sq);
629 char normal_annotation[201]; snprintf(normal_annotation, 200, ",{%sv%s:null},{%sv%s:null}", kq, kq, kq, kq);
630 char pre_date[51]; snprintf(pre_date, 50, " {%sc%s:[{%sv%s:%s", kq, kq, kq, kq, sq);
631 char post_date[21]; snprintf(post_date, 20, "%s}", sq);
632 char pre_value[21]; snprintf(pre_value, 20, ",{%sv%s:", kq, kq);
633 char post_value[21]; snprintf(post_value, 20, "}");
636 // -------------------------------------------------------------------------
637 // checks for debugging
640 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"
642 , rrdset_first_entry_t(st)
643 , rrdset_last_entry_t(st)
644 , rrdset_last_entry_t(st) - rrdset_first_entry_t(st)
653 debug(D_RRD_STATS, "WARNING: %s The newest value in the database (%lu) is earlier than the oldest (%lu)", st->name, before, after);
655 if((before - after) > st->entries * st->update_every)
656 debug(D_RRD_STATS, "WARNING: %s The time difference between the oldest and the newest entries (%lu) is higher than the capacity of the database (%lu)", st->name, before - after, st->entries * st->update_every);
660 // -------------------------------------------------------------------------
661 // temp arrays for keeping values per dimension
663 calculated_number group_values[dimensions]; // keep sums when grouping
664 int print_hidden[dimensions]; // keep hidden flags
665 int found_non_zero[dimensions];
666 int found_non_existing[dimensions];
669 for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
671 print_hidden[c] = (rd->flags & RRDDIM_FLAG_HIDDEN)?1:0;
672 found_non_zero[c] = 0;
673 found_non_existing[c] = 0;
677 // error("OLD: points=%d after=%d before=%d group=%d, duration=%d", entries_to_show, before - (st->update_every * group * entries_to_show), before, group, before - after + 1);
678 // rrd2array(st, entries_to_show, before - (st->update_every * group * entries_to_show), before, group_method, only_non_zero);
679 // rrd2rrdr(st, entries_to_show, before - (st->update_every * group * entries_to_show), before, group_method);
681 // -------------------------------------------------------------------------
682 // remove dimensions that contain only zeros
685 if(only_non_zero) max_loop = 2;
687 for(; max_loop ; max_loop--) {
689 // -------------------------------------------------------------------------
690 // print the JSON header
692 web_buffer_snprintf(wb, 1024, "{\n %scols%s:\n [\n", kq, kq);
693 web_buffer_snprintf(wb, 1024, " {%sid%s:%s%s,%slabel%s:%stime%s,%spattern%s:%s%s,%stype%s:%sdatetime%s},\n", kq, kq, sq, sq, kq, kq, sq, sq, kq, kq, sq, sq, kq, kq, sq, sq);
694 web_buffer_snprintf(wb, 1024, " {%sid%s:%s%s,%slabel%s:%s%s,%spattern%s:%s%s,%stype%s:%sstring%s,%sp%s:{%srole%s:%sannotation%s}},\n", kq, kq, sq, sq, kq, kq, sq, sq, kq, kq, sq, sq, kq, kq, sq, sq, kq, kq, kq, kq, sq, sq);
695 web_buffer_snprintf(wb, 1024, " {%sid%s:%s%s,%slabel%s:%s%s,%spattern%s:%s%s,%stype%s:%sstring%s,%sp%s:{%srole%s:%sannotationText%s}}", kq, kq, sq, sq, kq, kq, sq, sq, kq, kq, sq, sq, kq, kq, sq, sq, kq, kq, kq, kq, sq, sq);
697 // print the header for each dimension
698 // and update the print_hidden array for the dimensions that should be hidden
700 for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
701 if(!print_hidden[c]) {
703 web_buffer_snprintf(wb, 1024, ",\n {%sid%s:%s%s,%slabel%s:%s%s%s,%spattern%s:%s%s,%stype%s:%snumber%s}", kq, kq, sq, sq, kq, kq, sq, rd->name, sq, kq, kq, sq, sq, kq, kq, sq, sq);
707 web_buffer_snprintf(wb, 1024, ",\n {%sid%s:%s%s,%slabel%s:%s%s%s,%spattern%s:%s%s,%stype%s:%snumber%s}", kq, kq, sq, sq, kq, kq, sq, "no data", sq, kq, kq, sq, sq, kq, kq, sq, sq);
710 // print the begin of row data
711 web_buffer_snprintf(wb, 1024, "\n ],\n %srows%s:\n [\n", kq, kq);
714 // -------------------------------------------------------------------------
717 int annotate_reset = 0;
718 int annotation_count = 0;
720 // the minimum line length we expect
721 int line_size = 4096 + (dimensions * 200);
723 long t = rrdset_time2slot(st, before),
724 stop_at_t = rrdset_time2slot(st, after),
729 time_t now = rrdset_slot2time(st, t),
730 dt = st->update_every;
732 long count = 0, printed = 0, group_count = 0;
735 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 , rrdset_first_entry_t(st)
743 , rrdset_last_entry_t(st)
748 for(; !stop_now ; now -= dt, t--) {
749 if(t < 0) t = st->entries - 1;
750 if(t == stop_at_t) stop_now = 1;
754 if(st->debug) debug(D_RRD_STATS, "%s t = %ld, count = %ld, group_count = %ld, printed = %ld, now = %lu, %s %s"
761 , (group_count + 1 == group)?"PRINT":" - "
762 , (now >= after && now <= before)?"RANGE":" - "
766 // make sure we return data in the proper time range
767 if(now > before) continue;
768 if(now < after) break;
770 //if(rrdset_slot2time(st, t) != now)
771 // error("%s: slot=%ld, now=%ld, slot2time=%ld, diff=%ld, last_entry_t=%ld, rrdset_last_slot=%ld", st->id, t, now, rrdset_slot2time(st,t), now - rrdset_slot2time(st,t), rrdset_last_entry_t(st), rrdset_last_slot(st));
776 // check if we have to print this now
777 if(group_count == group) {
778 if(printed >= points) {
779 // debug(D_RRD_STATS, "Already printed all rows. Stopping.");
783 // generate the local date time
784 struct tm *tm = localtime(&now);
785 if(!tm) { error("localtime() failed."); continue; }
786 if(now > last_timestamp) last_timestamp = now;
788 if(printed) web_buffer_strcat(wb, "]},\n");
789 web_buffer_strcat(wb, pre_date);
790 web_buffer_jsdate(wb, tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
791 web_buffer_strcat(wb, post_date);
796 // do the calculations
797 for(rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
798 storage_number n = rd->values[t];
799 calculated_number value = unpack_storage_number(n);
801 if(!does_storage_number_exist(n)) {
803 found_non_existing[c]++;
805 if(did_storage_number_reset(n)) annotate_reset = 1;
807 switch(group_method) {
809 if(abs(value) > abs(group_values[c])) group_values[c] = value;
813 group_values[c] += value;
818 group_values[c] += value;
819 if(print_this) group_values[c] /= ( group_count - found_non_existing[c] );
827 web_buffer_strcat(wb, overflow_annotation);
831 web_buffer_strcat(wb, normal_annotation);
834 for(c = 0 ; c < dimensions ; c++) {
835 if(found_non_existing[c] == group_count) {
836 // all entries are non-existing
838 web_buffer_strcat(wb, pre_value);
839 web_buffer_strcat(wb, "null");
840 web_buffer_strcat(wb, post_value);
842 else if(!print_hidden[c]) {
844 web_buffer_strcat(wb, pre_value);
845 web_buffer_rrd_value(wb, group_values[c]);
846 web_buffer_strcat(wb, post_value);
848 if(group_values[c]) found_non_zero[c]++;
851 // reset them for the next loop
853 found_non_existing[c] = 0;
856 // if all dimensions are hidden, print a null
858 web_buffer_strcat(wb, pre_value);
859 web_buffer_strcat(wb, "null");
860 web_buffer_strcat(wb, post_value);
868 if(printed) web_buffer_strcat(wb, "]}");
869 web_buffer_strcat(wb, "\n ]\n}\n");
871 if(only_non_zero && max_loop > 1) {
873 for(rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
875 found_non_existing[c] = 0;
877 if(!print_hidden[c] && !found_non_zero[c]) {
883 if(changed) web_buffer_flush(wb);
890 debug(D_RRD_STATS, "RRD_STATS_JSON: %s total %ld bytes", st->name, wb->len);
892 pthread_rwlock_unlock(&st->rwlock);
893 return last_timestamp;