Overview of the SNMP Mixin
mainsnmp_exporter. It automates the creation of Prometheus recording and alerting rules, as well as Grafana dashboard descriptions.repository·main·Indexed 24 days ago
https://github.com/prometheus/snmp_exporterA 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.
snmp_exporter. It automates the creation of Prometheus recording and alerting rules, as well as Grafana dashboard descriptions.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: gaugeThe 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"} 1000The 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:
community strings for SNMPv2).walk, which specific OIDs to get, and how to map those values into Prometheus metrics.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: gaugeThe 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_tableTo avoid namespace collisions in MIB definitions, it is recommended to use a directory-per-device-family structure.
Each device family directory should contain:
mibs directory containing only the MIBs required for that specific family.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.
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: cbQosCMNameTo generate configurations, the generator requires MIB files. You can obtain them through several methods:
prometheus-community/snmp repository by running make mibs in the generator directory.librenms/librenms MIB collection is a recommended alternative source.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 mibsTo 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@latestStarting 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.
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.
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.http://localhost:9116/snmp?target=192.0.0.8http://localhost:9116/snmp?auth=my_secure_v3&module=ddwrt&target=192.0.0.8http://localhost:9116/snmp?auth=my_secure_v3&module=ddwrt&target=tcp%3A%2F%2F192.0.0.8%3A1161You can start the exporter as a daemon or directly from the CLI by running the binary:
./snmp_exporterBy default, the exporter listens on port 9116.