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

上一篇:spark 统计每天新增用户数


下一篇:Prometheus-node-exporter