Querying the First Piece of Data

Function Description

You can query a data point with the earliest timestamp by specifying a metric.

If the metric has multiple data points with different tags sharing the earliest timestamp, only one data point is returned. The unit of the timestamp is millisecond.

URI

  • URI format

    POST {OpenTSDB URL}/api/query/first

Request

  • Sample request
    {
    	"resolveNames":true,
    	"backScan":20,
    	"queries":[
    		{
    			"metric":"sys.cpu.nice"
    		},
    		{
    			"metric":"cpu.system"
    		}
    	]
    }
  • Parameter description
    Table 1 Request parameters

    Parameter

    Type

    Mandatory

    Description

    resolveNames

    Boolean

    No

    Whether to convert tsuid in the return result to the corresponding metric, Tagk, and Tagv names.

    • true: Convert
    • false: Do not convert

    backScan

    Integer

    No

    Past hours in which you want to scan data. The unit is hour.

    Data is stored by hour. Assume that the current system time is 2018/07/20 19:30:00 and backScan is set to 2. The query time range is from 2018/07/20 17:00:00 to 2106/01/01 00:00:00 instead of starting from 2018/07/20 17:30:00. The data scan starts from 2018/07/20 17:00:00 until the first piece of data is found.

    If you leave backScan blank or set it to 0, data in all time will be scanned.

    queries

    Array

    Yes

    List of metrics to be queried. The tag and tsuid cannot be specified. Multiple subqueries can be performed.

Response

  • Sample response
    [
        {
            "metric": "sys.cpu.nice",
            "timestamp": 1346846400000,
            "value": "18",
            "tags": {
                "host": "web01",
                "dc": "lga"
            },
            "tsuid": "00000E0000090007E500000A0007E6"
        },
        {
            "metric": "cpu.system",
            "timestamp": 1346846400000,
            "value": "9",
            "tags": {
                "host": "web02",
                "dc": "lga"
            },
            "tsuid": "00000F0000090007E700000A0007E6"
        }
    ]
  • Parameter description
    Table 2 Response parameters

    Parameter

    Type

    Description

    metric

    String

    Metric

    timestamp

    long

    Timestamp. The unit is millisecond.

    value

    String

    Data value

    tags

    Map

    Key-value pair of Tagk and Tagv

    tsuid

    String

    tsuid corresponding to the metric, Tagk, and Tagv

Status Code

For details about status codes, see Response Code.