SNMP 输入插件
此插件通过轮询具有单个 OID 或完整 SNMP 表的 SNMP 代理来收集指标。
路径设置在所有 SNMP 插件类型的实例之间共享!
引入于: Telegraf v0.10.1 标签: hardware, network 操作系统支持: all
全局配置选项
插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md。
Secret-store 支持
此插件支持从 secret-stores 获取 auth_password 和 priv_password 选项的 secret。有关如何使用它们的更多详细信息,请参阅 secret-store 文档。
配置
# Retrieves SNMP values from remote agents
[[inputs.snmp]]
## Agent addresses to retrieve values from.
## format: agents = ["<scheme://><hostname>:<port>"]
## scheme: optional, either udp, udp4, udp6, tcp, tcp4, tcp6.
## default is udp
## port: optional
## example: agents = ["udp://127.0.0.1:161"]
## agents = ["tcp://127.0.0.1:161"]
## agents = ["udp4://v4only-snmp-agent"]
agents = ["udp://127.0.0.1:161"]
## Timeout for each request.
# timeout = "5s"
## Stop polling tables if polling fails on the same agent
# stop_on_error = false
## SNMP version; can be 1, 2, or 3.
# version = 2
## Unconnected UDP socket
## When true, SNMP responses are accepted from any address not just
## the requested address. This can be useful when gathering from
## redundant/failover systems.
# unconnected_udp_socket = false
## Path to mib files
## Used by the gosmi translator.
## To add paths when translating with netsnmp, use the MIBDIRS environment variable
# path = ["/usr/share/snmp/mibs"]
## SNMP community string.
# community = "public"
## Agent host tag; should be set to "source" for consistent usage across plugins
## example: agent_host_tag = "source"
## The default value is inconsistent with other plugins. Users will get a
## warning that can be ignored if this is not changed. However, to have a
## consistent experience, set this to "source" in your config to align with
## other plugins.
# agent_host_tag = "agent_host"
## Number of retries to attempt.
# retries = 3
## The GETBULK max-repetitions parameter.
# max_repetitions = 10
## SNMPv3 authentication and encryption options.
##
## Security Name.
# sec_name = "myuser"
## Authentication protocol; one of "MD5", "SHA", "SHA224", "SHA256", "SHA384", "SHA512" or "".
# auth_protocol = "MD5"
## Authentication password.
# auth_password = "pass"
## Security Level; one of "noAuthNoPriv", "authNoPriv", or "authPriv".
# sec_level = "authNoPriv"
## Context Name.
# context_name = ""
## Privacy protocol used for encrypted messages; one of "DES", "AES", "AES192", "AES192C", "AES256", "AES256C", or "".
### Protocols "AES192", "AES192", "AES256", and "AES256C" require the underlying net-snmp tools
### to be compiled with --enable-blumenthal-aes (http://www.net-snmp.org/docs/INSTALL.html)
# priv_protocol = ""
## Privacy password used for encrypted messages.
# priv_password = ""
## Add fields and tables defining the variables you wish to collect. This
## example collects the system uptime and interface variables. Reference the
## full plugin documentation for configuration details.
[[inputs.snmp.field]]
oid = "RFC1213-MIB::sysUpTime.0"
name = "sysUptime"
conversion = "float(2)"
[[inputs.snmp.field]]
oid = "RFC1213-MIB::sysName.0"
name = "sysName"
is_tag = true
[[inputs.snmp.table]]
oid = "IF-MIB::ifTable"
name = "interface"
inherit_tags = ["sysName"]
[[inputs.snmp.table.field]]
oid = "IF-MIB::ifDescr"
name = "ifDescr"
is_tag = trueSNMP 后端:gosmi vs netsnmp
此插件支持两个后端来翻译 SNMP 对象。默认情况下,Telegraf 将使用 netsnmp,但此选项已弃用,鼓励迁移到 gosmi。如果用户发现 gosmi 与 netsnmp 存在相同的问题,请在 GitHub 上提出项目 issue。
SNMP 后端设置是全局设置,适用于 Telegraf 中所有 SNMP 用途。用户可以在 [agent] 配置中通过 snmp_translator 选项设置此选项。有关更多详细信息,请参阅 agent 配置。
配置 SNMP 请求
此插件提供两种配置 SNMP 请求的方法:fields 和 tables。使用 field 选项收集单个临时变量。要收集 SNMP 表,请使用 table 选项。
字段
使用 field 通过 OID 收集变量。使用此选项指定的请求的操作方式类似于 snmpget 实用程序。
[[inputs.snmp]]
# ... snip ...
[[inputs.snmp.field]]
## Object identifier of the variable as a numeric or textual OID.
oid = "RFC1213-MIB::sysName.0"
## Name of the field or tag to create. If not specified, it defaults to
## the value of 'oid'. If 'oid' is numeric, an attempt to translate the
## numeric OID into a textual OID will be made.
# name = ""
## If true the variable will be added as a tag, otherwise a field will be
## created.
# is_tag = false
## Apply one of the following conversions to the variable value:
## float(X): Convert the input value into a float and divides by the
## Xth power of 10. Effectively just moves the decimal left
## X places. For example a value of `123` with `float(2)`
## will result in `1.23`.
## float: Convert the value into a float with no adjustment. Same
## as `float(0)`.
## int: Convert the value into an integer.
## ipaddr: Convert the value to an IP address.
## hex: Convert bytes to a hex string.
## hextoint:X:Y Convert bytes to integer, where X is the endian and Y the
## bit size. For example: hextoint:LittleEndian:uint64 or
## hextoint:BigEndian:uint32. Valid options for the endian
## are: BigEndian and LittleEndian. For the bit size:
## uint16, uint32 and uint64.
## enum: Convert the value according to its syntax in the MIB.
## (Only supported with gosmi translator)
## displayhint: Format the value according to the textual convention in the MIB.
## (Only supported with gosmi translator)
##
# conversion = ""表
使用 table 配置 SNMP 表的收集。使用此选项形成的 SNMP 请求的操作方式类似于 snmptable 命令。
通过嵌套的 field 控制特定表列的处理。这些嵌套字段的指定方式与顶级 field 类似。
默认情况下,将收集 SNMP 表的所有列 - 无需为每列添加嵌套字段,只需添加您希望修改的列。要仅收集某些列,请在 table 部分省略 oid,仅在 field 部分包含 oid 设置。有关更复杂的列包含/排除情况,请使用 metric filtering。
为 SNMP 表的每一行创建一个指标。
[[inputs.snmp]]
# ... snip ...
[[inputs.snmp.table]]
## Object identifier of the SNMP table as a numeric or textual OID.
oid = "IF-MIB::ifTable"
## Name of the field or tag to create. If not specified, it defaults to
## the value of 'oid'. If 'oid' is numeric an attempt to translate the
## numeric OID into a textual OID will be made.
# name = ""
## Which tags to inherit from the top-level config and to use in the output
## of this table's measurement.
## example: inherit_tags = ["source"]
# inherit_tags = []
## Add an 'index' tag with the table row number. Use this if the table has
## no indexes or if you are excluding them. This option is normally not
## required as any index columns are automatically added as tags.
# index_as_tag = false
[[inputs.snmp.table.field]]
## OID to get. May be a numeric or textual module-qualified OID.
oid = "IF-MIB::ifDescr"
## Name of the field or tag to create. If not specified, it defaults to
## the value of 'oid'. If 'oid' is numeric an attempt to translate the
## numeric OID into a textual OID will be made.
# name = ""
## Output this field as a tag.
# is_tag = false
## The OID sub-identifier to strip off so that the index can be matched
## against other fields in the table.
# oid_index_suffix = ""
## Specifies the length of the index after the supplied table OID (in OID
## path segments). Truncates the index after this point to remove non-fixed
## value or length index suffixes.
# oid_index_length = 0
## Specifies if the value of given field should be snmptranslated
## by default no field values are translated
# translate = true
## Secondary index table allows to merge data from two tables with
## different index that this filed will be used to join them. There can
## be only one secondary index table.
# secondary_index_table = false
## This field is using secondary index, and will be later merged with
## primary index using SecondaryIndexTable. SecondaryIndexTable and
## SecondaryIndexUse are exclusive.
# secondary_index_use = false
## Controls if entries from secondary table should be added or not
## if joining index is present or not. I set to true, means that join
## is outer, and index is prepended with "Secondary." for missing values
## to avoid overlapping indexes from both tables. Can be set per field or
## globally with SecondaryIndexTable, global true overrides per field false.
# secondary_outer_join = false两个表的连接
Snmp 插件可以连接两个具有不同索引的 snmp 表。要实现这一点,一个表应该有一个返回第二个表索引作为值的转换字段。此类字段的示例包括:
- Cisco portTable 及其转换字段:
CISCO-STACK-MIB::portIfIndex,其值为 ifTable 中的 IfIndex - Adva entityFacilityTable 及其转换字段:
ADVA-FSPR7-MIB::entityFacilityOneIndex,其值为 ifTable 中的 IfIndex - Cisco cpeExtPsePortTable 及其转换字段:
CISCO-POWER-ETHERNET-EXT-MIB::cpeExtPsePortEntPhyIndex,其值为 entPhysicalTable 中的索引
可以使用此类字段通过 secondary_index_table = true 将索引转换为第二个表,并且第二个表中的所有字段(以及由转换字段指向的索引)都应添加 secondary_index_use = true 选项。Telegraf 在连接时不能重复条目,因此转换必须是 1 对 1 的(不是 1 对多)。要添加第二个表中具有在转换表中不存在的索引的字段(外连接),还有一个用于转换索引的选项 secondary_outer_join = true。
表连接的示例配置
CISCO-POWER-ETHERNET-EXT-MIB 表连接前
[[inputs.snmp.table]]
name = "ciscoPower"
index_as_tag = true
[[inputs.snmp.table.field]]
name = "PortPwrConsumption"
oid = "CISCO-POWER-ETHERNET-EXT-MIB::cpeExtPsePortPwrConsumption"
[[inputs.snmp.table.field]]
name = "EntPhyIndex"
oid = "CISCO-POWER-ETHERNET-EXT-MIB::cpeExtPsePortEntPhyIndex"部分结果(本节中所有后续输出中的 agent 和 host 标签已移除)
> ciscoPower,index=1.2 EntPhyIndex=1002i,PortPwrConsumption=6643i 1621460628000000000
> ciscoPower,index=1.6 EntPhyIndex=1006i,PortPwrConsumption=10287i 1621460628000000000
> ciscoPower,index=1.5 EntPhyIndex=1005i,PortPwrConsumption=8358i 1621460628000000000请注意,这里的 EntPhyIndex 列承载着 ENTITY-MIB 表的索引,其配置如下:
[[inputs.snmp.table]]
name = "entityTable"
index_as_tag = true
[[inputs.snmp.table.field]]
name = "EntPhysicalName"
oid = "ENTITY-MIB::entPhysicalName"部分结果
> entityTable,index=1006 EntPhysicalName="GigabitEthernet1/6" 1621460809000000000
> entityTable,index=1002 EntPhysicalName="GigabitEthernet1/2" 1621460809000000000
> entityTable,index=1005 EntPhysicalName="GigabitEthernet1/5" 1621460809000000000现在,让我们尝试将这些结果连接到一个表中。EntPhyIndex 与第二个表的索引匹配,我们将 EntPhysicalName 转换为标签,因此第二个表将仅为结果提供标签。配置:
[[inputs.snmp.table]]
name = "ciscoPowerEntity"
index_as_tag = true
[[inputs.snmp.table.field]]
name = "PortPwrConsumption"
oid = "CISCO-POWER-ETHERNET-EXT-MIB::cpeExtPsePortPwrConsumption"
[[inputs.snmp.table.field]]
name = "EntPhyIndex"
oid = "CISCO-POWER-ETHERNET-EXT-MIB::cpeExtPsePortEntPhyIndex"
secondary_index_table = true # enables joining
[[inputs.snmp.table.field]]
name = "EntPhysicalName"
oid = "ENTITY-MIB::entPhysicalName"
secondary_index_use = true # this tag is indexed from secondary table
is_tag = true结果
> ciscoPowerEntity,EntPhysicalName=GigabitEthernet1/2,index=1.2 EntPhyIndex=1002i,PortPwrConsumption=6643i 1621461148000000000
> ciscoPowerEntity,EntPhysicalName=GigabitEthernet1/6,index=1.6 EntPhyIndex=1006i,PortPwrConsumption=10287i 1621461148000000000
> ciscoPowerEntity,EntPhysicalName=GigabitEthernet1/5,index=1.5 EntPhyIndex=1005i,PortPwrConsumption=8358i 1621461148000000000故障排除
检查数字字段是否可以转换为文本字段
$ snmptranslate .1.3.6.1.2.1.1.3.0
DISMAN-EVENT-MIB::sysUpTimeInstance请求一个顶级字段
snmpget -v2c -c public 127.0.0.1 sysUpTime.0请求一个表
snmptable -v2c -c public 127.0.0.1 ifTable要捕获数据包,请在运行 Telegraf 或上述任何命令时在后台运行此命令。根据需要调整接口、主机和端口。
sudo tcpdump -s 0 -i eth0 -w telegraf-snmp.pcap host 127.0.0.1 and port 161Metrics
字段和标签将取决于配置的表和字段。
- snmp
- 标签 (tags)
- agent_host (1.29 中已弃用:请使用
source代替)
- agent_host (1.29 中已弃用:请使用
- 标签 (tags)
示例输出
snmp,agent_host=127.0.0.1,sysName=example.org uptime=113319.74 1575509815000000000
interface,agent_host=127.0.0.1,ifDescr=wlan0,ifIndex=3,sysName=example.org ifAdminStatus=1i,ifInDiscards=0i,ifInErrors=0i,ifInNUcastPkts=0i,ifInOctets=3436617431i,ifInUcastPkts=2717778i,ifInUnknownProtos=0i,ifLastChange=0i,ifMtu=1500i,ifOperStatus=1i,ifOutDiscards=0i,ifOutErrors=0i,ifOutNUcastPkts=0i,ifOutOctets=581368041i,ifOutQLen=0i,ifOutUcastPkts=1354338i,ifPhysAddress="c8:5b:76:c9:e6:8c",ifSpecific=".0.0",ifSpeed=0i,ifType=6i 1575509815000000000
interface,agent_host=127.0.0.1,ifDescr=eth0,ifIndex=2,sysName=example.org ifAdminStatus=1i,ifInDiscards=0i,ifInErrors=0i,ifInNUcastPkts=21i,ifInOctets=3852386380i,ifInUcastPkts=3634004i,ifInUnknownProtos=0i,ifLastChange=9088763i,ifMtu=1500i,ifOperStatus=1i,ifOutDiscards=0i,ifOutErrors=0i,ifOutNUcastPkts=0i,ifOutOctets=434865441i,ifOutQLen=0i,ifOutUcastPkts=2110394i,ifPhysAddress="c8:5b:76:c9:e6:8c",ifSpecific=".0.0",ifSpeed=1000000000i,ifType=6i 1575509815000000000
interface,agent_host=127.0.0.1,ifDescr=lo,ifIndex=1,sysName=example.org ifAdminStatus=1i,ifInDiscards=0i,ifInErrors=0i,ifInNUcastPkts=0i,ifInOctets=51555569i,ifInUcastPkts=339097i,ifInUnknownProtos=0i,ifLastChange=0i,ifMtu=65536i,ifOperStatus=1i,ifOutDiscards=0i,ifOutErrors=0i,ifOutNUcastPkts=0i,ifOutOctets=51555569i,ifOutQLen=0i,ifOutUcastPkts=339097i,ifSpecific=".0.0",ifSpeed=10000000i,ifType=24i 1575509815000000000此页面是否有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一员!我们欢迎并鼓励您对 Telegraf 和本文档提出反馈和 bug 报告。要获取支持,请使用以下资源
具有年度合同或支持合同的客户可以 联系 InfluxData 支持。