All Products
Search
Document Center

Query the latest data point of a time series

Last Updated: Jul 02, 2020

Request path and method

Path Method Description
/api/query/last POST Obtains the latest data point written into by the time series

Note: This port is fully compatible with OpenTSDB protocol.

Request content

Request content in the JSON format

Parameter Type Required Description Default value Example
queries Array Yes The subquery array. N/A For more information about example values, see the subquery description.
timestamp Long No The Unix timestamp, in seconds or milliseconds. If you specify this parameter, the API operation returns the latest data points up to the time specified by this parameter. If you do not specify this parameter, the API operation returns the current latest data points for the tags. This parameter is of the same level as the queries parameter. N/A 1539763573

Subqueries in the JSON format

Metric query

Name Type Required Description Default value Example
metric String Yes Metric of the latest data point to be queried None cpu.usage
tags String No Tags of the latest data point to be queried None host_name=host1

TSUID query

Name Type Required Description Default value Example
tsuid String Yes TSUID of the latest data point to be queried None 00005B00005C0000F000005D0000EE00005E0000EF

Note: The TSUID of the timeline can be queried through /api/search/lookup.

Request JSON example

Job: Query the latest data point written into by the time series, of which the metric is “cpu.usage” and the tag is “host_name=host1”. Meanwhile, query the latest data point written into by the two time series, of which TSUIDs are 00005B00005C00002E00005D0000EE00005E0000EF and 00005B00005C0000F000005D0000EE00005E0000EF respectively.

Request: POST/api/query/last

Body:

  1. {
  2. "queries" : [
  3. {
  4. "metric":"cpu.usage",
  5. "tags" : {
  6. "host_name": "host1"
  7. }
  8. },
  9. {
  10. "tsuids": [
  11. "00005B00005C00002E00005D0000EE00005E0000EF",
  12. "00005B00005C0000F000005D0000EE00005E0000EF"
  13. ]
  14. }
  15. ]
  16. }

Response description

After the successful query, HTTP response code 200 is returned. The latest data points of the compliant timeline, in JSON format, are returned. If no timeline meets the condition, an empty set is returned. The JSON object is described as follows:

Name Description
metric metric name
timestamp The timestamp of the latest data point.
value The value of the metric.
tags The tag key and value set of the data point.
tsuid The ID of the timeline corresponding to the data point.

Response body:

  1. [{
  2. "metric": "cpu.usage ",
  3. "timestamp": 1556418300000
  4. "value": 30.3
  5. "tags ": {
  6. "host_name": "host1"
  7. },
  8. "tsuid": "00005B00005C00001D ",
  9. }, {
  10. "metric": "cpu.usage ",
  11. "timestamp": 1556418300000
  12. "value": 25.6
  13. "tags ": {
  14. "host_name": "host2",
  15. "cluster": "cluster1"
  16. "zone": "zone1"
  17. },
  18. "tsuid": "00005B00005C00002E00005D0000EE00005E0000EFE ",
  19. }, {
  20. "metric": "cpu.usage ",
  21. "timestamp": 1556418300000
  22. "value": 43.1
  23. "tags ": {
  24. "host_name": "host3",
  25. "cluster": "cluster1"
  26. "zone": "zone1"
  27. },
  28. "tsuid": "00005B00005C0000F000005D0000EE00005E0000EF ",
  29. }]