]> arthur.barton.de Git - netdata.git/commitdiff
updated swagger and unified a few parameter names
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 20 Dec 2015 19:25:35 +0000 (21:25 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 20 Dec 2015 19:25:35 +0000 (21:25 +0200)
README.md
src/rrd2json.c
src/web_client.c
web/dashboard.js
web/netdata-swagger.json
web/netdata-swagger.yaml

index 4f4699717b9a087016d05c2dc56c1474acb6f3d4..3e41ffc3e63232a657010af7e246fd2d843c0dbc 100755 (executable)
--- a/README.md
+++ b/README.md
@@ -144,6 +144,9 @@ Out of the box, it comes with plugins for data collection about system informati
  ```
 
  The above will give you the last 300 seconds of traffic for eth0, aggregated in 120 points, grouped as averages, in json format.
+
+ Check [Netdata Swagger UI](http://netdata.firehol.org/swagger/) for more information about the API.
+
  
 2. If you need to embed a **netdata** chart on your web page, you can add a few javascript lines and a `div` for every graph you need. Check [this example](http://netdata.firehol.org/dashboard.html) (open it in a new tab and view its source to get the idea).
 
index 028824dd7e4ec25ec43e2bb8bf95e5f1ba9178df..1e718b48eeb7cea1f0fc9699565d7a95c013b353 100755 (executable)
@@ -472,8 +472,8 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, uint32_t opti
                        "       %sname%s: %s%s%s,\n"
                        "       %sview_update_every%s: %d,\n"
                        "       %supdate_every%s: %d,\n"
-                       "       %sfirst_entry_t%s: %u,\n"
-                       "       %slast_entry_t%s: %u,\n"
+                       "       %sfirst_entry%s: %u,\n"
+                       "       %slast_entry%s: %u,\n"
                        "       %smin%s: "
                        , kq, kq
                        , kq, kq, sq, r->st->id, sq
@@ -560,7 +560,7 @@ void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, uint32_t opti
        }
 
        buffer_sprintf(wb, "],\n"
-                       "       %sresult_latest_values%s: ["
+                       "       %sview_latest_values%s: ["
                        , kq, kq);
 
        i = 0;
index f0ec7fb658dc8727a37f2bd73630b9b3b9f53272..03a5d6049deb56450e69c53232d533e5a8ca1a5f 100755 (executable)
@@ -568,8 +568,8 @@ int web_client_api_request_v1_data(struct web_client *w, char *url)
                        *google_reqId = "0",
                        *google_sig = "0",
                        *google_out = "json",
-                       *google_responseHandler = "google.visualization.Query.setResponse",
-                       *google_outFileName = NULL;
+                       *responseHandler = NULL,
+                       *outFileName = NULL;
 
        time_t last_timestamp_in_data = 0, google_timestamp = 0;
 
@@ -614,6 +614,12 @@ int web_client_api_request_v1_data(struct web_client *w, char *url)
                else if(!strcmp(name, "options")) {
                        options |= web_client_api_request_v1_data_options(value);
                }
+               else if(!strcmp(name, "callback")) {
+                       responseHandler = value;
+               }
+               else if(!strcmp(name, "filename")) {
+                       outFileName = value;
+               }
                else if(!strcmp(name, "tqx")) {
                        // parse Google Visualization API options
                        // https://developers.google.com/chart/interactive/docs/dev/implementing_data_source
@@ -640,9 +646,9 @@ int web_client_api_request_v1_data(struct web_client *w, char *url)
                                        format = web_client_api_request_v1_data_google_format(google_out);
                                }
                                else if(!strcmp(tqx_name, "responseHandler"))
-                                       google_responseHandler = tqx_value;
+                                       responseHandler = tqx_value;
                                else if(!strcmp(tqx_name, "outFileName"))
-                                       google_outFileName = tqx_value;
+                                       outFileName = tqx_value;
                        }
                }
        }
@@ -676,19 +682,29 @@ int web_client_api_request_v1_data(struct web_client *w, char *url)
                        , options
                        );
 
-       if(google_outFileName && *google_outFileName) {
-               buffer_sprintf(w->response.header, "Content-Disposition: attachment; filename=\"%s\"\r\n", google_outFileName);
-               error("generating outfilename header: '%s'", google_outFileName);
+       if(outFileName && *outFileName) {
+               buffer_sprintf(w->response.header, "Content-Disposition: attachment; filename=\"%s\"\r\n", outFileName);
+               error("generating outfilename header: '%s'", outFileName);
        }
 
        if(format == DATASOURCE_DATATABLE_JSONP) {
+               if(responseHandler == NULL)
+                       responseHandler = "google.visualization.Query.setResponse";
+
                debug(D_WEB_CLIENT_ACCESS, "%llu: GOOGLE JSON/JSONP: version = '%s', reqId = '%s', sig = '%s', out = '%s', responseHandler = '%s', outFileName = '%s'",
-                               w->id, google_version, google_reqId, google_sig, google_out, google_responseHandler, google_outFileName
+                               w->id, google_version, google_reqId, google_sig, google_out, responseHandler, outFileName
                        );
 
                buffer_sprintf(w->response.data,
                        "%s({version:'%s',reqId:'%s',status:'ok',sig:'%lu',table:",
-                       google_responseHandler, google_version, google_reqId, st->last_updated.tv_sec);
+                       responseHandler, google_version, google_reqId, st->last_updated.tv_sec);
+       }
+       else if(format == DATASOURCE_JSONP) {
+               if(responseHandler == NULL)
+                       responseHandler = "callback";
+
+               buffer_strcat(w->response.data, responseHandler);
+               buffer_strcat(w->response.data, "(");
        }
 
        ret = rrd2format(st, w->response.data, dimensions, format, points, after, before, group, options, &last_timestamp_in_data);
@@ -702,9 +718,11 @@ int web_client_api_request_v1_data(struct web_client *w, char *url)
                        buffer_flush(w->response.data);
                        buffer_sprintf(w->response.data,
                                "%s({version:'%s',reqId:'%s',status:'error',errors:[{reason:'not_modified',message:'Data not modified'}]});",
-                               google_responseHandler, google_version, google_reqId);
+                               responseHandler, google_version, google_reqId);
                }
        }
+       else if(format == DATASOURCE_JSONP)
+               buffer_strcat(w->response.data, ");");
 
 cleanup:
        if(dimensions) buffer_free(dimensions);
@@ -1257,6 +1275,8 @@ void web_client_process(struct web_client *w) {
                "Server: NetData Embedded HTTP Server\r\n"
                "Content-Type: %s\r\n"
                "Access-Control-Allow-Origin: *\r\n"
+               "Access-Control-Allow-Methods: GET\r\n"
+               "Access-Control-Allow-Headers: x-requested-with\r\n"
                "Date: %s\r\n"
                , code, code_msg
                , w->keepalive?"keep-alive":"close"
@@ -1271,10 +1291,13 @@ void web_client_process(struct web_client *w) {
                buffer_sprintf(w->response.header_output,
                        "Expires: %s\r\n"
                        "Cache-Control: no-cache\r\n"
+                       "Access-Control-Max-Age: 0\r\n"
                        , date);
        }
-       else
+       else {
                buffer_strcat(w->response.header_output, "Cache-Control: public\r\n");
+               buffer_strcat(w->response.header_output, "Access-Control-Max-Age: 3600\r\n");
+       }
 
        // if we know the content length, put it
        if(!w->response.zoutput && (w->response.data->len || w->response.rlen))
index 1a02fbb19d5d602e108f8cbf387838143adfdd01..c3a8986c1bdd8ef26d0740e92e824e1cc150cfe5 100755 (executable)
                }
 
                var show_undefined = true;
-               if(Math.abs(this.current.data.last_entry_t - this.current.data.before) <= this.current.data.view_update_every)
+               if(Math.abs(this.current.data.last_entry - this.current.data.before) <= this.current.data.view_update_every)
                        show_undefined = false;
 
                if(show_undefined)
                        if(show_undefined)
                                this.legendSetLabelValue(label, null);
                        else
-                               this.legendSetLabelValue(label, this.current.data.result_latest_values[i]);
+                               this.legendSetLabelValue(label, this.current.data.view_latest_values[i]);
                }
        }
 
 
                        // do we have to update the current values?
                        // we do this, only when the visible chart is current
-                       if(Math.abs(this.current.data.last_entry_t - this.current.data.before) <= this.current.data.view_update_every) {
+                       if(Math.abs(this.current.data.last_entry - this.current.data.before) <= this.current.data.view_update_every) {
                                if(this.debug === true)
                                        this.log('chart in running... updating values on legend...');
 
                        if(typeof data.before !== 'undefined')
                                this.current.before_ms = data.before * 1000;
 
-                       if(typeof data.first_entry_t !== 'undefined')
-                               this.current.first_entry_ms = data.first_entry_t * 1000;
+                       if(typeof data.first_entry !== 'undefined')
+                               this.current.first_entry_ms = data.first_entry * 1000;
 
-                       if(typeof data.last_entry_t !== 'undefined')
-                               this.current.last_entry_ms = data.last_entry_t * 1000;
+                       if(typeof data.last_entry !== 'undefined')
+                               this.current.last_entry_ms = data.last_entry * 1000;
 
                        if(typeof data.points !== 'undefined')
                                this.current.points = data.points;
                                        if(NETDATA.options.debug.dygraph === true)
                                                state.log('dygraphDrawCallback()');
 
-                                       var first = state.current.data.first_entry_t * 1000;
-                                       var last = state.current.data.last_entry_t * 1000;
+                                       var first = state.current.data.first_entry * 1000;
+                                       var last = state.current.data.last_entry * 1000;
 
                                        var x_range = dygraph.xAxisRange();
                                        var after = Math.round(x_range[0]);
                                                var after = new_x_range[0];
                                                var before = new_x_range[1];
 
-                                               var first = (state.current.data.first_entry_t + state.current.data.view_update_every) * 1000;
-                                               var last = (state.current.data.last_entry_t + state.current.data.view_update_every) * 1000;
+                                               var first = (state.current.data.first_entry + state.current.data.view_update_every) * 1000;
+                                               var last = (state.current.data.last_entry + state.current.data.view_update_every) * 1000;
 
                                                if(before > last) {
                                                        after -= (before - last);
index 61e96b293b5a382da270cb8cbdad3d5ca19733c7..b15434510270e317df64625cd749f90ef7fe7747 100755 (executable)
@@ -5,6 +5,7 @@
         "description": "Real time monitoring for linux, over the web!",
         "version": "1.0.0"
     },
+    "host": "195.97.5.206:19999",
     "schemes": [
         "http"
     ],
@@ -41,7 +42,8 @@
                         "description": "The id of the chart as returned by the /charts call.",
                         "required": true,
                         "type": "string",
-                        "format": "as returned by /charts"
+                        "format": "as returned by /charts",
+                        "default": "system.cpu"
                     }
                 ],
                 "responses": {
@@ -69,7 +71,8 @@
                         "required": true,
                         "type": "string",
                         "format": "as returned by /charts",
-                        "allowEmptyValue": false
+                        "allowEmptyValue": false,
+                        "default": "system.cpu"
                     },
                     {
                         "name": "dimension",
                         "type": "number",
                         "format": "integer",
                         "allowEmptyValue": false,
-                        "default": 100
+                        "default": 20
                     },
                     {
                         "name": "group",
                             "max",
                             "average"
                         ],
-                        "default": "max",
+                        "default": "average",
                         "allowEmptyValue": false
                     },
                     {
                             "collectionFormat": "pipes",
                             "format": ""
                         },
+                        "default": "seconds|jsonwrap",
                         "allowEmptyValue": false
                     },
                     {
-                        "name": "tqx",
+                        "name": "callback",
                         "in": "query",
-                        "description": "[Google Visualization API](https://developers.google.com/chart/interactive/docs/dev/implementing_data_source?hl=en) formatted parameter.",
+                        "description": "For JSONP responses, the callback function name.",
                         "required": false,
                         "type": "string",
                         "allowEmptyValue": false
+                    },
+                    {
+                        "name": "filename",
+                        "in": "query",
+                        "description": "Add Content-Disposition: attachment; filename=<filename> header to the response, that will instruct the browser to save the response with the given filename.",
+                        "required": false,
+                        "type": "string",
+                        "allowEmptyValue": false
+                    },
+                    {
+                        "name": "tqx",
+                        "in": "query",
+                        "description": "[Google Visualization API](https://developers.google.com/chart/interactive/docs/dev/implementing_data_source?hl=en) formatted parameter.",
+                        "required": false,
+                        "type": "string"
                     }
                 ],
                 "responses": {
                     "description": "The name of the dimension"
                 }
             }
+        },
+        "json_wrap": {
+            "type": "object",
+            "properties": {
+                "api": {
+                    "type": "number",
+                    "description": "The API version this conforms to, currently 1"
+                },
+                "id": {
+                    "type": "string",
+                    "description": "The unique id of the chart"
+                },
+                "name": {
+                    "type": "string",
+                    "description": "The name of the chart"
+                },
+                "update_every": {
+                    "type": "number",
+                    "description": "The update frequency of this chart, in seconds. One value every this amount of time is kept in the round robin database (indepedently of the current view)."
+                },
+                "view_update_every": {
+                    "type": "number",
+                    "description": "The current view appropriate update frequency of this chart, in seconds. There is no point to request chart refreshes, using the same settings, more frequently than this."
+                },
+                "first_entry": {
+                    "type": "number",
+                    "description": "The UNIX timestamp of the first entry (the oldest) in the round robin database (indepedently of the current view)."
+                },
+                "last_entry": {
+                    "type": "number",
+                    "description": "The UNIX timestamp of the latest entry in the round robin database (indepedently of the current view)."
+                },
+                "after": {
+                    "type": "number",
+                    "description": "The UNIX timestamp of the first entry (the oldest) returned in this response."
+                },
+                "before": {
+                    "type": "number",
+                    "description": "The UNIX timestamp of the latest entry returned in this response."
+                },
+                "min": {
+                    "type": "number",
+                    "description": "The minimum value returned in the current view. This can be used to size the y-series of the chart."
+                },
+                "max": {
+                    "type": "number",
+                    "description": "The maximum value returned in the current view. This can be used to size the y-series of the chart."
+                },
+                "dimension_names": {
+                    "description": "The dimension names of the chart as returned in the current view.",
+                    "type": "array",
+                    "items": {
+                        "type": "string"
+                    }
+                },
+                "dimension_ids": {
+                    "description": "The dimension IDs of the chart as returned in the current view.",
+                    "type": "array",
+                    "items": {
+                        "type": "string"
+                    }
+                },
+                "latest_values": {
+                    "description": "The latest values collected for the chart (indepedently of the current view).",
+                    "type": "array",
+                    "items": {
+                        "type": "string"
+                    }
+                },
+                "view_latest_values": {
+                    "description": "The latest values returned with this response.",
+                    "type": "array",
+                    "items": {
+                        "type": "string"
+                    }
+                },
+                "dimensions": {
+                    "type": "number",
+                    "description": "The number of dimensions returned."
+                },
+                "points": {
+                    "type": "number",
+                    "description": "The number of rows / points returned."
+                },
+                "format": {
+                    "type": "string",
+                    "description": "The format of the result returned."
+                },
+                "result": {
+                    "description": "The result requested, in the format requested."
+                }
+            }
         }
     }
 }
\ No newline at end of file
index 707d17f2bcb4761442c7ff0c4538c943868ea8ca..479818b7dcdcecdb34381eabdd97f7780cf07878 100755 (executable)
@@ -3,6 +3,7 @@ info:
   title: NetData API
   description: 'Real time monitoring for linux, over the web!'
   version: 1.0.0
+host: 195.97.5.206:19999
 schemes:
   - http
 basePath: /api/v1
@@ -31,6 +32,7 @@ paths:
           required: true
           type: string
           format: 'as returned by /charts'
+          default: 'system.cpu'
       responses:
         '200':
           description: 'A javascript object with detailed information about the chart.'
@@ -51,6 +53,7 @@ paths:
           type: string
           format: 'as returned by /charts'
           allowEmptyValue: false
+          default: system.cpu
         - name: dimension
           in: query
           description: 'zero, one or more dimension ids, as returned by the /chart call.'
@@ -84,14 +87,14 @@ paths:
           type: number
           format: integer
           allowEmptyValue: false
-          default: 100
+          default: 20
         - name: group
           in: query
           description: 'The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. Two methods are supported, "max" and "average". "max" is actually calculated on the absolute value collected (so it works for both positive and negative dimesions to return the most extreme value in either direction).'
           required: true
           type: string
           enum: [ 'max', 'average' ]
-          default: 'max'
+          default: 'average'
           allowEmptyValue: false
         - name: format
           in: query
@@ -111,13 +114,25 @@ paths:
             enum: [ 'nonzero', 'flip', 'jsonwrap', 'min2max', 'seconds', 'milliseconds', 'abs', 'absolute', 'absolute-sum', 'null2zero', 'objectrows', 'google_json' ]
             collectionFormat: pipes
             format: ''
+          default: seconds|jsonwrap
+          allowEmptyValue: false
+        - name: callback
+          in: query
+          description: 'For JSONP responses, the callback function name.'
+          required: false
+          type: string
+          allowEmptyValue: false
+        - name: filename
+          in: query
+          description: 'Add Content-Disposition: attachment; filename=<filename> header to the response, that will instruct the browser to save the response with the given filename.'
+          required: false
+          type: string
           allowEmptyValue: false
         - name: tqx
           in: query
           description: '[Google Visualization API](https://developers.google.com/chart/interactive/docs/dev/implementing_data_source?hl=en) formatted parameter.'
           required: false
           type: string
-          allowEmptyValue: false
       responses:
         '200':
           description: 'The call was successful. The response should include the data.'
@@ -204,4 +219,71 @@ definitions:
       name:
         type: string
         description: 'The name of the dimension'
-
+  
+  json_wrap:
+    type: object
+    properties:
+      api:
+        type: number
+        description: 'The API version this conforms to, currently 1'
+      id:
+        type: string
+        description: 'The unique id of the chart'
+      name:
+        type: string
+        description: 'The name of the chart'
+      update_every:
+        type: number
+        description: 'The update frequency of this chart, in seconds. One value every this amount of time is kept in the round robin database (indepedently of the current view).'
+      view_update_every:
+        type: number
+        description: 'The current view appropriate update frequency of this chart, in seconds. There is no point to request chart refreshes, using the same settings, more frequently than this.'
+      first_entry:
+        type: number
+        description: 'The UNIX timestamp of the first entry (the oldest) in the round robin database (indepedently of the current view).'
+      last_entry:
+        type: number
+        description: 'The UNIX timestamp of the latest entry in the round robin database (indepedently of the current view).'
+      after:
+        type: number
+        description: 'The UNIX timestamp of the first entry (the oldest) returned in this response.'
+      before:
+        type: number
+        description: 'The UNIX timestamp of the latest entry returned in this response.'
+      min:
+        type: number
+        description: 'The minimum value returned in the current view. This can be used to size the y-series of the chart.'
+      max:
+        type: number
+        description: 'The maximum value returned in the current view. This can be used to size the y-series of the chart.'
+      dimension_names:
+        description: 'The dimension names of the chart as returned in the current view.'
+        type: array
+        items:
+          type: string
+      dimension_ids:
+        description: 'The dimension IDs of the chart as returned in the current view.'
+        type: array
+        items:
+          type: string
+      latest_values:
+        description: 'The latest values collected for the chart (indepedently of the current view).'
+        type: array
+        items:
+          type: string
+      view_latest_values:
+        description: 'The latest values returned with this response.'
+        type: array
+        items:
+          type: string
+      dimensions:
+        type: number
+        description: 'The number of dimensions returned.'
+      points:
+        type: number
+        description: 'The number of rows / points returned.'
+      format:
+        type: string
+        description: 'The format of the result returned.'
+      result:
+        description: 'The result requested, in the format requested.'