文档文档

influx write

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

用法

influx write [flags]
influx write [command]

必需数据

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

  • measurement(测量)
  • field(字段)
  • value(值)

行协议

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

带注释的 CSV

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

扩展的带注释的 CSV

扩展的带注释的 CSV 中,measurement(测量)、field(字段)和 value(值)及其类型由 CSV 注释 确定。

子命令

子命令描述
dryrun写入 stdout 而不是 InfluxDB

标志

标志描述输入类型映射到 ?
-c--active-config用于命令的 CLI 配置字符串
-b--bucket存储桶名称(与 --bucket-id 互斥)字符串INFLUX_BUCKET_NAME
--bucket-id存储桶 ID(与 --bucket 互斥)字符串INFLUX_BUCKET_ID
--configs-pathinflux CLI 配置的路径(默认为 ~/.influxdbv2/configs字符串INFLUX_CONFIGS_PATH
--compression输入压缩(nonegzip,默认为 none,除非输入文件以 .gz 结尾。)字符串
--debug将错误输出到 stderr
--encoding输入的字符编码(默认为 UTF-8字符串
--errors-file用于记录拒绝行错误的文件路径字符串
-f--file要导入的文件字符串数组
--format输入格式(lpcsv,默认为 lp字符串
--header将标头行添加到 CSV 输入数据字符串
-h--helpwrite 命令的帮助
--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)。字符串
--skip-verify跳过 TLS 证书验证INFLUX_SKIP_VERIFY
--skipHeader跳过输入数据的前 n整数
--skipRowOnError将 CSV 错误输出到 stderr,但继续处理
-t--tokenAPI 令牌字符串INFLUX_TOKEN
-u--url要从中导入数据的 URL字符串数组

示例

身份验证凭据

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

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

行协议

通过 stdin 写入行协议
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

通过 stdin 写入带注释的 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
"
通过 stdin 写入扩展的带注释的 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 Core 和 Enterprise

快速启动。更快扩展。

获取更新

InfluxDB 3 Core 是一个开源、高速、最近数据引擎,可实时收集和处理数据,并将其持久化到本地磁盘或对象存储。InfluxDB 3 Enterprise 以 Core 的基础为构建,增加了高可用性、读取副本、增强的安全性以及数据压缩,从而实现更快的查询和优化的存储。InfluxDB 3 Enterprise 的免费层级可供非商业家庭或业余爱好者使用。

有关更多信息,请查看