Request path and method

Request path Request method Description
/api/query/last POST Queries the latest data point in a time series.
Notice This operation is fully compatible with OpenTSDB.

Request parameters

Parameters for requests in the JSON format
Parameter Type Required Description Default value Example
queries Array Yes The subqueries. None For more information, see the "Subqueries in the JSON format" section.
timestamp Long No The UNIX timestamp. Unit: seconds or milliseconds. If you specify a timestamp, you query the latest data point at the specified timestamp. If you leave this parameter empty, you query the latest data point at the current timestamp. None 1539763573

Subqueries in the JSON format

You can perform a subquery based on a metric or a TSUID. If you query data based on a metric, use the metric and tags parameters to specify query conditions. If you query data based on a TSUID, use the tsuid parameter to specify query conditions. The tsuid parameter specifies the unique ID of a time series. You can include metric queries and TSUID queries in a list of subqueries.

Query data based on a metric

Parameter Type Required Description Default value Example
metric String Yes The metric of the latest data point that you want to query. None cpu.usage
tags String No The tags of the latest data point that you want to query. None host_name=host1
Notice You can use only the tags parameter to specify query conditions. The filters parameter is not supported.

Query data based on a TSUID

Parameter Type Required Description Default value Example
tsuid String Yes The TSUID of the time series in which you want to query the latest data point. None 00005B00005C0000F000005D0000EE00005E0000EF
Notice
  • To query the TSUID of a time series, use /api/search/lookup.
  • For ApsaraDB for Lindorm (Lindorm) High-availability Edition, you can specify the tsuid parameter in a request. However, the configuration of this parameter does not take effect. When you use /api/search/lookup in the high-availability edition, Lindorm TSDB does not return the TSUID of a time series.

Sample requests in the JSON format

Objective:

Query the latest data point in each time series. In the first subquery, you set metric to cpu.usage and tags to host_name: host1.

In the second subquery, you set tsuids to 00005B00005C00002E00005D0000EE00005E0000EF and 00005B00005C0000F000005D0000EE00005E0000EF and query the latest data point in each time series.

Request line: POST/api/query/last

Request body:

{
    "queries" : [
        {
            "metric":"cpu.usage",
            "tags" : {
                "host_name": "host1"
            }
        },
        {
            "tsuids": [
                "00005B00005C00002E00005D0000EE00005E0000EF",
                "00005B00005C0000F000005D0000EE00005E0000EF"
            ]
        }
    ]
}
            

Responses

If the HTTP status code 200 is returned, the query is successful. The result indicates that the latest data point in the time series that meets the specified query conditions is returned. The result is in the JSON format. If no time series meets the query conditions, an empty set is returned. The following table describes the response parameters.

Parameter Description
metric The name of the metric.
timestamp The timestamp of the latest data point.
value The value for the metric.
tags The tag pairs of a data point. A tag consists of a tag key and a tag value.
tsuid The ID of a time series in which a data point exists.

Response body:

[{
    "metric": "cpu.usage",
    "timestamp": 1556418300000,
    "value": 30.3,
    "tags": {
        "host_name": "host1"
    },
    "tsuid": "00005B00005C00001D",
}, {
    "metric": "cpu.usage",
    "timestamp": 1556418300000,
    "value": 25.6,
    "tags": {
        "host_name": "host2",
        "cluster": "cluster1"
        "zone": "zone1"
    },
    "tsuid": "00005B00005C00002E00005D0000EE00005E0000EFE",
}, {
    "metric": "cpu.usage",
    "timestamp": 1556418300000,
    "value": 43.1,
    "tags": {
        "host_name": "host3",
        "cluster": "cluster1"
        "zone": "zone1"
    },
    "tsuid": "00005B00005C0000F000005D0000EE00005E0000EF",
}]