Prometheus SNMP Exporter

repository·main·Indexed 24 days ago

https://github.com/prometheus/snmp_exporter

A specialized exporter that translates hierarchical SNMP data from network devices into the n-dimensional metric format required by Prometheus. It includes a generator tool to produce the required snmp.yml configuration from MIBs and a generator.yml file, supporting SNMP v1, v2, and v3 authentication, label lookups, and custom metric overrides.

Tokens
7.8K
Snippets
25
Records
43
Agent score
80%

What's inside snmp_exporter

  1. Overview of the SNMP Mixin

    main
    The SNMP Mixin provides a set of configurable, reusable, and extensible alerts and dashboards designed specifically for the metrics exported by snmp_exporter. It automates the creation of Prometheus recording and alerting rules, as well as Grafana dashboard descriptions.
  2. Handle SNMP enumerations with EnumAsInfo and EnumAsStateSet

    main

    SNMP integer enumerations can be represented in Prometheus in two ways via overrides:

    • EnumAsInfo: Best for inventory-like, constant data (e.g., device type). The exporter emits human-readable strings in labels instead of numeric values.
    • EnumAsStateSet: Best for stateful data you want to alert on (e.g., link status). This generates one time series per possible state value. Use with caution for high-cardinality values.

    To keep numeric label values for an enum column, override its type to gauge instead.

    modules:
      cisco_device:
        overrides:
          cempMemPoolType:
            type: gauge
  3. How SNMP data maps to Prometheus metrics

    main

    The snmp_exporter bridges the gap between SNMP's hierarchical OID tree structure and Prometheus's n-dimensional matrix. It automatically maps SNMP index instances to Prometheus labels.

    For example, if an SNMP entry like ifEntry uses ifIndex as an index, the exporter converts this into an ifIndex label in Prometheus. If an entry has multiple index values, each is mapped to a separate label. This allows the exporter to combine disparate OID values into a single Prometheus metric line with multiple descriptive labels.

    # Example SNMP walk return:
    1.3.6.1.2.1.2.2.1.1.2 = INTEGER: 2         # ifIndex
    1.3.6.1.2.1.2.2.1.2.2 = STRING: "eth0"     # ifDescr
    1.3.6.1.2.1.31.1.1.1.10.2 = INTEGER: 1000  # ifHCOutOctets
    
    # Resulting Prometheus metric:
    ifHCOutOctets{ifAlias="",ifDescr="eth0",ifIndex="2",ifName="eth0"} 1000
  4. Understand the SNMP Exporter configuration file format

    main

    The SNMP Exporter configuration file is a YAML file generated by the generator tool. It defines authentication methods (auths) and specific SNMP modules (modules) that dictate how the exporter interacts with SNMP devices.

    Key components include:

    • auths: Defines SNMP versions and credentials (e.g., community strings for SNMPv2).
    • modules: Contains the logic for a specific device or service, including which OID subtrees to walk, which specific OIDs to get, and how to map those values into Prometheus metrics.
    • metrics: Defines the mapping of SNMP OIDs to Prometheus metric names, types, and labels.
    auths:
      public_v2:
        version: 2
        community: public
    modules:
      module_name:
        walk:
          - "IF-MIB::interfaces"
        get:
          - 1.3.6.1.2.1.1.3
        metrics:
          - name: sysUpTime
            oid: 1.3.6.1.2.1.1.3
            type: gauge
  5. Use multiple SNMP modules in a single scrape

    main

    The multi-module functionality allows you to retrieve information from several modules in a single scrape request. You can specify multiple modules by either separating them with a comma in the module parameter or by defining the module parameter multiple times.

    Note: This implementation does not perform de-duplication of walks between different modules. You can control the concurrency of these walks using the --snmp.module-concurrency flag (default is 1).

    ### Comma separation
    http://localhost:9116/snmp?module=if_mib,arista_sw&target=192.0.0.8
    
    ### Multiple params_module
    http://localhost:9116/snmp?module=if_mib&module=arista_sw&target=192.0.0.8
    
    ### Prometheus Configuration Example
    ```yaml
      - job_name: 'my'
        params:
          module:
            - if_mib
            - synology
            - ucd_la_table
  6. Organize MIBs and configurations for multiple device families

    main

    To avoid namespace collisions in MIB definitions, it is recommended to use a directory-per-device-family structure.

    Each device family directory should contain:

    1. A mibs directory containing only the MIBs required for that specific family.
    2. A logical link to the generator executable.
    3. The generator.yml configuration file.

    After generating individual snmp.yml files for each family, merge them into a single main snmp.yml file to be used by the snmp_exporter collector.

  7. Perform label lookups in SNMP modules

    main

    The lookups option allows you to resolve table indexes into human-readable labels. This is useful for replacing a numeric index with a descriptive value from another table.

    • source_indexes: The index (or list of indexes) to use for the lookup.
    • lookup: The target OID/table to fetch the value from.
    • drop_source_indexes: If true, the original numeric index label is removed to avoid clutter.
    • display_hint: Use @mib to use the MIB's hint, or provide a custom RFC 2579 hint string.

    Lookups can be chained: the result of one lookup can serve as the source_indexes for the next.

    modules:
      module_name:
        lookups:
          - source_indexes: [bsnDot11EssIndex]
            lookup: bsnDot11EssSsid
            drop_source_indexes: false
            display_hint: "@mib"
          - source_indexes: [cbQosPolicyIndex, cbQosObjectsIndex]
            lookup: cbQosConfigIndex
          - source_indexes: [cbQosConfigIndex]
            lookup: cbQosCMName
  8. Obtain MIB files for the SNMP Exporter Generator

    main

    To generate configurations, the generator requires MIB files. You can obtain them through several methods:

    1. Automatic Download: Use the pre-maintained MIBs from the prometheus-community/snmp repository by running make mibs in the generator directory.
    2. Vendor Portals: Download MIBs directly from the hardware vendor's support or developer portal.
    3. LibreNMS: The librenms/librenms MIB collection is a recommended alternative source.
    4. OID Browsing: Use http://oidref.com to browse and identify specific MIBs.

    Note: Using MIBs from the prometheus-community/snmp repository is preferred because they are centrally maintained and versioned.

    make mibs
  9. Install dependencies for SNMP Mixin

    main

    To use the SNMP Mixin, you must install mixtool and jsonnetfmt. If you have a Go development environment configured, you can install them using the following commands:

    $ go install github.com/monitoring-mixins/mixtool/cmd/mixtool@latest
    $ go install github.com/google/go-jsonnet/cmd/jsonnetfmt@latest
  10. Migrate to the Module and Auth Split configuration format

    main

    Starting from snmp_exporter v0.23.0, the configuration format has changed. The configuration is no longer a flat list of modules; instead, it is split into separate metric walking/mapping modules and authentication configurations (auths).

    To upgrade, you must migrate both your generator configuration and your generated snmp_exporter configuration to this new format. Configuration files for v0.22.0 and earlier are incompatible with v0.23.0 and later.

  11. Scrape SNMP metrics via HTTP URL

    main

    To retrieve metrics for a specific device, send a GET request to the /snmp endpoint. You must provide the target (the IP or FQDN of the device) and typically the module and auth defined in your snmp.yml.

    URL Parameters

    • target: The IP or FQDN of the SNMP device. Use URL encoding for special characters (e.g., tcp://host:port becomes tcp%3A%2F%2Fhost%3Aport).
    • module: The SNMP module to use (e.g., if_mib).
    • auth: The authentication configuration to use (e.g., public_v2).
    • snmp_context: (Optional) Overrides the context_name in snmp.yml.
    • snmp_engineid: (Optional) Used with SNMPv3 to specify the engine ID.

    Examples

    • Default (UDP, port 161, public_v2, if_mib): http://localhost:9116/snmp?target=192.0.0.8
    • Custom Auth and Module: http://localhost:9116/snmp?auth=my_secure_v3&module=ddwrt&target=192.0.0.8
    • Custom Transport (TCP) and Port: http://localhost:9116/snmp?auth=my_secure_v3&module=ddwrt&target=tcp%3A%2F%2F192.0.0.8%3A1161