/api/put
To save on bandwidth, the put API allows clients to store multiple data points in a single request. The data points do not have to be related in any way. Each data point is processed individually and an error with one piece of data will not affect the storing of good data. This means if your request has 100 data points and 1 of them has an error, 99 data points will still be written and one will be rejected. See the Response section below for details on determining what data point was not stored.
Note
If the content you provide with the request cannot be parsed, such JSON content missing a quotation mark or curly brace, then all of the datapoints will be discarded. The API will return an error with details about what went wrong.
While the API does support multiple data points per request, the API will not return until every one has been processed. That means metric and tag names/values must be verified, the value parsed and the data queued for storage. If your put request has a large number of data points, it may take a long time for the API to respond, particularly if OpenTSDB has to assign UIDs to tag names or values. Therefore it is a good idea to limit the maximum number of data points per request; 50 per request is a good starting point.
Another recommendation is to enable keep-alives on your HTTP client so that you can re-use your connection to the server every time you put data.
Note
When using HTTP for puts, you may need to enable support for chunks if your HTTP client automatically breaks large requests into smaller packets. For example, CURL will break up messages larger than 2 or 3 data points and by default, OpenTSDB disables chunk support. Enable it by setting to true in the config file.
Note
If the tsd.mode
is set to ro
, the /api/put
endpoint will be unavailable and all calls will return a 404 error.
- POST
Some query string parameters can be supplied that alter the response to a put request:
If both detailed
and summary
are present in a query string, the API will respond with information.
The fields and examples below refer to the default JSON serializer.
You can supply a single data point in a request:
Multiple data points must be encased in an array:
By default, the put endpoint will respond with a 204
HTTP status code and no content if all data points were stored successfully. If one or more datapoints had an error, the API will return a 400
with an error message in the content.
For debugging purposes, you can ask for the response to include a summary of how many data points were stored successfully and failed, or get details about what data points could not be stored and why so that you can fix your client code. Also, errors with a data point will be logged in the TSD’s log file so you can look there for issues.
Fields present in summary
or responses include: