套接字监听器监控
免费使用此InfluxDB集成Telegraf套接字监听器输入插件是一个服务输入插件,它监听来自流协议的消息,如TCP或Unix,以及数据报协议,如UDP或unixgram。
使用Unix套接字而非常见网络协议的主要优点是性能提升。开销更小,同一主机上的两个进程可以通过内核交换数据。使用TCP或UDP等网络协议将数据通过网络接口循环发送,这需要更多的时间和资源。如果您主要发送本地数据,使用Socket Listener Telegraf输入插件是个好主意。
为什么使用Socket Listener Telegraf输入插件?
您想使用套接字监听器插件的主要原因是它为您提供了如何将数据发送到Telegraf的巨大灵活性。它支持所有最流行的网络协议和平常的Unix套接字,这意味着您可以使用几乎任何支持创建套接字的语言编写数据。这使得套接字监听器插件非常适合快速测试和长期生产解决方案。
一旦数据被发送到Telegraf,您可以将这些数据输出到多种不同的数据存储库。虽然Telegraf与InfluxDB配合最好,但您也可以输出到许多其他流行的数据库,或将Telegraf配置为同时存储多个数据存储库中的指标。
如何使用Telegraf插件监控套接字监听器
设置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"
可以使用read_buffer_size
配置选项来调整套接字缓冲区的大小,但这个数字受操作系统设置的限制。在Linux上,read_buffer_size
将默认为rmem_default
,并将由rmem_max
限制。在BSD系统上,read_buffer_size
受maxsockbuf
限制,且没有操作系统默认设置。
有关某些特定于操作系统的设置说明和注意事项,请单击下面的项目URL按钮。
用于监控的关键套接字监听器指标
由于套接字的灵活性,您可以定义通过Socket Listener Telegraf输入插件发送的指标。这可以是来自简单脚本或复杂应用的数据。