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-path | influx CLI 配置的路径(默认为 ~/.influxdbv2/configs ) | 字符串 | INFLUX_CONFIGS_PATH | |
--compression | 输入压缩(none 或 gzip ,默认为 none ,除非输入文件以 .gz 结尾。) | 字符串 | ||
--debug | 将错误输出到 stderr | |||
--encoding | 输入的字符编码(默认为 UTF-8 ) | 字符串 | ||
--errors-file | 用于记录拒绝行错误的文件路径 | 字符串 | ||
-f | --file | 要导入的文件 | 字符串数组 | |
--format | 输入格式(lp 或 csv ,默认为 lp ) | 字符串 | ||
--header | 将标头行添加到 CSV 输入数据 | 字符串 | ||
-h | --help | write 命令的帮助 | ||
--host | InfluxDB 的 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/5min 或 1MB/s )。 | 字符串 | ||
--skip-verify | 跳过 TLS 证书验证 | INFLUX_SKIP_VERIFY | ||
--skipHeader | 跳过输入数据的前 n 行 | 整数 | ||
--skipRowOnError | 将 CSV 错误输出到 stderr,但继续处理 | |||
-t | --token | API 令牌 | 字符串 | INFLUX_TOKEN |
-u | --url | 要从中导入数据的 URL | 字符串数组 |
示例
身份验证凭据
以下示例假定您的 InfluxDB 主机、组织和 令牌 由 活动的 influx
CLI 配置 或环境变量(INFLUX_HOST
、INFLUX_ORG
和 INFLUX_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
此页是否对您有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一份子!我们欢迎并鼓励您对 InfluxDB 和本文档提出反馈和错误报告。要获得支持,请使用以下资源
拥有年度合同或支持合同的客户 可以 联系 InfluxData 支持。