search
数据采集 采集源配置 SNMP 指标采集

SNMP 指标采集

简介

通过 snmp 协议 采集 snmp 设备相关指标上报到 DataFlux 中

内置视图

Overview视图

内置视图

视图Json文件Overview视图

视图Json文件内置视图

前置条件

  • 采集设备需已启用snmp服务
    验证设备已开启snmp服务:
    # snmpwalk -c public -v 1 192.168.1.1 #你的IP地址
    
  • 已安装 DataKit(datakit 安装文档
  • 需在全局路径下安装 net-snmp 项目的 snmptablesnmptranslate 工具
安装命令举例:
# apt install snmp-mibs snmp-utils

配置

该采集器默认会通过 /usr/share/snmp/mibs 加载系统的 MIBs,如果系统 MIBs 的路径不在该路径下,需要配置 snmp.conf 配置文件指定需采集的 MIBs 或配置 MIBDIRS 环境变量,具体可参考 man 1 snmpcmd

打开 DataKit 采集源配置文件夹(默认路径为 DataKit 安装目录的 conf.d 文件夹),找到 snmp 文件夹,打开里面的 snmp.conf

[[inputs.snmp]]
  ## Agent addresses to retrieve values from.
  ##   example: agents = ["udp://127.0.0.1:161"]
  ##            agents = ["tcp://127.0.0.1:161"]
  #配置需要进行SNMP采集的设备IP,当需要采集多个SNMP设备时使用 
  #agents = ["udp://127.0.0.1:161","udp://127.0.0.1:161"]
  agents = ["udp://127.0.0.1:161"]

  ## Timeout for each request.
  # timeout = "5s"

  ## SNMP version; can be 1, 2, or 3.
  # version = 2

  ## SNMP community string.
  # community = "public"

  ## 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", 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" or "".
  # 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 = "uptime"

  [[inputs.snmp.field]]
    oid = "RFC1213-MIB::sysName.0"
    name = "source"
    is_tag = true

  [[inputs.snmp.table]]
    oid = "IF-MIB::ifTable"
    name = "interface"
    inherit_tags = ["source"]

    [[inputs.snmp.table.field]]
      oid = "IF-MIB::ifDescr"
      name = "ifDescr"
      is_tag = true

该采集器提供了 2 种方式采集 SNMP 设备的数据,通过 field 配置采集指定的指标或者通过 table 配置采集 SNMP table 数据。

field 采集配置

配置参数

指标 描述
oid 需获取 OID名称
oid_index_suffix 要剥离的OID子标识符
oid_index_length 指定提供的表OID之后的索引长度
name 指定采集的指标或者标签名称,如果为空,默认会使用 oid 作为名称
is_tag 是否指定该采集字段为标签,默认 false,即该字段默认作为指标
conversion 指定数据转换方法,具体参见下面的表格

conversion 说明

conversion 说明
float(X) Convert the input value into a float and divides by the Xth power of 10. Efficively 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
hwaddr Convert the value to a MAC address
ipaddr Convert the value to an IP address

配置好后,重启 datakit 即可生效

table 配置采集

每个 table 配置项都会创建一个新的指标集,默认情况下不用配置 [[inputs.snmp.table.field]] , SNMP table 中的所有列数据都会被采集,除非你需要对 table 中采集的列数据进行修改

配置参数

表名 描述
oid 需采集的对象的oid 或者 table 名称
name 指定指标集名称,如果为空,默认会使用 oid 作为指标集名称
inherit_tags 需从顶级的配置中继承的标签
index_as_tag 将表的行数作为 index 标签的值,一般情况下不需要开启

采集指标

示例数据

snmp,agent_host=127.0.0.1,source=loaner uptime=11331974i 1575509815000000000
interface,agent_host=127.0.0.1,ifDescr=wlan0,ifIndex=3,source=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,source=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,source=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