Telemetry API
Telemetry API provides HTTP API to request telemetry.
Get Current Telemetry Values
GET /telemetry/v1/now
Return the latest values of specified telemetry attributes.
Request
$ curl http://enapter-gateway.local/api/telemetry/v1/now -X GET -G \
-H 'X-Enapter-Auth-Token: {ACCESS_TOKEN}' \
-d 'devices[123e4567-e89b-12d3-a456-426614174000]=voltage,uptime'
Path Parameters
devices
objectrequired#The object whose keys are device IDs and values are comma-separated telemetry attributes list.
Response
devices
object#Object containing successfully requested telemetry attributes. Object keys are the requested device IDs, and values are
DeviceTelemetry
objects.DeviceTelemetry
is an object whose keys are names of telemetry attributes, and values are theSnapshot
objects.Snapshot.value
string,number,boolean#Telemetry attribute value.
Snapshot.timestamp
number#Unix timestamp.
errors
array of errors#Array of errors. See common error format for more details.
{
"devices": {
"123e4567-e89b-12d3-a456-426614174000": {
"voltage": {
"value": 12,
"timestamp": 1662593249
},
"uptime": {
"value": 12345,
"timestamp": 1662593249
}
}
}
}
Get Time Series
POST /telemetry/v1/timeseries
Return the time series — a sequence of measurements, ordered in time.
Request
$ curl http://enapter-gateway.local/api/telemetry/v1/timeseries -X POST \
-H 'X-Enapter-Auth-Token: {ACCESS_TOKEN}' \
-H 'Accept: text/csv' \
-d '{
"from": "2022-10-11T00:00:00Z",
"to": "2022-10-11T00:01:00Z",
"granularity": "1s",
"telemetry": [{
"device": "123e4567-e89b-12d3-a456-426614174000",
"attribute": "voltage",
"aggregation": "avg"
}]
}'
Body Parameters
Request body is written in query language based on JSON according to the the schema.
from
number, stringrequired#Begin of time frame. Either a number containing Unix timestamp or a string in RFC 3339 format.
to
number, stringrequired#End of time frame. Either a number containing Unix timestamp or a string in RFC 3339 format.
aggregation
string#Time bucket aggregation function. Can be overridden for each individual telemetry attribute.
Currently supported functions:
auto
— select eitheravg
orlast
depending on the data type;avg
— calculate arithmetic mean;last
— use last known value.
granularity
duration string#Time bucket interval. Can be overridden for each individual telemetry attribute.
gap_filling
object#Gap filling settings, instance of
GapFilling
object. Can be overridden for each individual telemetry attribute.GapFilling.method
string#Gap filling method. Currently the only supported gap filling method is
locf
— last observation carried forward.
GapFilling.look_around
duration string#Interval in the past to look for values outside of the time range specified.
telemetry
arrayrequired#List of
TelemetryAttribute
objects, one for each requested telemetry attribute.Currently, the maximum number of telemetry attributes per request is 10.
TelemetryAttribute.device
string#Device ID.
TelemetryAttribute.attribute
string#Telemetry attribute name, same as specified in the blueprint manifest for this device.
TelemetryAttribute.aggregation
string#Time bucket aggregation function. Overrides global
aggregation
settings. Required if global aggregation settings are not set.
TelemetryAttribute.granularity
duration string#Time bucket interval. Overrides global
granularity
settings. Required if global granularity settings are not set.
TelemetryAttribute.gap_filling
object#Gap filling settings. Overrides global
gap_filling
settings.
Response
ts,telemetry=voltage device=123e4567-e89b-12d3-a456-426614174000 aggregation=auto granularity=1s gap_filling_method=none gap_filling_look_around=0s
1665446400,4.3087
1665446410,4.3556
1665446419,4.3712
Successful response is a telemetry data in CSV format. The first row of response is CSV header. The first column is always ts
— a Unix timestamp. Other columns contain space-separated list of key=value
pairs describing the parameters used to calculate the time series in the column.
Possible header keys:
telemetry
— telemetry attribute name;device
— device ID;aggregation
— time bucket aggregation function;granularity
— time bucket interval;gap_filling_method
— gap filling method;gap_filling_look_around
— gap filling interval.
Each row after the first one represents one time series measurement at a specific time from the first column.
The HTTP header Content-Type
is text/csv
. The HTTP header X-Enapter-Timeseries-Data-Types
contains comma-separated list of types for each data column. The first column is always timestamp, so this header describes types starting from the second. Possible types are float
, integer
, string
, boolean
.
X-Enapter-Timeseries-Data-Types: float,integer,boolean
If error occurred, response contains an array of errors in JSON format, HTTP header Content-Type
is application/json
. See common error format for more details.
{
"errors": [...]
}
Duration String Format
A duration string is a sequence of decimal numbers, each with optional fraction and a unit suffix, such as 1s
, 1.5m
or 2h45m
. Valid time units are ns
(nanosecond), us
(microsecond), ms
(millisecond), s
(second), m
(minute), h
(hour), d
(day), y
(year).