```
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).
" %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
}
buffer_sprintf(wb, "],\n"
- " %sresult_latest_values%s: ["
+ " %sview_latest_values%s: ["
, kq, kq);
i = 0;
*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;
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
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;
}
}
}
, 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);
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);
"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"
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))
}
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);
"description": "Real time monitoring for linux, over the web!",
"version": "1.0.0"
},
+ "host": "195.97.5.206:19999",
"schemes": [
"http"
],
"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": {
"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
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
required: true
type: string
format: 'as returned by /charts'
+ default: 'system.cpu'
responses:
'200':
description: 'A javascript object with detailed information about the chart.'
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.'
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
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.'
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.'