InfluxDB 中 UDP 协议支持
此页面记录了早期版本的 InfluxDB OSS。InfluxDB OSS v2 是最新的稳定版本。请参阅 InfluxDB v2 文档。
UDP 输入
关于 UDP/IP 操作系统缓冲区大小的说明
某些操作系统(最值得注意的是 Linux)对 UDP 协议的性能施加了非常严格的限制。强烈建议您在尝试将 UDP 流量路由到您的实例之前,将这些操作系统限制增加到至少 25MB。25MB 只是一个建议,应根据您的 read-buffer
插件设置进行调整。
Linux
通过键入以下命令检查当前的 UDP/IP 接收缓冲区默认值和限制
sysctl net.core.rmem_max
sysctl net.core.rmem_default
如果值小于 26214400 字节 (25MB),您应该将以下行添加到 /etc/sysctl.conf
文件
net.core.rmem_max=26214400
net.core.rmem_default=26214400
对 /etc/sysctl.conf
的更改在重新启动之前不会生效。要立即更新这些值,请以 root 身份键入以下命令
sysctl -w net.core.rmem_max=26214400
sysctl -w net.core.rmem_default=26214400
BSD/Darwin
在 BSD/Darwin 系统上,您需要为内核限制套接字缓冲区添加大约 15% 的填充。例如,如果您想要一个 25MB 的缓冲区(26214400 字节),您需要将内核限制设置为 26214400*1.15 = 30146560
。这在任何地方都没有文档记录,但 内核代码在此处发生了这种情况。
检查当前的 UDP/IP 缓冲区限制
要检查当前的 UDP/IP 缓冲区限制,请键入以下命令
sysctl kern.ipc.maxsockbuf
如果该值小于 30146560 字节,您应该将以下行添加到 /etc/sysctl.conf
文件(必要时创建它)
kern.ipc.maxsockbuf=30146560
对 /etc/sysctl.conf
的更改在重新启动之前不会生效。要立即更新这些值,请以 root 身份键入以下命令
sysctl -w kern.ipc.maxsockbuf=30146560
为 UDP 监听器使用 read-buffer
选项
read-buffer
选项允许用户设置 UDP 监听器的缓冲区大小。它设置与 UDP 流量关联的操作系统接收缓冲区的大小。请记住,操作系统必须能够处理此处设置的数字,否则 UDP 监听器将出错并退出。
将 read-buffer = 0
设置为导致使用操作系统默认值,并且对于高 UDP 性能而言通常太小。
配置
每个 UDP 输入都允许设置绑定地址、目标数据库和目标保留策略。如果数据库不存在,则会在初始化输入时自动创建它。如果未配置保留策略,则使用数据库的默认保留策略。但是,如果设置了保留策略,则必须显式创建保留策略。输入不会自动创建它。
每个 UDP 输入还会对其接收的点执行内部批处理,因为对数据库进行批量写入效率更高。默认批处理大小为 1000,待处理批处理因子为 5,批处理超时为 1 秒。这意味着输入将写入最大大小为 1000 的批次,但如果一个批次在添加到批次的第一个点后的 1 秒内未达到 1000 个点,则无论大小如何,它都会发出该批次。待处理批处理因子控制可以同时在内存中存在的批次数量,允许输入在传输一个批次的同时,仍然构建其他批次。
处理
UDP 输入每次读取最多可以接收 64KB,并通过换行符拆分接收到的数据。然后将每个部分解释为行协议编码的点,并进行相应的解析。
UDP 是无连接的
由于 UDP 是一种无连接协议,因此无法向数据源发出信号,告知是否发生任何错误,以及数据是否已被成功索引。在决定是否以及何时使用 UDP 输入时,应牢记这一点。内置的 UDP 统计信息对于监控 UDP 输入非常有用。
配置示例
一个 UDP 监听器
# influxd.conf
...
[[udp]]
enabled = true
bind-address = ":8089" # the bind address
database = "telegraf" # Name of the database that will be written to
batch-size = 5000 # will flush if this many points get buffered
batch-timeout = "1s" # will flush at least this often even if the batch-size is not reached
batch-pending = 10 # number of batches that may be pending in memory
read-buffer = 0 # UDP read buffer, 0 means to use OS default
...
多个 UDP 监听器
# influxd.conf
...
[[udp]]
# Default UDP for Telegraf
enabled = true
bind-address = ":8089" # the bind address
database = "telegraf" # Name of the database that will be written to
batch-size = 5000 # will flush if this many points get buffered
batch-timeout = "1s" # will flush at least this often even if the batch-size is not reached
batch-pending = 10 # number of batches that may be pending in memory
read-buffer = 0 # UDP read buffer size, 0 means to use OS default
[[udp]]
# High-traffic UDP
enabled = true
bind-address = ":8189" # the bind address
database = "mymetrics" # Name of the database that will be written to
batch-size = 5000 # will flush if this many points get buffered
batch-timeout = "1s" # will flush at least this often even if the batch-size is not reached
batch-pending = 100 # number of batches that may be pending in memory
read-buffer = 8388608 # (8*1024*1024) UDP read buffer size
...
内容来自 README
此页是否对您有帮助?
感谢您的反馈!