This endpoint (2.1 and later) provides support for accessing the latest value of individual time series. It provides an optimization over a regular query when only the last data point is required. Locating the last point can be done with the timestamp of the meta data counter or by scanning backwards from the current system time.
Note
In order for this endpoint to function with metric string queries by scanning for matching time series, the meta data table must exist and have been populated with counters or TSMeta objects using one of the methods specified in Metadata. You must set either tsd.core.meta.enable_tsuid_tracking
or tsd.core.meta.enable_realtime_ts
. Queries with a backscan parameter will skip the meta table.
Similar to the standard query endpoint, there are two methods to use in selecting which time series should return data:
Additionally there are two ways to find the last data point for each time series located:
All queries will return results only for time series that matched the query and for which a data point was found. The results are a list of individual data points per time series. Aggregation cannot be performed on individual data points as the timestamps may not align and the TSD will only return a single point so interpolation is impossible.
Common parameters include:
Name | Data Type | Required | Description | Default | QS | RW | Example |
---|---|---|---|---|---|---|---|
queries | Array | Required | A list of one or more queries used to determine which time series to fetch the last data point for. | timeseries | tsuids | |||
resolveNames | Boolean | Optional | Whether or not to resolve the TSUIDs of results to their metric and tag names. | false | resolve | true | |
backScan | Integer | Optional | A number of hours to search in the past for data. If set to 0 then the timestamp of the meta data counter for the time series is used. | 0 | back_scan | 24 |
Note that you can mix multiple metric and TSUID queries in one request.
The full specification for a metric query string sub query is as follows:
timeseries=<metric_name>[{<tag_name1>=<tag_value1>[,...<tag_nameN>=<tag_valueN>]}]
It is similar to a regular metric query but does not allow for aggregations, rates, down sampling or grouping operators. Note that if you supply a backscan value to avoid the meta table, then you must supply all of the tags and values to match the exact time series you are looking for. Backscan does not currently filter on the metric and tags given but will look for the specific series.
TSUID queries are simpler than Metric queries. Simply pass a list of one or more hexadecimal encoded TSUIDs separated by commas:
tsuids=<tsuid1>[,...<tsuidN>]
http://localhost:4242/api/query/last?timeseries=proc.stat.cpu{host=foo,type=idle}×eries=proc.stat.mem{host=foo,type=idle} http://localhost:4242/api/query/last?tsuids=000001000002000003,000001000002000004&back_scan=24&resolve=true
{ "queries": [ { "metric": "sys.cpu.0", "tags": { "host": "web01", "dc": "lga" } }, { "tsuids": [ "000001000002000042", "000001000002000043" ] } } ], "resolveNames":true, "backScan":24 }
The output will be an array of 0 or more data points depending on the data that was found. If a data point for a particular time series was not located within the time specified, it will not appear in the output. Output fields depend on whether or not the resolve
flag was set.
Name | Description |
---|---|
metric | Name of the metric for the time series. Only returned if resolve was set to true. |
tags | A list of tags for the time series. Only returned if resolve was set to true. |
timestamp | A Unix epoch timestamp, in milliseconds, when the data point was written |
value | The value of the data point enclosed in quotation marks as a string |
tsuid | The hexadecimal TSUID for the time series |
Unless there was an error with the query, you will generally receive a 200
status with content. However if your query couldn't find any data, it will return an empty result set. In the case of the JSON serializer, the result will be an empty array:
[]
[ { "timestamp": 1377118201000, "value": "1976558550", "tsuid": "0023E3000002000008000006000001" }, { "timestamp": 1377118201000, "value": "1654587485", "tsuid": "0023E3000002000008000006001656" } ]
[ { "metric": "tsd.hbase.rpcs", "timestamp": 1377186301000, "value": "2723265185", "tags": { "type": "put", "host": "tsd1" }, "tsuid": "0023E3000002000008000006000001" }, { "metric": "tsd.hbase.rpcs", "timestamp": 1377186301000, "value": "580720", "tags": { "type": "put", "host": "tsd2" }, "tsuid": "0023E3000002000008000006017438" } ]
© 2010–2016 The OpenTSDB Authors
Licensed under the GNU LGPLv2.1+ and GPLv3+ licenses.
http://opentsdb.net/docs/build/html/api_http/query/last.html