目录
Telegraf Socket Listener 输入插件是一个服务输入插件,用于监听来自 TCP 或 Unix 等流协议以及 UDP 或 unixgram 等数据报协议的消息。
与常见的网络协议相比,使用 Unix 套接字的主要优势在于性能提升。开销更少,同一主机上的两个进程可以通过内核交换数据。使用 TCP 或 UDP 等网络协议将通过环回网络接口发送数据,这需要更多的时间和资源。如果您主要在本地发送数据,那么使用 Socket Listener Telegraf 输入插件是一个好主意。
为什么要使用 Socket Listener Telegraf 输入插件?
您想要使用套接字监听器插件的主要原因是它为您提供了发送数据到 Telegraf 的巨大灵活性。它支持所有最流行的网络协议和纯 Unix 套接字,这意味着您可以使用几乎任何支持创建套接字的编程语言来编写数据。这使得套接字监听器插件非常适合快速测试和长期生产解决方案。
一旦您的数据被发送到 Telegraf,您可以将该数据输出到许多不同的数据存储。虽然 Telegraf 最适合 InfluxDB,但您也可以输出到许多其他流行的数据库,或者配置 Telegraf 同时将指标存储在多个数据存储中。
如何使用 Telegraf 插件监控 Socket Listener
设置 Socket Listener Telegraf 输入插件很简单,但也有大量的可用选项使其对您的用例非常灵活
# Generic socket listener capable of handling multiple socket types. [[inputs.socket_listener]] ## URL to listen on # service_address = "tcp://:8094" # service_address = "tcp://127.0.0.1:http" # service_address = "tcp4://:8094" # service_address = "tcp6://:8094" # service_address = "tcp6://[2001:db8::1]:8094" # service_address = "udp://:8094" # service_address = "udp4://:8094" # service_address = "udp6://:8094" # service_address = "unix:///tmp/telegraf.sock" # service_address = "unixgram:///tmp/telegraf.sock" ## Change the file mode bits on unix sockets. These permissions may not be ## respected by some platforms, to safely restrict write permissions it is best ## to place the socket into a directory that has previously been created ## with the desired permissions. ## ex: socket_mode = "777" # socket_mode = "" ## Maximum number of concurrent connections. ## Only applies to stream sockets (e.g. TCP). ## 0 (default) is unlimited. # max_connections = 1024 ## Read timeout. ## Only applies to stream sockets (e.g. TCP). ## 0 (default) is unlimited. # read_timeout = "30s" ## Optional TLS configuration. ## Only applies to stream sockets (e.g. TCP). # tls_cert = "/etc/telegraf/cert.pem" # tls_key = "/etc/telegraf/key.pem" ## Enables client authentication if set. # tls_allowed_cacerts = ["/etc/telegraf/clientca.pem"] ## Maximum socket buffer size (in bytes when no unit specified). ## For stream sockets, once the buffer fills up, the sender will start backing up. ## For datagram sockets, once the buffer fills up, metrics will start dropping. ## Defaults to the OS default. # read_buffer_size = "64KiB" ## Period between keep alive probes. ## Only applies to TCP sockets. ## 0 disables keep alive probes. ## Defaults to the OS configuration. # keep_alive_period = "5m" ## Data format to consume. ## Each data format has its own unique set of configuration options, read ## more about them here: ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md # data_format = "influx" ## Content encoding for message payloads, can be set to "gzip" to or ## "identity" to apply no encoding. # content_encoding = "identity"
The read_buffer_size
config option can be used to adjust the size of the socket buffer, but this number is limited by OS settings. On Linux, read_buffer_size
will default to rmem_default
and will be capped by rmem_max
. On BSD systems, read_buffer_size
is capped by maxsockbuf
, and there is no OS default setting.
有关特定于操作系统的设置说明和注意事项,请单击下面的项目 URL 按钮。
用于监控的关键 Socket Listener 指标
由于套接字的灵活性,您可以定义通过 Socket Listener Telegraf 输入插件发送的指标。这可以是来自简单脚本或复杂应用程序的数据。