This topic describes how to write data to ApsaraDB for Lindorm instances by using the InfluxDB® line protocol. This topic also provides examples.
For more information about the format of the InfluxDB® line protocol that is supported by Lindorm instances, see Line protocol. You can use applications or devices that support data transmission over the line protocol to write data points to Lindorm instances.
Request path and method
Request path | Request method | Description |
---|---|---|
/api/v2/write | POST | Write data by using the line protocol. You must write data in the line protocol format to the body of a POST request. |
Protocol format
<table_name>[,<tag_key>=<tag_value>[,<tag_key>=<tag_value>]] <field_key>=<field_value>[,<field_key>=<field_value>] [<timestamp>]
Data types
The syntax of the line protocol supports the following data types: float, integer, string, Boolean, and timestamp. The following table describes the data types.
Data type | Description |
---|---|
Float | Floating-point numbers, for example, 1, 1.0, 1.e+78, and 1.E+78. Default data type: float. |
Integer | Integers. You can specify 64-bit integers. You must suffix an integer with an i to identify the data type, for example, 12i and 101i. |
String | Strings. You must enclose a string in double quotation marks ("). for example, "hello world". |
Boolean | Boolean values. Valid values: True and False.
|
Timestamp | Timestamps. The line protocol allows you to specify timestamps in ns. When the system stores the timestamps, the unit of the timestamps is converted to ms. If you want to modify the precision for timestamps, specify the required value for the precision parameter. |
Parameters
Parameter | Required | Description |
---|---|---|
table_name | Yes | The name of the table to which you want to write data. |
tag_set | No | The data tags. You can search data by tag. |
field_set | Yes | The data fields. |
timestamp | No | The timestamp. By default, the timestamp indicates the present time. Default unit: ns. If you want to modify the precision for timestamps, specify the required value for the precision parameter. |
precision | No | The time precision. Default value: ns. Valid values: ns, us, ms, s, m, and h. |
Examples
The following sample code shows how to write data by using the line protocol.
POST /api/v2/write?precision=ms
sensor,device_id=F07A1260,region=north-cn temperature=12.1,humidity=45 1619076780000
sensor,device_id=F07A1260,region=north-cn temperature=13.2,humidity=47 1619076790000
sensor,device_id=F07A1260,region=north-cn temperature=10.6,humidity=46 1619076800000
sensor,device_id=F07A1260,region=north-cn temperature=18.1,humidity=44 1619076780000
sensor,device_id=F07A1260,region=north-cn temperature=19.7,humidity=44 1619076790000