]> arthur.barton.de Git - netdata.git/blobdiff - src/rrd2json.c
layout: remove executable from unrelated files
[netdata.git] / src / rrd2json.c
old mode 100755 (executable)
new mode 100644 (file)
index 7a5f6df..ad453cb
@@ -23,6 +23,7 @@ void rrd_stats_api_v1_chart(RRDSET *st, BUFFER *wb)
                "\t\t\t\"name\": \"%s\",\n"
                "\t\t\t\"type\": \"%s\",\n"
                "\t\t\t\"family\": \"%s\",\n"
+               "\t\t\t\"context\": \"%s\",\n"
                "\t\t\t\"title\": \"%s\",\n"
                "\t\t\t\"priority\": %ld,\n"
                "\t\t\t\"enabled\": %s,\n"
@@ -38,6 +39,7 @@ void rrd_stats_api_v1_chart(RRDSET *st, BUFFER *wb)
                , st->name
                , st->type
                , st->family
+               , st->context
                , st->title
                , st->priority
                , st->enabled?"true":"false"
@@ -122,6 +124,7 @@ unsigned long rrd_stats_one_json(RRDSET *st, char *options, BUFFER *wb)
                "\t\t\t\"name\": \"%s\",\n"
                "\t\t\t\"type\": \"%s\",\n"
                "\t\t\t\"family\": \"%s\",\n"
+               "\t\t\t\"context\": \"%s\",\n"
                "\t\t\t\"title\": \"%s\",\n"
                "\t\t\t\"priority\": %ld,\n"
                "\t\t\t\"enabled\": %d,\n"
@@ -144,6 +147,7 @@ unsigned long rrd_stats_one_json(RRDSET *st, char *options, BUFFER *wb)
                , st->name
                , st->type
                , st->family
+               , st->context
                , st->title
                , st->priority
                , st->enabled
@@ -259,16 +263,21 @@ void rrd_stats_all_json(BUFFER *wb)
 
 // ----------------------------------------------------------------------------
 
-// RRDR options
+// RRDR dimension options
 #define RRDR_EMPTY     0x01 // the dimension contains / the value is empty (null)
 #define RRDR_RESET     0x02 // the dimension contains / the value is reset
 #define RRDR_HIDDEN    0x04 // the dimension contains / the value is hidden
 #define RRDR_NONZERO   0x08 // the dimension contains / the value is non-zero
 
+// RRDR result options
+#define RRDR_RESULT_OPTION_ABSOLUTE 0x00000001
+#define RRDR_RESULT_OPTION_RELATIVE 0x00000002
 
 typedef struct rrdresult {
        RRDSET *st;                     // the chart this result refers to
 
+       uint32_t result_options;        // RRDR_RESULT_OPTION_*
+
        int d;                                  // the number of dimensions
        long n;                                 // the number of values in the arrays
        long rows;                          // the number of rows used
@@ -1200,6 +1209,7 @@ cleanup:
 RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int group_method)
 {
        int debug = st->debug;
+       int absolute_period_requested = -1;
 
        time_t first_entry_t = rrdset_first_entry_t(st);
        time_t last_entry_t = rrdset_last_entry_t(st);
@@ -1207,14 +1217,22 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
        if(before == 0 && after == 0) {
                before = last_entry_t;
                after = first_entry_t;
+               absolute_period_requested = 0;
        }
 
        // allow relative for before and after
-       if(before <= st->update_every * st->entries)
+       if(before <= st->update_every * st->entries) {
                before = last_entry_t + before;
+               absolute_period_requested = 0;
+       }
 
-       if(after <= st->update_every * st->entries)
+       if(after <= st->update_every * st->entries) {
                after = last_entry_t + after;
+               absolute_period_requested = 0;
+       }
+
+       if(absolute_period_requested == -1)
+               absolute_period_requested = 1;
 
        // make sure they are within our timeframe
        if(before > last_entry_t) before = last_entry_t;
@@ -1314,6 +1332,11 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
                return r;
        }
 
+       if(absolute_period_requested == 1)
+               r->result_options |= RRDR_RESULT_OPTION_ABSOLUTE;
+       else
+               r->result_options |= RRDR_RESULT_OPTION_RELATIVE;
+
        // find how many dimensions we have
        long dimensions = r->d;
 
@@ -1497,6 +1520,11 @@ int rrd2format(RRDSET *st, BUFFER *wb, BUFFER *dimensions, uint32_t format, long
                return 500;
        }
 
+       if(r->result_options & RRDR_RESULT_OPTION_RELATIVE)
+               wb->options |= WB_CONTENT_NO_CACHEABLE;
+       else if(r->result_options & RRDR_RESULT_OPTION_ABSOLUTE)
+               wb->options |= WB_CONTENT_CACHEABLE;
+
        options = rrdr_check_options(r, options, (dimensions)?buffer_tostring(dimensions):NULL);
 
        if(dimensions)