SNMP monitoring and easing it with Prometheus.

Mohan Prasath
Sep 18, 2018 · 8 min read

How it works:

tar xvfz prometheus-*.tar.gz
cd prometheus-*
./snmp_exporter
sudo apt-get install build-essential libsnmp-dev snmp-mibs-downloader  # Debian-based distros
go get github.com/prometheus/snmp_exporter/generator
cd ${GOPATH-$HOME/go}/src/github.com/prometheus/snmp_exporter/generator
go build
docker build -t snmp-generator .
docker run -ti \
-v $HOME/.snmp/mibs:/root/.snmp/mibs \
-v $PWD/generator.yml:/opt/generator.yml:ro \
-v $PWD/out/:/opt/ \
snmp-generator generate
Cisco:
version: 3
auth:
username: snmpUser
password: yourPassword
auth_protocol: SHA
priv_protocol: DES
security_level: authPriv
priv_password: privacyPassword
walk:
- 1.3.6.1.2.1.1 # sysInfo
- 1.3.6.1.2.1.2.2 # ifTable
- 1.3.6.1.2.1.31.1.1 # ifXTable
metrics:
#sysInfo
- name: sysUpTime
oid: 1.3.6.1.2.1.1.3
type: counter
lookups:
- labels:
labelname: sysDescr
oid: 1.3.6.1.2.1.1.1.0
type: DisplayString
- labels:
labelname: sysName
oid: 1.3.6.1.2.1.1.5.0
type: DisplayString
- labels:
labelname: sysLocation
oid: 1.3.6.1.2.1.1.6.0
type: DisplayString
- labels:
labelname: sysContact
oid: 1.3.6.1.2.1.1.4.0
type: DisplayString
#Interfaces
#Interface ifIndex
- name: ifIndex
oid: 1.3.6.1.2.1.2.2.1.1
type: gauge
indexes:
- labelname: ifIndex
type: Integer
lookups:
- labels:
- ifIndex
labelname: ifDescr
oid: 1.3.6.1.2.1.2.2.1.2
type: DisplayString
- labels:
- ifIndex
labelname: ifName
oid: 1.3.6.1.2.1.31.1.1.1.1
type: DisplayString
- labels:
- ifIndex
labelname: ifAlias
oid: 1.3.6.1.2.1.31.1.1.1.18
type: DisplayString
#Interface Type
- name: ifType
oid: 1.3.6.1.2.1.2.2.1.3
type: gauge
indexes:
- labelname: ifIndex
type: Integer
lookups:
- labels:
- ifIndex
labelname: ifDescr
oid: 1.3.6.1.2.1.2.2.1.2
type: DisplayString
- labels:
- ifIndex
labelname: ifName
oid: 1.3.6.1.2.1.31.1.1.1.1
type: DisplayString
- labels:
- ifIndex
labelname: ifAlias
oid: 1.3.6.1.2.1.31.1.1.1.18
type: DisplayString
Tree structure of Mib
#Interface Speed
- name: ifSpeed
oid: 1.3.6.1.2.1.2.2.1.5
type: gauge
indexes:
- labelname: ifIndex
type: Integer
lookups:
- labels:
- ifIndex
labelname: ifDescr
oid: 1.3.6.1.2.1.2.2.1.2
type: DisplayString
- labels:
- ifIndex
labelname: ifName
oid: 1.3.6.1.2.1.31.1.1.1.1
type: DisplayString

Make Prometheus collect data:

global:
scrape_interval: 15s
evaluation_interval: 15s

rule_files:
# - "first.rules"
# - "second.rules"

scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
# Sample config for Prometheus.
global:
scrape_interval: 5m
scrape_timeout: 10s
evaluation_interval: 1m

# A scrape configuration containing exactly one endpoint to scrape:
scrape_configs:
# Cisco
- job_name: 'Cisco'
scrape_interval: 120s
scrape_timeout: 120s
file_sd_configs:
- files :
- /etc/prometheus/targetCisco.yml
# SNMP device.
metrics_path: /snmp
params:
module: [Cisco] #which OID's we will be querying in
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 127.0.0.1:9116 # The SNMP exporter's real hostname:port.

Mohan Prasath

Written by

Definitely not a Blogger. I like to develop things and love naming new cool functions. Know me more here: https://openmohan.github.io

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade