]> arthur.barton.de Git - netdata.git/blobdiff - src/rrd2json.c
fixes for enabling clion debugging
[netdata.git] / src / rrd2json.c
index 6306d9faec68d6d8f58a5f33e8661ade38afdb46..b2c1a05583ab535f4ed22a7164ad164e4e913c3b 100644 (file)
@@ -1,8 +1,5 @@
 #include "common.h"
 
-#define HOSTNAME_MAX 1024
-char *hostname = "unknown";
-
 void rrd_stats_api_v1_chart(RRDSET *st, BUFFER *wb)
 {
     pthread_rwlock_rdlock(&st->rwlock);
@@ -84,7 +81,7 @@ void rrd_stats_api_v1_charts(BUFFER *wb)
         ",\n\t\"update_every\": %d"
         ",\n\t\"history\": %d"
         ",\n\t\"charts\": {"
-        , hostname
+        , localhost.hostname
         , rrd_update_every
         , rrd_default_history_entries
         );
@@ -246,7 +243,7 @@ void rrd_stats_all_json(BUFFER *wb)
         "\t\"history\": %d,\n"
         "\t\"memory\": %lu\n"
         "}\n"
-        , hostname
+        , localhost.hostname
         , rrd_update_every
         , rrd_default_history_entries
         , memory
@@ -1161,7 +1158,7 @@ inline static void rrdr_free(RRDR *r)
     freez(r);
 }
 
-inline void rrdr_done(RRDR *r)
+static inline void rrdr_done(RRDR *r)
 {
     r->rows = r->c + 1;
     r->c = 0;
@@ -1217,13 +1214,13 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
         absolute_period_requested = 0;
     }
 
-    // allow relative for before and after
-    if(((before < 0)?-before:before) <= (st->update_every * st->entries)) {
+    // allow relative for before and after (smaller than 3 years)
+    if(((before < 0)?-before:before) <= (3 * 365 * 86400)) {
         before = last_entry_t + before;
         absolute_period_requested = 0;
     }
 
-    if(((after < 0)?-after:after) <= (st->update_every * st->entries)) {
+    if(((after < 0)?-after:after) <= (3 * 365 * 86400)) {
         if(after == 0) after = -st->update_every;
         after = before + after;
         absolute_period_requested = 0;
@@ -1548,7 +1545,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
     return r;
 }
 
-int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensions, long points, long long after, long long before, int group_method, uint32_t options, time_t *latest_timestamp, int *value_is_null)
+int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensions, long points, long long after, long long before, int group_method, uint32_t options, time_t *db_after, time_t *db_before, int *value_is_null)
 {
     RRDR *r = rrd2rrdr(st, points, after, before, group_method, !(options & RRDR_OPTION_NOT_ALIGNED));
     if(!r) {
@@ -1558,22 +1555,26 @@ int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensio
 
     if(rrdr_rows(r) == 0) {
         rrdr_free(r);
+
+        if(db_after)  *db_after  = 0;
+        if(db_before) *db_before = 0;
         if(value_is_null) *value_is_null = 1;
+
         return 400;
     }
 
     if(r->result_options & RRDR_RESULT_OPTION_RELATIVE)
-        wb->options |= WB_CONTENT_NO_CACHEABLE;
+        buffer_no_cacheable(wb);
     else if(r->result_options & RRDR_RESULT_OPTION_ABSOLUTE)
-        wb->options |= WB_CONTENT_CACHEABLE;
+        buffer_cacheable(wb);
 
     options = rrdr_check_options(r, options, dimensions);
 
     if(dimensions)
         rrdr_disable_not_selected_dimensions(r, dimensions);
 
-    if(latest_timestamp)
-        *latest_timestamp = r->before;
+    if(db_after)  *db_after  = r->after;
+    if(db_before) *db_before = r->before;
 
     long i = (options & RRDR_OPTION_REVERSED)?rrdr_rows(r) - 1:0;
     *n = rrdr2value(r, i, options, value_is_null);
@@ -1591,9 +1592,9 @@ int rrd2format(RRDSET *st, BUFFER *wb, BUFFER *dimensions, uint32_t format, long
     }
 
     if(r->result_options & RRDR_RESULT_OPTION_RELATIVE)
-        wb->options |= WB_CONTENT_NO_CACHEABLE;
+        buffer_no_cacheable(wb);
     else if(r->result_options & RRDR_RESULT_OPTION_ABSOLUTE)
-        wb->options |= WB_CONTENT_CACHEABLE;
+        buffer_cacheable(wb);
 
     options = rrdr_check_options(r, options, (dimensions)?buffer_tostring(dimensions):NULL);