Request path and method

Request path Request method Description
/api/query/mlast POST Queries the latest data point from a multi-value model time series. The returned data point contains the latest values of the specified fields of the specified metric.

Request parameters

Parameter Type Required Description Default value Example
queries Array Yes The subquery array. None See the "Subquery parameters" section.
timestamp Long No The UNIX timestamp. Unit: seconds or milliseconds. If you specify a timestamp, the subquery queries the latest data point that is imported to the database before the specified timestamp. If you do not specify a timestamp, the subquery queries the latest data point that is imported before the current time. This parameter is at the same level as the queries parameter in the request. For more information, see the example. None 1539763573
tupleFormat Boolean No Specifies whether to return the tuple structure of the latest data point of the queried fields. Valid values: true and false. For more information, see the example. false false
tupleOffset Long No The offset of the tuples when the returned data is paginated. This parameter is valid only if the tupleFormat parameter is set to true. 0 5
tupleLimit Long No The maximum number of tuples when the returned data is paginated. This parameter is valid only if the tupleFormat parameter is set to true. 0 100
Notice You can use /api/query/mlast to query only the latest data point from a multi-value model time series. If you want to query the latest data point from a single-value model time series, use /api/query/last.

Subquery parameters

Parameter Type Required Description Default value Example
metric String Yes The metric of the time series from which you want to query the latest data point. None wind
fields List Yes The metric fields that you want to query. If you set this parameter to an asterisk (*), the values of all the fields in the specified metric are returned. None {speed, level, description}
tags String No The tags of the time series that you want to query for the latest data point. None sensor = IOTE_1988_0001

Sample requests in the JSON format

Objective: query the latest data point from a multi-value model time series. The returned data point contains the values of the usage_system and usage_idle fields in the cpu metric. The time series is defined by the cpu metric and the "host_name":"host1" tag.

Request line: POST/api/query/last

Request body:

    {
        "tupleFormat": true,
        "tupleOffset":5,
        "tupleLimit":100,
        "timestamp" : 1551851846,
        "queries": [
            {
                "metric": "cpu",
                "fields": ["usage_system", "usage_idle"],
                "tags": {
                    "host_name": "host1"
                }
            }
        ]
    }
            

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.
columns The columns in the returned result set. This parameter includes the timestamp field and the metric fields that are queried.
tags The tag pairs of the time series in which the time point is queried. A tag consists of a tag key and a tag value.
values The values of the metric fields. The order of the values is the same as the order of the columns.
Notice If you set the tupleFormat parameter to false in the request, the format of the response is the same as that of the response format for single-value metrics.

Sample responses in the JSON format

[
  {
    "metric": "wind",
    "columns": [
      "timestamp",
      "level",
      "speed"
    ],
    "tags": {
      "city": "hangzhou",
      "country": "china",
      "province": "zhejiang",
      "sensor": "IOTE_8859_0001"
    },
    "values": [
      [1346846405000, 5.1, 45.1]
    ]
  }
]