SNMP Exporter 配置生成器

SNMP Exporter generator 項(xiàng)目地址

此配置生成器使用 NetSNMP 解析 MIB,并使用它們?yōu)?snmp_exporter 生成配置。

構(gòu)建

由于對(duì) NetSNMP 的動(dòng)態(tài)依賴(lài),因此您必須自己構(gòu)建生成器。

  • Debian 系發(fā)行版
sudo apt-get install unzip build-essential libsnmp-dev # Debian-based distros
  • Redhat 系發(fā)行版
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

運(yùn)行

export MIBDIRS=mibs
./generator generate

生成器從 generator.yml 讀取并寫(xiě)入 snmp.yml。
其他命令可用于調(diào)試,請(qǐng)使用 help 命令查看它們。

使用 Docker

如果要在 docker 中運(yùn)行生成器以生成 snmp.yml 配置,請(qǐng)運(yùn)行以下命令。
Docker 鏡像需要一個(gè)包含 generator.yml 的目錄和一個(gè)名為 mibs 的目錄,其中包含您要使用的所有 MIB。
此示例將生成示例 snmp.yml,該示例包含在 snmp_exporter 存儲(chǔ)庫(kù)的頂級(jí)中:

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

文件格式

generator.yml 提供模塊列表。最簡(jiǎn)單的模塊只是一個(gè)名稱(chēng)和一組要遍歷的 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 包含整數(shù)索引枚舉的概念。 在 Prometheus 中有兩種表示這些字符串的方法。 它們可以是“信息”指標(biāo),也可以是“狀態(tài)集”。 SNMP 沒(méi)有指定應(yīng)使用的內(nèi)容,這取決于數(shù)據(jù)的使用情況。 一些用戶(hù)可能更喜歡原始整數(shù)值,而不是字符串。
為了將枚舉整數(shù)設(shè)置為字符串映射,必須使用兩個(gè)替代之一。
EnumAsInfo應(yīng)該用于提供類(lèi)庫(kù)存數(shù)據(jù)的屬性。 例如設(shè)備類(lèi)型,顏色名稱(chēng)等。此值恒定是很重要的。
EnumAsStateSet應(yīng)該用于表示狀態(tài)或您可能要發(fā)出警報(bào)的事物。 例如,鏈接狀態(tài)是打開(kāi)還是關(guān)閉,處于錯(cuò)誤狀態(tài),面板是打開(kāi)還是關(guān)閉等。請(qǐng)注意不要將其用于高基數(shù)值,因?yàn)樗鼘槊總€(gè)可能的值生成1個(gè)時(shí)間序列。

從哪里獲得 MIB

其中一些相當(dāng)緩慢,建議使用 wget下載。
將提取的 mib 放在 NetSNMP 可以讀取的位置。 $HOME/.snmp/mibs 是一種選擇。

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 常用操作在本教程中,我們將逐步構(gòu)建并運(yùn)行一些不同的SNMP命令請(qǐng)求和通知。我們將使用 最簡(jiǎn)單的PySNMP同步高級(jí)...
    Joncc閱讀 14,515評(píng)論 0 2
  • # Python 資源大全中文版 我想很多程序員應(yīng)該記得 GitHub 上有一個(gè) Awesome - XXX 系列...
    小邁克閱讀 3,129評(píng)論 1 3
  • 生成器(Generator)可以說(shuō)是在 ES2015 中最為強(qiáng)悍的一個(gè)新特性,因?yàn)樯善魇巧婕暗?ECMAScri...
    Will_Wen_Gunn閱讀 5,089評(píng)論 0 9
  • Prometheus SNMP Exporter 項(xiàng)目地址 SNMP Exporter 從 SNMP 服務(wù)中采集信...
    科舉閱讀 7,635評(píng)論 0 3
  • PEP原文 : https://www.python.org/dev/peps/pep-0342/ PEP標(biāo)題: ...
    豌豆花下貓閱讀 516評(píng)論 0 0

友情鏈接更多精彩內(nèi)容