Querying the Last Piece of Data
Function Description
You can query a data point with the latest timestamp by specifying a metric or tsuid.
If the metric or tsuid has multiple data points with different tags sharing the latest timestamp, only one data point is returned. The unit of the timestamp is millisecond.
URI
- URI format
POST {OpenTSDB URL}/api/query/last
Request
- Sample request (specified metric)
{ "resolveNames":true, "backScan":20, "queries":[ { "metric":"sys.cpu.nice" }, { "metric":"cpu.system" } ] } - Sample request (specified metric and tag)
{ "resolveNames":true, "backScan":20, "queries":[ { "metric":"sys.cpu.nice", "tags": { "host": "web01", "dc": "lga" } }, { "metric":"cpu.system", "tags": { "host": "web01", "dc": "lga" } } ] } - Sample request (specified tsuid)
{ "resolveNames":true, "backScan":20, "queries":[ { "tsuids": [ "00000E0000090007E500000A0007E6", "00000F0000090007E500000A0007E6" ] } ] }
- 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.
- If only metric is specified in the subquery of queries, and tags or tsuids is not specified, the time range of the subquery is from 2018/07/20 17:00:00 to 2106/01/01 00:00:00. The data scan starts from 2106/01/01 00:00:00 until the latest piece of data is found.
- If both metric and tags are specified or tsuids is specified in the subquery of queries, the time range of the sub-query is from 2018/07/20 17:00:00 to 2018/07/20 19:30:00. The data scan starts from 2018/07/20 19:30:00 until the latest 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, tags, and tsuids to be queried. Multiple subqueries can be performed. For details, see Table 2.
Table 2 queries parameters Parameter
Type
Mandatory
Description
metric
String
No
Metric
tags
Map
No
Key-value pair of Tagk and Tagv
tsuids
List
No
tsuid corresponding to the metric, Tagk, and Tagv
In the subquery of queries, either metric or tsuids must be set.
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 3 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.
Last Article: Querying the First Piece of Data
Next Article: Managing the Data Lifecycle
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.