Updated on 2022-06-01 GMT+08:00

HTTP APIs

OpenTSDB provides HTTP-based or HTTPS-based APIs. A request method is to send a standard HTTP request containing the GET and POST methods to a path of a resource. The API is the same as that of the open source OpenTSDB. For details, visit https://opentsdb.net/docs/build/html/api_http/index.html.

The request and response entity type is application/JSON.

The code of the request and response entity is ISO-8859-1.

  • HTTP has security risks and HTTPS is a secure protocol. You are advised to use HTTPS for connection.
  • OpenTSDB provides HTTP-based RESTful APIs that are language-independent. Any language that supports HTTP requests can interconnect to OpenTSDB.

Using Java APIs to Perform Operations on OpenTSDB

OpenTSDB provides HTTP-based or HTTPS-based APIs. You can use Java APIs to call related APIs to operate data. For details, see chapter Application Development.

Running the curl Command to Operate OpenTSDB

  • Write data. For example, to write data of a metric named testdata, whose timestamp is 1524900185, value is true, tag is key and value, run the following command:
    curl -ki -X POST -d '{"metric":"testdata", "timestamp":1524900185, "value":"true", "tags":{"key":"value"}}' https://<tsd_ip>:4242/api/put?sync
    <tsd_ip>: indicates the IP address of the TSD instance of OpenTSDB to which data is to be written.
    HTTP/1.1 204 No Content
    Content-Type: application/json; charset=UTF-8
    Content-Length: 0
  • Query data. For example, to query summary information about the testdata metric in the past three years, run the following command:
    curl -ks https://<tsd_ip>:4242/api/query?start=3y-ago\&m=sum:testdata | python -m json.tool
    • <tsd_ip>: indicates the IP address or host name of the TSD instance of OpenTSDB that needs to be accessed.
    • <start=3y-ago\&m=sum:testdata>: Translates the & symbol, which may not be identified in the request.
    • (Optional) <python -m json.tool>: Converts the response request to the JSON format.
    [
        {
            "aggregateTags": [],
            "dps": {
                "1524900185": 1
            },
            "metric": "testdata",
            "tags": {
                "key": "value"
            }
        }
    ]
  • Query tsd status. For example, to query information about the client connected to HBase, run the following command:
    curl -ks https://<tsd_ip>:4242/api/stats/region_clients | python -m json.tool

    <tsd_ip>: indicates the IP address of the TSD instance of OpenTSDB that needs to be accessed.

    [
        {
            "dead": false,
            "endpoint": "/192.168.2.187:16020",
            "inflightBreached": 0,
            "pendingBatchedRPCs": 0,
            "pendingBreached": 0,
            "pendingRPCs": 0,
            "rpcResponsesTimedout": 0,
            "rpcResponsesUnknown": 0,
            "rpcid": 78,
            "rpcsInFlight": 0,
            "rpcsSent": 79,
            "rpcsTimedout": 0,
            "writesBlocked": 0
        }
    ]