]> arthur.barton.de Git - netdata.git/blobdiff - src/web_api_v1.c
Merge pull request #1998 from ktsaou/master
[netdata.git] / src / web_api_v1.c
index c180cf39fd1cf2e45e3057c6a1ead7d149720696..0acc43acb873df4b8603423d5802bb8f16ad839e 100644 (file)
@@ -185,6 +185,7 @@ inline int web_client_api_request_single_chart(RRDHOST *host, struct web_client
     }
 
     w->response.data->contenttype = CT_APPLICATION_JSON;
+    st->last_accessed_time = now_realtime_sec();
     callback(st, w->response.data);
     return 200;
 
@@ -221,6 +222,8 @@ inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client
                 format = ALLMETRICS_SHELL;
             else if(!strcmp(value, ALLMETRICS_FORMAT_PROMETHEUS))
                 format = ALLMETRICS_PROMETHEUS;
+            else if(!strcmp(value, ALLMETRICS_FORMAT_JSON))
+                format = ALLMETRICS_JSON;
             else
                 format = 0;
         }
@@ -230,6 +233,11 @@ inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client
     buffer_no_cacheable(w->response.data);
 
     switch(format) {
+        case ALLMETRICS_JSON:
+            w->response.data->contenttype = CT_APPLICATION_JSON;
+            rrd_stats_api_v1_charts_allmetrics_json(host, w->response.data);
+            return 200;
+
         case ALLMETRICS_SHELL:
             w->response.data->contenttype = CT_TEXT_PLAIN;
             rrd_stats_api_v1_charts_allmetrics_shell(host, w->response.data);
@@ -242,7 +250,7 @@ inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client
 
         default:
             w->response.data->contenttype = CT_TEXT_PLAIN;
-            buffer_strcat(w->response.data, "Which format? Only '" ALLMETRICS_FORMAT_SHELL "' and '" ALLMETRICS_FORMAT_PROMETHEUS "' is currently supported.");
+            buffer_strcat(w->response.data, "Which format? '" ALLMETRICS_FORMAT_SHELL "', '" ALLMETRICS_FORMAT_PROMETHEUS "' and '" ALLMETRICS_FORMAT_JSON "' are currently supported.");
             return 400;
     }
 }
@@ -329,6 +337,7 @@ int web_client_api_request_v1_badge(RRDHOST *host, struct web_client *w, char *u
         ret = 200;
         goto cleanup;
     }
+    st->last_accessed_time = now_realtime_sec();
 
     RRDCALC *rc = NULL;
     if(alarm) {
@@ -462,18 +471,8 @@ int web_client_api_request_v1_badge(RRDHOST *host, struct web_client *w, char *u
 
         // if the collected value is too old, don't calculate its value
         if (rrdset_last_entry_t(st) >= (now_realtime_sec() - (st->update_every * st->gap_when_lost_iterations_above)))
-            ret = rrd2value(st,
-                    w->response.data,
-                    &n,
-                    (dimensions) ? buffer_tostring(dimensions) : NULL,
-                    points,
-                    after,
-                    before,
-                    group,
-                    options,
-                    NULL,
-                    &latest_timestamp,
-                    &value_is_null);
+            ret = rrdset2value_api_v1(st, w->response.data, &n, (dimensions) ? buffer_tostring(dimensions) : NULL
+                                      , points, after, before, group, options, NULL, &latest_timestamp, &value_is_null);
 
         // if the value cannot be calculated, show empty badge
         if (ret != 200) {
@@ -613,6 +612,7 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c
         ret = 404;
         goto cleanup;
     }
+    st->last_accessed_time = now_realtime_sec();
 
     long long before = (before_str && *before_str)?str2l(before_str):0;
     long long after  = (after_str  && *after_str) ?str2l(after_str):0;
@@ -655,7 +655,8 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c
         buffer_strcat(w->response.data, "(");
     }
 
-    ret = rrd2format(st, w->response.data, dimensions, format, points, after, before, group, options, &last_timestamp_in_data);
+    ret = rrdset2anything_api_v1(st, w->response.data, dimensions, format, points, after, before, group, options
+                                 , &last_timestamp_in_data);
 
     if(format == DATASOURCE_DATATABLE_JSONP) {
         if(google_timestamp < last_timestamp_in_data)