/write 1.x 兼容性 API
该 /write 1.x 兼容性端点使用 InfluxDB 1.x /write API 端点的模式将数据写入 InfluxDB Cloud 和 InfluxDB OSS Cloud。使用 POST 请求方法将 行协议 写入 /write 端点。
POST http://localhost:8086/write
如果您有一个现有的存储桶不符合 database/retention-policy 命名规范,您 必须 手动创建一个数据库和保留策略映射 以便通过 /write 兼容 API 将数据写入该存储桶。
认证
请求体
将你的线协议包含在请求体中。 二进制编码线协议以防止意外格式化。下面的示例使用curl --data-binary标志来二进制编码线协议。
查询字符串参数
你
(可选) 用于验证请求的 InfluxDB Cloud username。 参见 查询字符串身份验证。
正义
(可选) InfluxDB Cloud API 令牌 用于验证请求。 参见 查询字符串身份验证。
数据库
(必填) 要写入数据的 数据库。 这映射到一个 InfluxDB 桶。 请参见 数据库和保留策略映射。
rp
写入数据的保留策略。 这映射到一个 InfluxDB 桶。 见 数据库和保留策略映射。
精度
行协议中Unix时间戳的精度。 默认是纳秒 (ns)。 可用的精度如下:
ns- 纳秒u或µ- 微秒ms- 毫秒s- 秒m- 分钟h- 小时
写示例
使用基本认证写入数据
使用令牌认证写入数据
curl --request POST http://localhost:8086/write?db=DATABASE_NAME \
--header "Authorization: Token API_TOKEN" \
--data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000"
将数据写入非默认保留策略
curl --request POST "http://localhost:8086/write?db=DATABASE_NAME&rp=RETENTION_POLICY" \
--header "Authorization: Token API_TOKEN" \
--data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000"
编写多行行协议
curl --request POST http://localhost:8086/write?db=DATABASE_NAME \
--header "Authorization: Token API_TOKEN" \
--data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000000000
measurement,host=host2 field1=14i,field2=12.7 1577836800000000000
measurement,host=host3 field1=5i,field2=6.8 1577836800000000000"
使用毫秒级Unix时间戳写入数据
curl --request POST "http://localhost:8086/write?db=DATABASE_NAME&precision=ms" \
--header "Authorization: Token API_TOKEN" \
--data-binary "measurement,host=host1 field1=2i,field2=2.0 1577836800000"
使用curl从文件写入数据
curl --request POST http://localhost:8086/write?db=DATABASE_NAME \
--header "Authorization: Token API_TOKEN" \
--data-binary @path/to/line-protocol.txt
替换以下内容:
DATABASE_NAME和RETENTION_POLICY: 你想要写入的 InfluxDB v2 桶的 数据库和保留策略映射 (DBRP)- }
exampleuser@influxdata.com: 您注册时使用的电子邮件地址 API_TOKEN: 你的 InfluxDB API 令牌