使用行协议写入数据
使用行协议将数据写入InfluxDB Cloud。行协议是一种基于文本的格式,提供数据点的测量值、标签集、字段集和时间戳。了解更多关于行协议的信息。
使用以下方法通过行协议写入数据:
使用influx写入命令编写线协议
使用 influx write 命令 以行协议将数据写入 InfluxDB。使用 -f 标志设置行协议文件的路径。验证您的行协议是否遵循正确的 行协议格式 规范。
示例写入命令
influx write -b example-bucket -f path/to/example.txt
行协议格式
mem,host=host1 used_percent=64.23 1577836800000000000
mem,host=host2 used_percent=72.01 1577836800000000000
mem,host=host1 used_percent=62.61 1577836810000000000
mem,host=host2 used_percent=72.98 1577836810000000000
mem,host=host1 used_percent=63.40 1577836820000000000
mem,host=host2 used_percent=73.77 1577836820000000000
行协议数据看起来像这样:
mem,host=host1 used_percent=23.43234543 1556892576842902000
cpu,host=host1 usage_user=3.8234,usage_system=4.23874 1556892726597397000
mem,host=host1 used_percent=21.83599203 1556892777007291000
编写线协议
通过标准输入写入线协议
influx write --bucket example-bucket "
m,host=host1 field1=1.2
m,host=host2 field1=2.4
m,host=host1 field2=5i
m,host=host2 field2=3i
"
从文件写入线协议
influx write \
--bucket example-bucket \
--file path/to/line-protocol.txt
从多个文件写入线协议
influx write \
--bucket example-bucket \
--file path/to/line-protocol-1.txt \
--file path/to/line-protocol-2.txt
从URL写入线协议
influx write \
--bucket example-bucket \
--url https://example.com/line-protocol.txt
从多个URL写入线协议
influx write \
--bucket example-bucket \
--url https://example.com/line-protocol-1.txt \
--url https://example.com/line-protocol-2.txt
从多个源写入行协议
influx write \
--bucket example-bucket \
--file path/to/line-protocol-1.txt \
--url https://example.com/line-protocol-2.txt
从压缩文件中写入线协议
# The influx CLI assumes files with the .gz extension use gzip compression
influx write \
--bucket example-bucket \
--file path/to/line-protocol.txt.gz
# Specify gzip compression for gzipped files without the .gz extension
influx write \
--bucket example-bucket \
--file path/to/line-protocol.txt.comp \
--compression gzip
InfluxDB Cloud限制未压缩的写请求有效负载为250 MB。当250 MB未压缩并写入后,剩余的行将不被写入,调用者将收到413响应。
我们建议调用者使用较小的未压缩有效负载重试请求。
时间戳精度
在将数据写入InfluxDB时,我们 建议为每个点包含一个时间戳。 如果数据点在被数据库接收时不包含时间戳,InfluxDB将使用其主机的当前系统时间(UTC)。
时间戳的默认精度是纳秒。如果时间戳的精度不是纳秒 (ns),你必须 在写请求中指定精度。InfluxDB 接受以下精度:
ns- 纳秒us- 微秒ms- 毫秒s- 秒