Prometheus SNMP_exporter Configuration – Part 2

Prometheus always needs an HTTP endpoint to scrapes the metric. In servers, we can run which collects the metrics and exposes it in an HTTP URL.

There are multiple exporters available, some are developed by the Prometheus team itself. The list of exporter details are available in

Network devices don’t allow installing any packages. The only way to collect the metric from the devices is by using SNMP or login via SSH and collect metrics. Login via SSH may have CPU impact. Hence we need an exporter that works between Prometheus and network devices for collecting metrics. SNMP_exporter is used for this. SNMP_exporter is developed by the core Prometheus team and it is very stable.

Installing SNMP_exporter

Binaries can be downloaded from page.

To start SNMP_exporter it needs a snmp.yml config file. This snmp.yml file three details, module name, OID details, and SNMP authentication details.
It doesn’t have any details about the network device IP details. network device details are sent to snmp_exporter using the HTTP URL(API). The URL contains the network device IP address and modules that need to collected. Below mentioned is a sample URL. In this core1.ash1 is the target network device and “ifmib” is the module name that needs to collect.

The “ifmib” details exist in the snmp.yml file.

ifmib:              ### MODULE NAME
  -     ### OID to SNMP GET
  - name: ifInDiscards
    type: counter
    help: The number of inbound packets which were chosen to be discarded even though
      no errors had been detected to prevent their being deliverable to a higher-layer
      protocol -
    - labelname: ifIndex
      type: gauge
    - labels:
      - ifIndex
      labelname: ifAlias
      type: DisplayString
    - labels:
      - ifIndex
      labelname: ifName
      type: DisplayString
    - labels: []
      labelname: ifIndex
    - labels: []
      labelname: ifIndex

Above mentioned is the sample snmp.yml config file, but Its not easy to write the snmp.yml by hand. Prometheus team has created for this reason. This snmp_genertor helps to create the snmp.yml config file.

Installing snmp_generator

snmp_generator can be installed at any location. once we run the snmp_generator with the generator.yml file, it generates the snmp.yml output file. The snmp.yml file can be copied to the same folder where snmp_exporter installed and you can start the snmp_exporter.

To install the SNMP_generator follow the instructions mentioned at

SNMP_generator needs the generator.yml config file to generate the snmp.yml file.

How to write generator.yml file

Below is the example of the generator.yml file. you can write your own generator.yml file or you can download my generator.yml file from

#System details and interface stats OID's are common for both Cisco and Juniper
      -  #System UPtime
      -  #System Descriptio
      - #ifHCInOctets
      - #ifHCOutOctets
      - #ifInDiscards
      - #ifInErrors
      - #ifOutDiscards
      - #ifOutErrors
      - #ifHighSpeed
      - #ifHCInUcastPkts
      - #ifHCOutUcastPkts
    version: 3
      security_level: authPriv
      username: testuser
      password: testpassword
      auth_protocol: MD5
      priv_protocol: AES
      priv_password: testpriv

      - source_indexes: [ifIndex]
        lookup: ifAlias
        drop_source_indexes: true
      - source_indexes: [ifIndex]
        lookup: ifName
        drop_source_indexes: true

In the above code “ifmib” is the module name, this will be used by Prometheus while scraping the targets. it’s always better to create multiple different modules, for example, OSPF, IS-IS, BGP, ifmib, ipsla, rpm, etc, this will be useful when writing the Prometheus config file. and if you have a switch and router, you don’t need to run the OSPF OID’s on the switch where you don’t have the OSPF running. so while writing the Prometheus config you can mention all the switches be checked for the ifmib module.

Walk: Mention the list of OID’s needs to be queried from the device

Get: InCase if we want to query get a single oid we can use the get option

Version: is the SNMP version which is running on the device.

auth: section contains the authentication details.

Lookups: all the SNMP oid comes under a table. details about SNMP tables can be found here . if we only query the OID’s it won’t be useful to the graph.

Check the ifHCInOctets metric output mentioned below, The metric has instance detail and other device detail as labels and ifindex of the metric. In this it’s not easy to identify which interface this belongs to, because ifindex is used by SNMP. we only can identify this if we know ifName(xe-0/1/6.0) or ifAlias(edge_cogent) of the interface.

ifHCInOctets{dc="ash1",ifIndex="5",instance="core1.ash1",job="all_default",region="eu-west"} = 19536684.216666665

Lookups are used to add the labels based on our interest. So we need the ifHCInOctets with ifName and ifAlias mapping to better understand the below metric for graphing. The below config says lookup for ifAlias value using the source_indexes as ifIndex and drop the source_indexes also lookup for ifName value using the source_indexes as ifIndex and drop the source_indexes

The concept it ifName, ifAlias, ifHcInOctets all have the same ifIndex value based on the SNMP table. lookups are used to correlate this and crate a meaningful metric.

      - source_indexes: [ifIndex]
        lookup: ifAlias
        drop_source_indexes: true
      - source_indexes: [ifIndex]
        lookup: ifName
        drop_source_indexes: true

so after adding the lookup config, we get the below metric. which is easy to understand


To generate the snmp.yml run the snmp_generator like below.

./generator generate

This will generate the snmp.yml file, copy it to the snmp_exporter folder, and run the snmp_exporter like below. It will auto pick the SNMP.YML config file from the folder it is running.

./snmp_exporter &

In my next post i will explain about the prometheus config for the network devices.

One reply on “Prometheus SNMP_exporter Configuration – Part 2”

Leave a Reply