跳到主要内容
版本:Next
influxdbINPUTBUFFERPROCESSOROUTPUT

InfluxDB

InfluxDB 输出(Output)使用行协议(Line Protocol)将时间序列数据写入 InfluxDB 2.x。它将列映射为 tag 与 field,把每个输入批次作为一次行协议请求写入 InfluxDB;暂态失败(传输错误、429、5xx)按封顶指数退避重试,确定性 4xx 拒绝立即失败且缓冲行保留。

配置​

FieldTypeRequiredDefault描述
typestringyes—固定值 "influxdb"
urlstringyes—InfluxDB 服务器 URL(例如 http://localhost:8086)。
orgstringyes—组织名称。
bucketstringyes—目标存储桶(bucket)。
tokenstringyes—认证令牌。
measurementstringyes—测量(measurement)名称。
tagsarray<object>no—标签(tag)映射(带索引的字段)。
fieldsarray<object>yes—字段(field)映射(值字段)。
timestamp_fieldstringno—数据点时间戳(纳秒)的源列。默认为当前时间。
batch_sizeintegerno—为兼容性接受,但当前无效:每个输入批次都会同步刷新为一次请求,批次从不拆分。唯一被校验的规则是拒绝 0。
flush_intervalintegerno—当前未被使用——schema 中有定义,但实现从不读取。
retry_countintegerno3每次刷新的 HTTP 尝试总次数(总尝试数,非重试次数)。
timeout_msintegerno5000HTTP 请求超时时间(毫秒)。

tags[]​

FieldTypeRequiredDefault描述
fieldstringyes—消息批次中的源列名。
tag_namestringyes—写入 InfluxDB 的 tag 名称。

fields[]​

FieldTypeRequiredDefault描述
fieldstringyes—消息批次中的源列名。
field_namestringyes—写入 InfluxDB 的 field 名称。
field_typestringnostringfloat、integer、boolean、string 之一。

示例​

基础 InfluxDB 输出​

output:
type: "influxdb"
url: "http://localhost:8086"
org: "my-org"
bucket: "sensor-data"
token: "${INFLUXDB_TOKEN}"
measurement: "temperature"
fields:
- field: "temp"
field_name: "value"
field_type: "float"

使用 tag 与时间戳​

output:
type: "influxdb"
url: "http://localhost:8086"
org: "production"
bucket: "metrics"
token: "${INFLUXDB_TOKEN}"
measurement: "system_metrics"
tags:
- field: "hostname"
tag_name: "host"
- field: "region"
tag_name: "region"
fields:
- field: "cpu_percent"
field_name: "cpu_usage"
field_type: "float"
- field: "memory_mb"
field_name: "memory_usage"
field_type: "integer"
- field: "status_message"
field_name: "status"
field_type: "string"
timestamp_field: "timestamp"

使用重试​

output:
type: "influxdb"
url: "https://influxdb.example.com:8086"
org: "enterprise"
bucket: "telemetry"
token: "${INFLUXDB_TOKEN}"
measurement: "iot_readings"
tags:
- field: "device_type"
tag_name: "device_type"
fields:
- field: "temp"
field_name: "temperature"
field_type: "float"
- field: "battery"
field_name: "battery_level"
field_type: "integer"
timestamp_field: "event_time"
retry_count: 5
timeout_ms: 10000

注意事项​

  • measurement、tag 与 field 标识符会自动按行协议规则转义。
  • 省略 field_type 时,该字段按字符串 field 处理。
  • 重试采用共享的封顶指数退避,起始间隔 100 毫秒(延迟封顶 5 秒;任意 retry_count 配置都不会溢出)。
  • 暂态失败——传输错误、429、5xx 响应——会被重试;其他 4xx 响应(token 错误、bucket 不存在等)首次尝试即失败且缓冲行保留,确定性拒绝不消耗重试预算。