Prerequisites
- Prometheus installed
- snmp_exporter installed (binary or container)
- Configuration access to the equipment
01The principle
Prometheus doesn’t query the device itself. It calls snmp_exporter (port 9116), passing the target, a module (what to read) and an auth (how to connect). The exporter queries the device over SNMP and returns the values in Prometheus format.
The if_mib module, shipped by default, covers the essentials: byte and error counters, state and speed of each interface.
02Enable SNMPv3 on the device
SNMPv1 and v2c send the community in clear text. SNMPv3 in authPriv mode authenticates and encrypts. An ACL limits queries to the monitoring server alone.
ip access-list standard MONITORING
permit host 192.168.5.20
!
snmp-server group PROM v3 priv access MONITORING
snmp-server user prometheus PROM v3 auth sha <password> priv aes 128 <key>03Declare the auth
The shipped snmp.yml must not be edited by hand: it is generated. snmp_exporter accepts several configuration files and can read secrets from environment variables: the auth goes into a separate file.
auths:
prom_v3:
version: 3
username: prometheus
security_level: authPriv
auth_protocol: SHA
password: ${SNMP_AUTH}
priv_protocol: AES
priv_password: ${SNMP_PRIV}04Run and test
snmp_exporter --config.file=snmp.yml --config.file=auths.yml \
--config.expand-environment-variables
# Direct test, without Prometheus
curl 'http://localhost:9116/snmp?target=192.168.5.11&module=if_mib&auth=prom_v3'05Declare it in Prometheus
The relabel_configs turn each target into the target parameter, keep the device’s address as the instance label, and send the request to the exporter.
scrape_configs:
- job_name: snmp
static_configs:
- targets: ['192.168.5.11', '192.168.5.12']
metrics_path: /snmp
params:
auth: [prom_v3]
module: [if_mib]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:911606Useful queries
64-bit counters (ifHC…) avoid the too-fast wraparound of 32-bit counters on fast links.
# Inbound throughput in bit/s, per interface
rate(ifHCInOctets[5m]) * 8
# Interfaces administratively up but down
ifAdminStatus == 1 and ifOperStatus != 1
# Inbound errors per second
rate(ifInErrors[5m]) > 0Key takeaways
- Prometheus → snmp_exporter (9116) → device over SNMP.
- SNMPv3 authPriv and an ACL: never a clear-text community.
- snmp.yml is generated; the auth lives in a separate file.
- 64-bit ifHC… counters and rate() for throughput.
Example addresses.