snmp 采集華為交換機 指標數據到prometheus


1.部署go環境
wget https://dl.google.com/go/go1.14.linux-amd64.tar.gz
tar -C /usr/local -zxvf go1.14.linux-amd64.tar.gz

vi /etc/profile
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin

保存后
source /etc/profile
2.下載snmp_exporter
yum -y install git
yum -y install gcc gcc-g++ make net-snmp net-snmp-utils net-snmp-libs net-snmp-devel

export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct

go get github.com/prometheus/snmp_exporter/generator
cd /home/cloudcmsp/go/src/github.com/prometheus/snmp_exporter/generator
go build

3.編輯generator.yml
modules:
# Default IF-MIB interfaces table with ifIndex.
huawei_mib:
walk:
- sysUpTime
- interfaces
- ifXTable
- sysDescr
- sysName
- 1.3.6.1.2.1.31.1.1.1.1
***
version: 2
auth:
community: zrgjcmsp123
lookups:
- source_indexes: [ifIndex]
lookup: ifAlias
- source_indexes: [ifIndex]
# Uis OID to avoid conflict with PaloAlto PAN-COMMON-MIB.
lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr
- source_indexes: [ifIndex]
# Use OID to avoid conflict with Netscaler NS-ROOT-MIB.
lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName
overrides:
ifAlias:
ignore: true # Lookup metric
ifDescr:
ignore: true # Lookup metric
ifName:
ignore: true # Lookup metric
ifType:
type: EnumAsInfo

4.生成snmp.yml
上傳華為交換機s1720的mib到generator目錄下,文件夾名mibs
export MIBDIRS=mibs
./generator generate
cp snmp.yml ../

5.啟動exporter
cd /home/cloudcmsp/go/src/github.com/prometheus/snmp_exporter
go build
./snmp_exporter
測試snmp命令:snmpwalk -v 2c 172.28.9.254 -c zrgjcmsp123 ifDescr

6.訪問exporter界面
http://172.28.9.239:9116/
輸入172.28.9.254 module輸入 huawei_mib 點擊submit跳轉
http://172.28.9.239:9116/snmp?target=172.28.9.254&module=huawei_mib
可以看到prometheus格式數據

7.配置prometheus
cd /data/cmsp-dev/prometheus/conf
增加job
- job_name: 'snmp'
scrape_interval: 30s
static_configs:
- targets:
- 172.28.9.254 #jiaohuanji ip
metrics_path: /snmp
params:
module: [huawei_mib] #generator.yml module name
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 172.28.9.239:9116 # snmp_exporter service IP

保存后重啟prometheus
可以看到指標數據
http://172.28.9.231:30909/graph?g0.range_input=1h&g0.expr=ifHCOutBroadcastPkts&g0.tab=0

下載編譯好的snmp_exporter
wget https://github.com/prometheus/snmp_exporter/releases/download/v0.20.0/snmp_exporter-0.20.0.freebsd-amd64.tar.gz


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM