Documentation

写入 Influx

influx write 命令通过 stdin 或指定文件将数据写入 InfluxDB。使用 行协议注释 CSV扩展注释 CSV 写入数据。如果您写入 CSV 数据,CSV 注释决定数据如何转换为行协议。

用法

influx write [flags]
influx write [command]

必需数据

要将数据写入InfluxDB,您必须为每一行提供以下内容:

  • 测量
  • 字段

行协议

行协议 中,行数据的结构 决定了测量、字段和数值。

带注释的CSV

带注释的CSV 中,测量、字段和数值由 _measurement_field_value 列表示。 它们的类型由CSV注释确定。 要成功将带注释的CSV写入InfluxDB,请包含所有 注释行

扩展注释的CSV

扩展注释的CSV 中,测量、字段、值及其类型由 CSV注释 决定。

子命令

子命令描述
dryrun写入标准输出而不是InfluxDB

标志

标志描述输入类型映射到 ?
-c--active-config用于命令的CLI配置string
-b--bucket存储桶名称(与 --bucket-id 互斥)字符串INFLUX_BUCKET_NAME
--bucket-id存储桶 ID(与 --bucket 互斥)字符串INFLUX_BUCKET_ID
--configs-path指向 influx CLI 配置的路径(默认 ~/.influxdbv2/configsstringINFLUX_CONFIGS_PATH
--compression输入压缩 (nonegzip,默认是 none,除非输入文件以 .gz 结尾。)string
--debug将错误输出到stderr
--encoding输入的字符编码(默认 UTF-8字符串
--errors-file用于记录被拒绝行错误的文件路径string
-f--file要导入的文件stringArray
--format输入格式 (lpcsv, 默认 lp)字符串
--header在CSV输入数据前添加标题行string
-h--help写入命令的帮助
--hostInfluxDB的HTTP地址(默认是 http://localhost:8086字符串INFLUX_HOST
--max-line-length单行可以读取的最大字节数(默认 16000000整数
-o--org组织名称(与 --org-id 互斥)字符串INFLUX_ORG
--org-id组织 ID(与 --org 互斥)字符串INFLUX_ORG_ID
-p--precision时间戳的精度(默认 ns字符串INFLUX_PRECISION
--rate-limit限制写入速率(示例: 5MB/5min1MB/s)。string
--skip-verify跳过TLS证书验证INFLUX_SKIP_VERIFY
--skipHeader跳过输入数据的前 n整数
--skipRowOnError将CSV错误输出到stderr,但继续处理
-t--tokenAPI令牌字符串INFLUX_TOKEN
-u--url从中导入数据的URLstringArray

示例

身份验证凭据

下面的示例假设您的 InfluxDB 主机组织令牌 是通过 活动 influx CLI 配置 或环境变量 (INFLUX_HOSTINFLUX_ORGINFLUX_TOKEN) 提供的。如果您没有设置 CLI 配置或环境变量,请在每个命令中使用以下标志包含这些必需的凭据:

  • --host: InfluxDB 主机
  • -o, --org--org-id: InfluxDB 组织名称或 ID
  • -t, --token: InfluxDB API 令牌
编写线协议
写入CSV数据

行协议

通过标准输入写入线协议
influx write --bucket example-bucket "
m,host=host1 field1=1.2,field2=5i 1640995200000000000
m,host=host2 field1=2.4,field2=3i 1640995200000000000
"
从文件写入线协议
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol.txt
跳过文件中的表头行
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol.txt
  --skipHeader 8
从多个文件写入线协议
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

CSV

通过标准输入写入注释的CSV数据
influx write \
  --bucket example-bucket \
  --format csv \
  "#group,false,false,false,false,true,true
#datatype,string,long,dateTime:RFC3339,double,string,string
#default,_result,,,,,
,result,table,_time,_value,_field,_measurement
,,0,2020-12-18T18:16:11Z,72.7,temp,sensorData
,,0,2020-12-18T18:16:21Z,73.8,temp,sensorData
,,0,2020-12-18T18:16:31Z,72.7,temp,sensorData
,,0,2020-12-18T18:16:41Z,72.8,temp,sensorData
,,0,2020-12-18T18:16:51Z,73.1,temp,sensorData
"
通过标准输入写入扩展注释的CSV数据
influx write \
  --bucket example-bucket \
  --format csv \
  "#constant measurement,sensorData
#datatype dateTime:RFC3339,double
time,temperature
2020-12-18T18:16:11Z,72.7
2020-12-18T18:16:21Z,73.8
2020-12-18T18:16:31Z,72.7
2020-12-18T18:16:41Z,72.8
2020-12-18T18:16:51Z,73.1
"
从文件中写入带注释的CSV数据
influx write \
  --bucket example-bucket \
  --file path/to/data.csv
从多个文件写入带注释的CSV数据
influx write \
  --bucket example-bucket \
  --file path/to/data-1.csv \
  --file path/to/data-2.csv
从URL写入带注释的CSV数据
influx write \
  --bucket example-bucket \
  --url https://example.com/data.csv
从多个URL写入带注释的CSV数据
influx write \
  --bucket example-bucket \
  --url https://example.com/data-1.csv \
  --url https://example.com/data-2.csv
从多个来源写入带注释的CSV数据
influx write \
  --bucket example-bucket \
  --file path/to/data-1.csv \
  --url https://example.com/data-2.csv
在CSV数据前添加注释标题
influx write \
  --bucket example-bucket \
  --header "#constant measurement,birds" \
  --header "#datatype dateTime:2006-01-02,long,tag" \
  --file path/to/data.csv
从压缩文件写入带注释的CSV数据
# The influx CLI assumes files with the .gz extension use gzip compression 
influx write \
  --bucket example-bucket \
  --file path/to/data.csv.gz

# Specify gzip compression for gzipped files without the .gz extension
influx write \
  --bucket example-bucket \
  --file path/to/data.csv.comp \
  --compression gzip
使用速率限制写入注释的CSV数据
influx write \
  --bucket example-bucket \
  --file path/to/data.csv \
  --rate-limit 5MB/5min


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