Iptables 输入插件
此插件从 Linux 的 iptables 防火墙中,收集一组表和链中规则的数据包和字节计数器。
规则通过关联的注释进行标识,因此您必须确保要监控的规则在添加时使用了 --comment 标志具有**唯一**的注释。没有注释的规则将被忽略。
规则编号不能用作标识符,因为它不是恒定的,并且在启动时插入/删除规则时可能会有所不同(或由自动工具(交互式防火墙、fail2ban 等)更改)。
iptables 命令需要 CAP_NET_ADMIN 和 CAP_NET_RAW 能力。请查看权限部分以获取授予这些能力的途径。
引入于: Telegraf v1.1.0 标签: network, system 操作系统支持: linux
全局配置选项
插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md。
配置
# Gather packets and bytes throughput from iptables
# This plugin ONLY supports Linux
[[inputs.iptables]]
## iptables require root access on most systems.
## Setting 'use_sudo' to true will make use of sudo to run iptables.
## Users must configure sudo to allow telegraf user to run iptables with
## no password.
## iptables can be restricted to only list command "iptables -nvL".
# use_sudo = false
## Setting 'use_lock' to true runs iptables with the "-w" option.
## Adjust your sudo settings appropriately if using this option
## ("iptables -w 5 -nvl")
# use_lock = false
## Define an alternate executable, such as "ip6tables". Default is "iptables".
# binary = "ip6tables"
## defines the table to monitor:
table = "filter"
## defines the chains to monitor.
## NOTE: iptables rules without a comment will not be monitored.
## Read the plugin documentation for more information.
chains = [ "INPUT" ]权限
iptables 命令需要 CAP_NET_ADMIN 和 CAP_NET_RAW capability。您有几种选项可以授予 telegraf 权限
- 以 root 用户运行 telegraf。这强烈不推荐。
- 配置 systemd 以 CAP_NET_ADMIN 和 CAP_NET_RAW 运行 telegraf。这是最简单且推荐的选项。
- 配置 sudo 以允许 telegraf 运行 iptables。这是最严格的选项,但需要 sudo 设置。
使用 systemd 功能
您可以运行 systemctl edit telegraf.service 并添加以下内容
[Service]
CapabilityBoundingSet=CAP_NET_RAW CAP_NET_ADMIN
AmbientCapabilities=CAP_NET_RAW CAP_NET_ADMIN由于 telegraf 将fork一个进程来运行 iptables,AmbientCapabilities 是必需的,以便将 capabilities bounding set 传递给fork的进程。
使用 sudo
要使用 sudo,请将 use_sudo 选项设置为 true 并更新您的 sudoers 文件
$ visudo
# Add the following line:
Cmnd_Alias IPTABLESSHOW = /usr/bin/iptables -nvL *
telegraf ALL=(root) NOPASSWD: IPTABLESSHOW
Defaults!IPTABLESSHOW !logfile, !syslog, !pam_session使用 IPtables 锁功能
在 telegraf.conf 中定义此插件的多个实例可能导致并发 IPtables 访问,从而在 telegraf.log 中出现“ERROR in input [inputs.iptables]: exit status 4”消息,并且指标丢失。在插件配置中设置 ‘use_lock = true’ 将使用 ‘-w’ 开关运行 IPtables,允许使用锁来防止此错误。
Metrics
- iptables
- 标签 (tags)
- table
- chain
- ruleid (与规则关联的注释)
- 字段 (fields)
- pkts (整数, 计数)
- bytes (整数, 字节)
- 标签 (tags)
示例输出
iptables -nvL INPUTChain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
100 1024 ACCEPT tcp -- * * 192.168.0.0/24 0.0.0.0/0 tcp dpt:22 /* ssh */
42 2048 ACCEPT tcp -- * * 192.168.0.0/24 0.0.0.0/0 tcp dpt:80 /* httpd */iptables,table=filter,chain=INPUT,ruleid=ssh pkts=100i,bytes=1024i 1453831884664956455
iptables,table=filter,chain=INPUT,ruleid=httpd pkts=42i,bytes=2048i 1453831884664956455此页面是否有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一员!我们欢迎并鼓励您对 Telegraf 和本文档提出反馈和 bug 报告。要获取支持,请使用以下资源
具有年度合同或支持合同的客户可以 联系 InfluxData 支持。