This topic describes how to write data to LindormTSDB by 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 | 64-bit integers. You must append a letter i to the end of a number to specify that the number is an integer. Example: 12i and 101i. |
String | Strings. Strings must be enclosed in double quotation marks (""). Example: "hello world". |
Boolean | Boolean values. Valid values: True and False.
|
Timestamp | Timestamps. The InfluxDB line protocol supports timestamps in nanoseconds. However, timestamps are converted and stored in milliseconds when they are stored in LindormTSDB. You can configure the precision parameter to change the precision of timestamps. |
Request path
Request path: /api/v2/write
Request method: POST
When you create a request to write data points to LindormTSDB by 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 include the authentication information of the user in the HTTP request headers when you use the /api/v2/write
API to send SQL queries. The /api/v2/write
API uses the BASIC AUTH
method. The encoded authentication information must be specified 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 in the following format: ${username}:${password}
. The username and password are separated by a colon (:).
For more information about how to encode and specify user credentials for basic authentication by using different programming languages, see the documentation for relevant class libraries of the programming languages.
For example, if you use the default username and password (which are both root) as the credential for basic authentication, the Base64-encoded value of the Authorization
field in the HTTP header is Basic cm9vdDpyb290, as shown in the following example:
Authorization: Basic cm9vdDpyb290
Data format of the InfluxDB line protocol
You can use the InfluxDB line protocol to write data to LindormTSDB in the following format:
<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 of the data point that you want to write. By default, the current time is specified. Default unit: nanoseconds. Note You can configure the precision parameter to change the precision of timestamps. |
Separate multiple data points with line feeds (
\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 by 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=45 1619076780000
sensor7,device_id=F07A1260,region=north-cn temperature=13.2,humidity=47 1619076790000
sensor7,device_id=F07A1260,region=north-cn temperature=10.6,humidity=46 1619076800000
sensor7,device_id=F07A1260,region=north-cn temperature=18.1,humidity=44 1619076780000
sensor7,device_id=F07A1260,region=north-cn temperature=19.7,humidity=44 1619076790000
'