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的更改在重启之前不会生效。要立即更新值,请以根用户身份输入以下命令:
sysctl -w kern.ipc.maxsockbuf=30146560
使用 read-buffer 选项为 UDP 监听器
“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 的内容