Documentation

使用行协议写入数据

使用行协议将数据写入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 - 秒

有关行协议的更多详情,请参阅行协议参考数据书写最佳实践



Flux的未来

Flux 正在进入维护模式。您可以像现在一样继续使用它,而无需对您的代码进行任何更改。

阅读更多

InfluxDB 3 开源版本现已公开Alpha测试

InfluxDB 3 Open Source is now available for alpha testing, licensed under MIT or Apache 2 licensing.

我们将发布两个产品作为测试版的一部分。

InfluxDB 3 核心,是我们新的开源产品。 它是一个用于时间序列和事件数据的实时数据引擎。 InfluxDB 3 企业版是建立在核心基础之上的商业版本,增加了历史查询能力、读取副本、高可用性、可扩展性和细粒度安全性。

有关如何开始的更多信息,请查看:

由TSM驱动的InfluxDB Cloud