SNMP Exporter 配置生成器

SNMP Exporter generator 项目地址

此配置生成器使用 NetSNMP 解析 MIB,并使用它们为 snmp_exporter 生成配置。

构建

由于对 NetSNMP 的动态依赖,因此您必须自己构建生成器。

  • Debian 系发行版
sudo apt-get install unzip build-essential libsnmp-dev # Debian-based distros
  • Redhat 系发行版
sudo yum install gcc gcc-g++ make net-snmp net-snmp-utils net-snmp-libs net-snmp-devel # RHEL-based distros
go get github.com/prometheus/snmp_exporter/generator
cd ${GOPATH-$HOME/go}/src/github.com/prometheus/snmp_exporter/generator
go build
make mibs

运行

export MIBDIRS=mibs
./generator generate

生成器从 generator.yml 读取并写入 snmp.yml
其他命令可用于调试,请使用 help 命令查看它们。

使用 Docker

如果要在 docker 中运行生成器以生成 snmp.yml 配置,请运行以下命令。
Docker 镜像需要一个包含 generator.yml 的目录和一个名为 mibs 的目录,其中包含您要使用的所有 MIB。
此示例将生成示例 snmp.yml,该示例包含在 snmp_exporter 存储库的顶级中:

make mibs
docker build -t snmp-generator .
docker run -ti \
  -v "${PWD}:/opt/" \
  snmp-generator generate

文件格式

generator.yml 提供模块列表。最简单的模块只是一个名称和一组要遍历的 OID。

modules:
  module_name:  # The module name. You can have as many modules as you want.
    walk:       # List of OIDs to walk. Can also be SNMP object names or specific instances.
      - 1.3.6.1.2.1.2              # Same as "interfaces"
      - sysUpTime                  # Same as "1.3.6.1.2.1.1.3"
      - 1.3.6.1.2.1.31.1.1.1.6.40  # Instance of "ifHCInOctets" with index "40"

    version: 2  # SNMP version to use. Defaults to 2.
                # 1 will use GETNEXT, 2 and 3 use GETBULK.
    max_repetitions: 25  # How many objects to request with GET/GETBULK, defaults to 25.
                         # May need to be reduced for buggy devices.
    retries: 3   # How many times to retry a failed request, defaults to 3.
    timeout: 10s # Timeout for each walk, defaults to 10s.

    auth:
      # Community string is used with SNMP v1 and v2. Defaults to "public".
      community: public

      # v3 has different and more complex settings.
      # Which are required depends on the security_level.
      # The equivalent options on NetSNMP commands like snmpbulkwalk
      # and snmpget are also listed. See snmpcmd(1).
      username: user  # Required, no default. -u option to NetSNMP.
      security_level: noAuthNoPriv  # Defaults to noAuthNoPriv. -l option to NetSNMP.
                                    # Can be noAuthNoPriv, authNoPriv or authPriv.
      password: pass  # Has no default. Also known as authKey, -A option to NetSNMP.
                      # Required if security_level is authNoPriv or authPriv.
      auth_protocol: MD5  # MD5 or SHA, defaults to MD5. -a option to NetSNMP.
                          # Used if security_level is authNoPriv or authPriv.
      priv_protocol: DES  # DES or AES, defaults to DES. -x option to NetSNMP.
                          # Used if security_level is authPriv.
      priv_password: otherPass # Has no default. Also known as privKey, -X option to NetSNMP.
                               # Required if security_level is authPriv.
      context_name: context # Has no default. -n option to NetSNMP.
                            # Required if context is configured on the device.

    lookups:  # Optional list of lookups to perform.
              # The default for `keep_source_indexes` is false. Indexes must be unique for this option to be used.

      # If the index of a table is bsnDot11EssIndex, usually that'd be the label
      # on the resulting metrics from that table. Instead, use the index to
      # lookup the bsnDot11EssSsid table entry and create a bsnDot11EssSsid label
      # with that value.
      - source_indexes: [bsnDot11EssIndex]
        lookup: bsnDot11EssSsid
        drop_source_indexes: false  # If true, delete source index labels for this lookup.
                                    # This avoids label clutter when the new index is unique.

     overrides: # Allows for per-module overrides of bits of MIBs
       metricName:
         ignore: true # Drops the metric from the output.
         regex_extracts:
           Temp: # A new metric will be created appending this to the metricName to become metricNameTemp.
             - regex: '(.*)' # Regex to extract a value from the returned SNMP walks's value.
               value: '$1' # The result will be parsed as a float64, defaults to $1.
           Status:
             - regex: '.*Example'
               value: '1'
             - regex: '.*'
               value: '0'
         type: DisplayString # Override the metric type, possible types are:
                             #   gauge:   An integer with type gauge.
                             #   counter: An integer with type counter.
                             #   OctetString: A bit string, rendered as 0xff34.
                             #   DateAndTime: An RFC 2579 DateAndTime byte sequence. If the device has no time zone data, UTC is used.
                             #   DisplayString: An ASCII or UTF-8 string.
                             #   PhysAddress48: A 48 bit MAC address, rendered as 00:01:02:03:04:ff.
                             #   Float: A 32 bit floating-point value with type gauge.
                             #   Double: A 64 bit floating-point value with type gauge.
                             #   InetAddressIPv4: An IPv4 address, rendered as 1.2.3.4.
                             #   InetAddressIPv6: An IPv6 address, rendered as 0102:0304:0506:0708:090A:0B0C:0D0E:0F10.
                             #   InetAddress: An InetAddress per RFC 4001. Must be preceded by an InetAddressType.
                             #   InetAddressMissingSize: An InetAddress that violates section 4.1 of RFC 4001 by
                             #       not having the size in the index. Must be preceded by an InetAddressType.
                             #   EnumAsInfo: An enum for which a single timeseries is created. Good for constant values.
                             #   EnumAsStateSet: An enum with a time series per state. Good for variable low-cardinality enums.

EnumAsInfo 和 EnumAsStateSet

SNMP 包含整数索引枚举的概念。 在 Prometheus 中有两种表示这些字符串的方法。 它们可以是“信息”指标,也可以是“状态集”。 SNMP 没有指定应使用的内容,这取决于数据的使用情况。 一些用户可能更喜欢原始整数值,而不是字符串。
为了将枚举整数设置为字符串映射,必须使用两个替代之一。
EnumAsInfo应该用于提供类库存数据的属性。 例如设备类型,颜色名称等。此值恒定是很重要的。
EnumAsStateSet应该用于表示状态或您可能要发出警报的事物。 例如,链接状态是打开还是关闭,处于错误状态,面板是打开还是关闭等。请注意不要将其用于高基数值,因为它将为每个可能的值生成1个时间序列。

从哪里获得 MIB

其中一些相当缓慢,建议使用 wget下载。
将提取的 mib 放在 NetSNMP 可以读取的位置。 $HOME/.snmp/mibs 是一种选择。

  • Cisco: ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz
  • APC: https://download.schneider-electric.com/files?p_File_Name=powernet426.mib
  • Servertech: ftp://ftp.servertech.com/Pub/SNMP/sentry3/Sentry3.mib
  • Palo Alto PanOS 7.0 enterprise MIBs: https://www.paloaltonetworks.com/content/dam/pan/en_US/assets/zip/technical-documentation/snmp-mib-modules/PAN-MIB-MODULES-7.0.zip
  • Arista Networks: https://www.arista.com/assets/data/docs/MIBS/ARISTA-ENTITY-SENSOR-MIB.txt
    https://www.arista.com/assets/data/docs/MIBS/ARISTA-SW-IP-FORWARDING-MIB.txt
    https://www.arista.com/assets/data/docs/MIBS/ARISTA-SMI-MIB.txt
  • Synology: https://global.download.synology.com/download/Document/MIBGuide/Synology_MIB_File.zip
  • MikroTik: http://download2.mikrotik.com/Mikrotik.mib
  • UCD-SNMP-MIB (Net-SNMP): http://www.net-snmp.org/docs/mibs/UCD-SNMP-MIB.txt
  • Ubiquiti Networks: http://dl.ubnt-ut.com/snmp/UBNT-MIB
    http://dl.ubnt-ut.com/snmp/UBNT-UniFi-MIB
    https://dl.ubnt.com/firmwares/airos-ubnt-mib/ubnt-mib.zip

https://github.com/librenms/librenms/tree/master/mibs can also be a good source of MIBs.
http://oidref.com is recommended for browsing MIBs.

你可能感兴趣的:(SNMP Exporter 配置生成器)