Debian: Prometheus SNMP

This exporter is the recommended way to expose SNMP data in a format which Prometheus can ingest.

Step 1: Basic Installation

Install the basic minimal required packages

# apt install prometheus-snmp-exporter snmp-mibs-downloader unzip build-essential libsnmp-dev p7zip-full

Download all the basic SNMP MIBS

# download-mibs
Downloading documents and extracting MIB files.
This will take some minutes.

In case this process fails, it can always be repeated later by executing
/usr/bin/download-mibs again.

RFC1155-SMI: 119 lines.
RFC1213-MIB: 2613 lines.
NOTE: SMUX: ignored.
SMUX-MIB: 158 lines.
CLNS-MIB: 1294 lines.
RFC1381-MIB: 1007 lines.
RFC1382-MIB: 2627 lines.
RFC1414-MIB: 131 lines.
SNMPv2-PARTY-MIB: 1410 lines.
SNMPv2-M2M-MIB: 807 lines.
MIOX25-MIB: 708 lines.
PPP-LCP-MIB: 764 lines.
PPP-SEC-MIB: 289 lines.
PPP-IP-NCP-MIB: 203 lines.
PPP-BRIDGE-NCP-MIB: 429 lines.
FDDI-SMT73-MIB: 2126 lines.
TOKEN-RING-RMON-MIB: 2302 lines.
SOURCE-ROUTING-MIB: 450 lines.
DECNET-PHIV-MIB: 3030 lines.
....
...

Step 2: Create Exporter

Ubiquiti EdgeRouter

Use the following data to generate an EdgeRouter configuration, this example includes BGP peer details.

# =================================================================================================
# EDGE ROUTER
# =================================================================================================
 edgerouter:
 version: 3
    version: 3
    timeout: 10s
    retries: 3
    auth:
      security_level: authPriv
      username: snmpuser
      password: someauthpw
      auth_protocol: SHA
      priv_protocol: AES
      priv_password: someprivpksl2
    walk:
      - hrSystemUptime
      - hrSystemNumUsers
      - hrSystemProcesses
      - hrStorage
      - interfaces
      - ipTrafficStats
      - ipInReceives
      - ipInHdrErrors
      - ipInAddrErrors
      - ipForwDatagrams
      - ipInUnknownProtos
      - ipInDiscards
      - ipInDelivers
      - ipOutRequests
      - ipOutDiscards
      - ipOutNoRoutes
      - ipReasmReqds
      - ipReasmOKs
      - ipReasmFails
      - ipFragOKs
      - ipFragFails
      - ipFragCreates
      - icmp
      - ifXTable
      - 1.3.6.1.4.1.2021.4 # UCD memory
      - 1.3.6.1.4.1.2021.10 # UCD Load
      - systemStats
      - bgpPeerTablee
    lookups:
      - source_indexes: [ifIndex]
        lookup: ifAlias
        drop_source_indexes: true
      - source_indexes: [ipIfStatsIfIndex]
        lookup: ifAlias
        drop_source_indexes: true
      - source_indexes: [hrStorageIndex]
        lookup: hrStorageDescr
        drop_source_indexes: true
      - source_indexes: [laIndex]
        lookup: laNames
        drop_source_indexes: true
      - source_indexes: [bgpPeerRemoteAddr]
        lookup: bgpPeerRemoteAs
    overrides:
      bgpPeerState:
        type: EnumAsStateSet
      bgpPeerAdminStatus:
        type: EnumAsStateSet

Ubiquiti UNIFi

Download the UNIFI MIB files

# cd /usr/share/snmp/mibs
# wget http://dl.ubnt-ut.com/snmp/UBNT-MIB -q -O UBNT-MIB.txt

The generator.yml data used for UNIFI is as follows:

# =================================================================================================
# Ubiquiti / UniFi
# =================================================================================================
#
# http://dl.ubnt-ut.com/snmp/UBNT-MIB
# http://dl.ubnt-ut.com/snmp/UBNT-UniFi-MIB
#
# =================================================================================================
 ubiquiti_unifi:
 version: 3
    version: 2
    timeout: 10s
    retries: 3
    auth:
      community: mycomro
    walk:
      - sysUpTime
      - interfaces
      - ifXTable
      - 1.3.6.1.4.1.41112.1.6 # ubntUniFi
    overrides:
      ifType:
        type: EnumAsInfo

Synology

Download the synology MIB files

# cd /tmp
# wget https://global.download.synology.com/download/Document/Software/DeveloperGuide/Firmware/DSM/All/enu/Synology_MIB_File.zip
# mkdir /usr/share/snmp/mibs
# cd Synology_MIB_File
# cp *.txt /usr/share/snmp/mibs

The generator.yml data used for SYNOLOGY is as follows:

# =================================================================================================
# SYNOLOGY
# =================================================================================================
#
# Synology MIBs can be found here:
# http://www.synology.com/support/snmp_mib.php
# https://global.download.synology.com/download/Document/Software/DeveloperGuide/Firmware/DSM/All/enu/Synology_MIB_File.zip
# Tested on RS2414rp+ NAS
#
# =================================================================================================
synology:
 version: 3
    version: 3
    timeout: 10s
    retries: 3
 auth:
   security_level: authPriv
   username: snmpuser
   password: someauthpw
   auth_protocol: SHA
   priv_protocol: AES
   priv_password: someprivpw
   walk:
      - interfaces
      - sysUpTime
      - ifXTable
      - laNames
      - laLoadInt
      - ssCpuUser
      - ssCpuSystem
      - ssCpuIdle
      - memory
      - hrStorage
      - 1.3.6.1.4.1.6574.1       # synoSystem
      - 1.3.6.1.4.1.6574.2       # synoDisk
      - 1.3.6.1.4.1.6574.3       # synoRaid
      - 1.3.6.1.4.1.6574.4       # synoUPS
      - 1.3.6.1.4.1.6574.5       # synologyDiskSMART
      - 1.3.6.1.4.1.6574.6       # synologyService
      - 1.3.6.1.4.1.6574.101     # storageIO
      - 1.3.6.1.4.1.6574.102     # spaceIO
      - 1.3.6.1.4.1.6574.104     # synologyiSCSILUN
    lookups:
      - source_indexes: [spaceIOIndex]
        lookup: spaceIODevice
        drop_source_indexes: true
      - source_indexes: [storageIOIndex]
        lookup: storageIODevice
        drop_source_indexes: true
      - source_indexes: [serviceInfoIndex]
        lookup: serviceName
        drop_source_indexes: true
      - source_indexes: [ifIndex]
        # Use OID to avoid conflict with Netscaler NS-ROOT-MIB.
        lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName
        drop_source_indexes: true
      - source_indexes: [diskIndex]
        lookup: diskID
        drop_source_indexes: true
      - source_indexes: [raidIndex]
        lookup: raidName
        drop_source_indexes: true
      - source_indexes: [laIndex]
        lookup: laNames
        drop_source_indexes: true
      - source_indexes: [hrStorageIndex]
        lookup: hrStorageDescr
        drop_source_indexes: true
    overrides:
      ifType:
        type: EnumAsInfo
      1.3.6.1.4.1.6574.1.5.1: # Model
        type: DisplayString
      1.3.6.1.4.1.6574.1.5.2: # Serial
        type: DisplayString
      1.3.6.1.4.1.6574.1.5.3: # Version
        type: DisplayString
      1.3.6.1.4.1.6574.2.1.1.2: # Disk Slot
        type: DisplayString
      1.3.6.1.4.1.6574.2.1.1.3: # Disk Model
        type: DisplayString
      1.3.6.1.4.1.6574.2.1.1.4: # Disk Type
        type: DisplayString
      1.3.6.1.4.1.6574.5.1.1.3: # SMART Attribute Name
        type: DisplayString
      1.3.6.1.4.1.6574.5.1.1.9: # SMART Status
        type: DisplayString
      1.3.6.1.4.1.6574.5.1.1.2: # Smart Device Name
        type: DisplayString
      1.3.6.1.4.1.6574.3.1.1.2: # RAID Name
        type: DisplayString
      1.3.6.1.4.1.6574.6.1.1.2: # Service Name
        type: DisplayString

 

Avmavis

Check /usr/share/doc/amavisd-new for the AMAVIS-MIB.txt.gz MIB file. Copy this file to your prometheus exporter server and place the file in /usr/share/snmp/mibs.

 

Step 3: Generate the snmp.yml

Make sure that /etc/prometheus/generator.yml is properly filled in with the SNMP OID data you want to scrape from devices. Using the following command you can generate a new snmp.yml

# prometheus-snmp-generator generate
level=info ts=2021-12-31T18:13:49.367Z caller=net_snmp.go:142 msg="Loading MIBs" from=$HOME/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf
level=info ts=2021-12-31T18:13:50.563Z caller=main.go:52 msg="Generating config for module" module=edge
level=info ts=2021-12-31T18:13:50.618Z caller=main.go:67 msg="Generated metrics" module=edge metrics=40
level=info ts=2021-12-31T18:13:50.619Z caller=main.go:52 msg="Generating config for module" module=synology
level=info ts=2021-12-31T18:13:50.706Z caller=main.go:67 msg="Generated metrics" module=synology metrics=292
level=info ts=2021-12-31T18:13:50.706Z caller=main.go:52 msg="Generating config for module" module=ubiquiti_unifi
level=info ts=2021-12-31T18:13:50.780Z caller=main.go:67 msg="Generated metrics" module=ubiquiti_unifi metrics=43
level=info ts=2021-12-31T18:13:50.866Z caller=main.go:92 msg="Config written" file=/etc/prometheus/snmp.yml

Now you can enable and start the prometheus-snmp-exporter service

# systemctl enable prometheus-snmp-exporter
# systemctl restart prometheus-snmp-exporter

Step 4: Prometheus Discovery

Each of the devices to be discovered are defined in the regulary prometheus configuration file /etc/prometheus/prometheus.yml Define each device as follows, following example for a synology device

  - job_name: 'synology'
    metrics_path: /snmp
    params:
      module: [synology]
    static_configs:
      - targets: ['nas']
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9116 # the Prometheus SNMP exporter

Check the configuration and if correct restart prometheus

# promtool check config /etc/prometheus/prometheus.yml
Checking /etc/prometheus/prometheus.yml
SUCCESS: 0 rule files found

# systemctl restart prometheus