This topic describes how to write data to LindormTSDB using the InfluxDB line protocol and provides examples.
Background information
LindormTSDB is compatible with the format defined by the InfluxDB line protocol. For more information, see Line Protocol. You can use applications or devices that support the InfluxDB line protocol to write data to LindormTSDB.
Supported data types
The syntax of the InfluxDB line protocol supports the following data types: Float, Integer, String, Boolean, and Timestamp. The following table describes the data types supported by the InfluxDB line protocol.
Data type | Description |
Float | Floating-point numbers. Float is the default data type. Example: 1, 1.0, 1.e+10, and 1.E+10. |
Integer | Supports 64-bit integers. Use the `i` suffix to identify integers. Numbers without a suffix are parsed as floating-point numbers. For example: 12i and 101i. |
String | String type. Use double quotation marks (""). For example: "hello world". |
Boolean | Boolean values. Valid values: True and False.
|
Timestamp | Timestamp. The protocol supports nanoseconds (ns), but data is converted to milliseconds (ms) for storage. To change the timestamp precision, set the precision parameter. |
Request path
Request path: /api/v2/write
Request method: POST
When you create a request to write data points to LindormTSDB using the InfluxDB line protocol, you must change the format of the data points to the format defined by the InfluxDB line protocol and then use the data points as the body of the POST request. The following table describes the parameters that you can configure in a request.
Parameter | Required | Description |
precision | No | The precision of timestamps. Default value: ns. Valid values: ns, us, ms, s, m, and h. |
db | No | The name of the database to which you want to write data points. |
schema_policy | No | The constraint policy for the schema. The default value of this parameter is WEAK. If you specify a weak constraint policy, time series tables can be automatically created. Valid values:
For more information, see Supported schema constraint policies. |
Specify user credentials for authentication
If user authentication is enabled for LindormTSDB, you must add user credentials to the HTTP request header when you send requests to /api/v2/write. The /api/v2/write endpoint uses the BASIC AUTH method. The encoded credentials must be included in the Authorization field of the HTTP request header.
You can specify user credentials in the following format for basic authentication:
BASIC {Base64-encoded authentication information}The Base64-encoded authentication information is a Base64-encoded string in the format ${username}:${password}.
For more information about how to encode and specify user credentials for basic authentication using different programming languages, see the documentation for relevant class libraries of the programming languages.
For the default username `root` and password `root`, the Base64-encoded value for the Authorization field in the HTTP request header is as follows:
Authorization: Basic cm9vdDpyb290Data format of the InfluxDB line protocol
The following describes the write format and parameters for Line Protocol.
<table_name>[,<tag_key>=<tag_value>[,<tag_key>=<tag_value>]] <field_key>=<field_value>[,<field_key>=<field_value>] [<timestamp>] Parameter | Required | Description |
table_name | Yes | The name of the table to which you want to write data points. |
tag_set | No | The tags of the data point that you want to write. The tags can be used to search written data points. |
field_set | Yes | The field of data point that you want to write. |
timestamp | No | The timestamp. If you do not specify a timestamp, the system uses the current time. The default unit is nanoseconds (ns). Important
|
Separate multiple data points with a line feed (
\n).When you use the InfluxDB line protocol to write data points to LindormTSDB, the schema constraints used by the engine are weak constraints. You can configure the schema_policy parameter to modify the constraint policy of the schema.
Examples
The following statements provide an example on how to write data to LindormTSDB using the InfluxDB line protocol:
curl -X POST \
'http://ld-bp1489gr5t*****-proxy-tsdb.lindorm.rds.aliyuncs.com:8242/api/v2/write?precision=ms&db=default' \
-d '
sensor7,device_id=F07A1260,region=north-cn temperature=12.1,humidity=45i 1619076780000000000
sensor7,device_id=F07A1260,region=north-cn temperature=13.2,humidity=47i 1619076790000000000
sensor7,device_id=F07A1260,region=north-cn temperature=10.6,humidity=46i 1619076800000000000
sensor7,device_id=F07A1260,region=north-cn temperature=18.1,humidity=44i 1619076780000000000
sensor7,device_id=F07A1260,region=north-cn temperature=19.7,humidity=44i 1619076790000000000
'