s3700-s5700-s6700系列通用
配置交换机SNMP Agent
ssh root@192.168.1.2
system-view
snmp-agent community read cipher sunday_public # 只读
snmp-agent sys-info contact admin@sundayhk.com # 联系信息
snmp-agent sys-info location guangzhou # 设备位置
snmp-agent sys-info version v2c # 版本
# Ubuntu 22
sudo apt-get install -y unzip build-essential libsnmp-dev
# CentOS 7
sudo yum install -y gcc gcc-g++
net-snmp net-snmp-utils net-snmp-libs net-snmp-devel
测试获取交换机Hostname
$ snmpwalk -v 2c -c sunday_public 192.168.1.2 1.3.6.1.2.1.1.5
iso.3.6.1.2.1.1.5.0 = STRING: "HW1
下载MIB文件
下载华为交换机版本对应MIB文件,如V200R019C10XXXXXX
,若下载不了对应MIB
或多款设备不同版本,可以下载高版本MIB
,一般高版本会向下兼容低版本,因为之前定义好的OID
很少改动,新版本MIB
只会增加特性OID
。
https://support.huawei.com/enterprise/zh/switches/s3700-s5700-s6700-pid-259602657/software
http://oss.sundayhk.com/file/snmp/MIB_V200R024C00SPC500.zip
OID信息查询
华为设备指标 OID
信息查询址:
https://info.support.huawei.com/info-finder/tool/zh/enterprise/mib
编辑配置文件
官方提供的snmp.yml对华为设备不太友好,所以需要自定义数据采集。
generator格式说明:
https://github.com/prometheus/snmp_exporter/tree/main/generator#file-format
vim ~/generator.yml
auths:
public_v2: # 认证模块名称
version: 2 # snmp v2c版本
community: sunday_public # snmp 团体名
modules:
huawei_common: # 华为公共指标模块名称
walk:
# 交换机基础信息 温度信息 风扇信息 电源信息
- 1.3.6.1.2.1.1.1 # sysDescr 系统的文字描述
- 1.3.6.1.2.1.1.5 # sysName 交换机名称
- 1.3.6.1.4.1.2011.5.25.31.1.1.6.1.1 # hwEntPowerUsedInfoBoardName 板卡实体名称
- 1.3.6.1.4.1.2011.5.25.31.1.1.1.1.10 # hwEntityUpTime 板卡实体启动时间 单位秒
- 1.3.6.1.4.1.2011.5.25.31.1.1.1.1.11 # hwEntityTemperature 实体温度 单位°C
- 1.3.6.1.4.1.2011.5.25.31.1.1.1.1.12 # hwEntityTemperatureThreshold 实体温度高门限 单位°C
- 1.3.6.1.4.1.2011.5.25.31.1.1.10.1.7 # hwEntityFanState 风扇状态
- 1.3.6.1.4.1.2011.5.25.31.1.1.10.1.6 # hwEntityFanPresent 风扇的在位状态
- 1.3.6.1.4.1.2011.5.25.31.1.1.10.1.5 # hwEntityFanSpeed 风扇的转速
#- 1.3.6.1.4.1.2011.5.25.31.1.1.18.1.1 # hwEntityPwrSlot 电源的槽位号
- 1.3.6.1.4.1.2011.5.25.31.1.1.18.1.6 # hwEntityPwrState 电源的状态
- 1.3.6.1.4.1.2011.6.157.1.6 # hwCurrentPower 当前功率mW
- 1.3.6.1.4.1.2011.6.157.1.3 # hwAveragePower 平均功率mW
# 交换机CPU和内存信息
- 1.3.6.1.4.1.2011.5.25.31.1.1.1.1.5 # hwEntityCpuUsage 实体CPU使用率
- 1.3.6.1.4.1.2011.5.25.31.1.1.1.1.7 # hwEntityMemUsage 实体内存使用率
- 1.3.6.1.4.1.2011.6.9.1.4.2.1.3 # hwStorageSpace Flash设备空间的大小 单位是千字节
- 1.3.6.1.4.1.2011.6.9.1.4.2.1.4 # hwStorageSpaceFree Flash设备剩余空间 单位是千字节
- 1.3.6.1.4.1.2011.6.9.1.4.2.1.5 # hwStorageName Flash设备名称
#- 1.3.6.1.4.1.2011.6.3.4.1.2 # hwCpuDevDuty 5秒钟内的CPU的平均使用率
#- 1.3.6.1.4.1.2011.6.3.4.1.3 # hwCpuDuty1min 1分钟内的CPU的平均使用率
#- 1.3.6.1.4.1.2011.6.3.4.1.4 # hwCpuDuty5min 5分钟内的CPU的平均使用率
#- 1.3.6.1.4.1.2011.6.3.5.1.1.2 # hwMemoryDevSize 每块板上内存总量
#- 1.3.6.1.4.1.2011.6.3.5.1.1.3 # hwMemoryDevFree 每块板上空闲的内存总量
#- 1.3.6.1.4.1.2011.6.3.5.1.1.4 # hwMemoryDevRawSliceUsed 每块板上已占用的raw slice内存总量
max_repetitions: 30
retries: 3
timeout: 5s
lookups:
- source_indexes: [hwEntityFanSlot, hwEntityFanSn]
lookup: hwEntityFanPresent
- source_indexes: [hwEntityFanSlot, hwEntityFanSn]
lookup: hwEntityFanState
- source_indexes: [entPhysicalIndex]
lookup: 1.3.6.1.4.1.2011.5.25.31.1.1.6.1.1
#drop_source_indexes: true
- source_indexes: [hwStorageIndex]
lookup: hwStorageName
overrides:
hwEntityFanPresent:
ignore: true
hwEntityFanState:
ignore: true
hwEntPowerUsedInfoBoardName:
ignore: true
type: DisplayString
hwStorageName:
ignore: true
type: DisplayString
huawei_core: # 核心模块指标 基于S12700E-4
walk:
# 接口信息
#- 1.3.6.1.2.1.2.2.1.1 # ifIndex 接口索引 该值大于零且全局唯一
#- 1.3.6.1.2.1.2.2.1.2 # ifDescr 描述接口的字符串
- 1.3.6.1.2.1.31.1.1.1.1 # ifName 由本地设备分配的接口名 同上指标 取其中之一
- 1.3.6.1.2.1.2.2.1.7 # ifAdminStatus 理想的接口状态
- 1.3.6.1.2.1.2.2.1.8 # ifOperStatus 接口当前的状态
- 1.3.6.1.2.1.31.1.1.1.18 # ifAlias 该节点是由网络管理员指定的接口别名 description命令
- 1.3.6.1.2.1.31.1.1.1.15 # ifHighSpeed 接口当前带宽 单位 Mbit/s
- 1.3.6.1.2.1.31.1.1.1.6 # ifHCInOctets 接口上接收到的字节总数 byte/s
- 1.3.6.1.2.1.31.1.1.1.10 # ifHCOutOctets 接口发送的字节总数 byte/s
- 1.3.6.1.2.1.2.2.1.13 # ifInDiscards 入方向的被丢弃的报文个数
- 1.3.6.1.2.1.2.2.1.19 # ifOutDiscards 出方向的被丢弃的报文个数
- 1.3.6.1.2.1.2.2.1.14 # ifInErrors 入方向出错报文个数
- 1.3.6.1.2.1.2.2.1.20 # ifOutErrors 出方向出错报文个数
#- 1.3.6.1.4.1.2011.5.25.41.1.7.1.1.2 # hwIfMonitorCrcErrorStatistics CRC错包统计值
#- 1.3.6.1.4.1.2011.5.25.41.1.7.1.1.8 # hwIfMonitorInputRate 接口入方向带宽占用率
#- 1.3.6.1.4.1.2011.5.25.41.1.7.1.1.10 # hwIfMonitorOutputRate 接口出方向带宽占用率
# 光模块信息
#- 1.3.6.1.2.1.47.1.1.1.1.1 # entPhysicalIndex 物理实体索引
- 1.3.6.1.2.1.47.1.1.1.1.7 # entPhysicalName 物理实体名 光模块接口名称
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.8 # hwEntityOpticalRxPower 光模块接收功率 单位 uW
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.9 # hwEntityOpticalTxPower 光模块发送功率 单位 uW
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.20 # hwEntityOpticalRxLowWarnThreshold 光模块接收功率过低的预警门限值 单位 dBm
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.21 # hwEntityOpticalRxHighWarnThreshold 光模块接收功率过高的预警门限值 单位 dBm
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.22 # hwEntityOpticalTxLowWarnThreshold 光模块发送功率过低的预警门限值 单位 dBm
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.23 # hwEntityOpticalTxHighWarnThreshold 光模块发送功率过高的预警门限值 单位 dBm
# CSS集群状态
- 1.3.6.1.4.1.2011.5.25.183.3.1.1 # hwCssEnable 使能设备集群功能
- 1.3.6.1.4.1.2011.5.25.183.3.2.1.8 # hwCssMemberRole 集群角色
- 1.3.6.1.4.1.2011.5.25.183.3.2.1.7 # hwCssMemberConfigEnable 集群使能状态
- 1.3.6.1.4.1.2011.5.25.42.2.1.14 # hwMacGlobalStatistics 获取设备上的MAC地址数
- 1.3.6.1.4.1.2011.5.25.42.2.1.1 # hwL2MaxMacLimit MAC地址限定的最大规则数
max_repetitions: 30
retries: 3
timeout: 5s
lookups:
- source_indexes: [ifIndex]
lookup: ifAlias
# 如果新的索引唯一 可以删除原来的索引 true
#drop_source_indexes: false
- source_indexes: [ifIndex]
lookup: ifName
- source_indexes: [ifIndex]
lookup: ifOperStatus
- source_indexes: [ifIndex]
lookup: ifHighSpeed
- source_indexes: [entPhysicalIndex]
lookup: entPhysicalName
overrides:
ifAlias:
ignore: true # 忽略IfAlias值,这里只用做标签
ifName:
ignore: true
ifOperStatus:
ignore: true
ifHighSpeed:
ignore: true
entPhysicalName:
ignore: true
filters:
dynamic: # 根据接口当前状态收集接口指标
- oid: 1.3.6.1.2.1.2.2.1.7
targets:
- "1.3.6.1.2.1.31.1.1.1.6"
- "1.3.6.1.2.1.31.1.1.1.10"
- "1.3.6.1.2.1.2.2.1.13"
- "1.3.6.1.2.1.2.2.1.19"
- "1.3.6.1.2.1.2.2.1.14"
- "1.3.6.1.2.1.2.2.1.20"
values: ["1"]
huawei_agg: # 华为汇聚和接入交换机模块指标
walk:
# 接口信息
#- 1.3.6.1.2.1.2.2.1.1 # ifIndex 接口索引 该值大于零且全局唯一
#- 1.3.6.1.2.1.2.2.1.2 # ifDescr 描述接口的字符串
- 1.3.6.1.2.1.31.1.1.1.1 # ifName 由本地设备分配的接口名 同上指标 取其中之一
- 1.3.6.1.2.1.2.2.1.7 # ifAdminStatus 理想的接口状态
- 1.3.6.1.2.1.2.2.1.8 # ifOperStatus 接口当前的状态
- 1.3.6.1.2.1.31.1.1.1.18 # ifAlias 该节点是由网络管理员指定的接口别名 description命令
- 1.3.6.1.2.1.31.1.1.1.15 # ifHighSpeed 接口当前带宽 单位 Mbit/s
- 1.3.6.1.2.1.31.1.1.1.6 # ifHCInOctets 接口上接收到的字节总数 byte/s
- 1.3.6.1.2.1.31.1.1.1.10 # ifHCOutOctets 接口发送的字节总数 byte/s
- 1.3.6.1.2.1.2.2.1.13 # ifInDiscards 入方向的被丢弃的报文个数
- 1.3.6.1.2.1.2.2.1.19 # ifOutDiscards 出方向的被丢弃的报文个数
- 1.3.6.1.2.1.2.2.1.14 # ifInErrors 入方向出错报文个数
- 1.3.6.1.2.1.2.2.1.20 # ifOutErrors 出方向出错报文个数
#- 1.3.6.1.4.1.2011.5.25.41.1.7.1.1.2 # hwIfMonitorCrcErrorStatistics CRC错包统计值
#- 1.3.6.1.4.1.2011.5.25.41.1.7.1.1.8 # hwIfMonitorInputRate 接口入方向带宽占用率
#- 1.3.6.1.4.1.2011.5.25.41.1.7.1.1.10 # hwIfMonitorOutputRate 接口出方向带宽占用率
# 光模块信息
#- 1.3.6.1.2.1.47.1.1.1.1.1 # entPhysicalIndex 物理实体索引
- 1.3.6.1.2.1.47.1.1.1.1.7 # entPhysicalName 物理实体名 光模块接口名称
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.8 # hwEntityOpticalRxPower 光模块接收功率 单位 uW
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.9 # hwEntityOpticalTxPower 光模块发送功率 单位 uW
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.20 # hwEntityOpticalRxLowWarnThreshold 光模块接收功率过低的预警门限值 单位 dBm
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.21 # hwEntityOpticalRxHighWarnThreshold 光模块接收功率过高的预警门限值 单位 dBm
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.22 # hwEntityOpticalTxLowWarnThreshold 光模块发送功率过低的预警门限值 单位 dBm
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.23 # hwEntityOpticalTxHighWarnThreshold 光模块发送功率过高的预警门限值 单位 dBm
# 堆叠状态
- 1.3.6.1.4.1.2011.5.25.183.1.1 # hwStackRun 堆叠是否使能
- 1.3.6.1.4.1.2011.5.25.183.1.2 # hwStackTopoType 环形拓扑还是链式拓扑
- 1.3.6.1.4.1.2011.5.25.183.1.4 # hwStackSystemMac 堆叠系统MAC
- 1.3.6.1.4.1.2011.5.25.183.1.5 # hwStackIsStackDevice 设备是否在堆叠环境
- 1.3.6.1.4.1.2011.5.25.42.2.1.14 # hwMacGlobalStatistics 获取设备上的MAC地址数
- 1.3.6.1.4.1.2011.5.25.42.2.1.1 # hwL2MaxMacLimit MAC地址限定的最大规则数
max_repetitions: 30
retries: 3
timeout: 5s
lookups:
- source_indexes: [ifIndex]
lookup: ifAlias
# 如果新的索引唯一 可以删除原来的索引 true
#drop_source_indexes: false
- source_indexes: [ifIndex]
lookup: ifName
- source_indexes: [ifIndex]
lookup: ifOperStatus
- source_indexes: [ifIndex]
lookup: ifHighSpeed
- source_indexes: [entPhysicalIndex]
lookup: entPhysicalName
overrides:
ifAlias:
ignore: true
ifName:
ignore: true
ifOperStatus:
ignore: true
ifHighSpeed:
ignore: true
entPhysicalName:
ignore: true
filters:
dynamic: # 根据接口当前状态收集接口指标
- oid: 1.3.6.1.2.1.2.2.1.7
targets:
- "1.3.6.1.2.1.31.1.1.1.6"
- "1.3.6.1.2.1.31.1.1.1.10"
- "1.3.6.1.2.1.2.2.1.13"
- "1.3.6.1.2.1.2.2.1.19"
- "1.3.6.1.2.1.2.2.1.14"
- "1.3.6.1.2.1.2.2.1.20"
values: ["1"]
huawei_acc: # 华为接入交换机模块指标 未堆叠
walk:
# 接口信息
#- 1.3.6.1.2.1.2.2.1.1 # ifIndex 接口索引 该值大于零且全局唯一
#- 1.3.6.1.2.1.2.2.1.2 # ifDescr 描述接口的字符串
- 1.3.6.1.2.1.31.1.1.1.1 # ifName 由本地设备分配的接口名 同上指标 取其中之一
- 1.3.6.1.2.1.2.2.1.7 # ifAdminStatus 理想的接口状态
- 1.3.6.1.2.1.2.2.1.8 # ifOperStatus 接口当前的状态
- 1.3.6.1.2.1.31.1.1.1.18 # ifAlias 该节点是由网络管理员指定的接口别名 description命令
- 1.3.6.1.2.1.31.1.1.1.15 # ifHighSpeed 接口当前带宽 单位 Mbit/s
- 1.3.6.1.2.1.31.1.1.1.6 # ifHCInOctets 接口上接收到的字节总数 byte/s
- 1.3.6.1.2.1.31.1.1.1.10 # ifHCOutOctets 接口发送的字节总数 byte/s
- 1.3.6.1.2.1.2.2.1.13 # ifInDiscards 入方向的被丢弃的报文个数
- 1.3.6.1.2.1.2.2.1.19 # ifOutDiscards 出方向的被丢弃的报文个数
- 1.3.6.1.2.1.2.2.1.14 # ifInErrors 入方向出错报文个数
- 1.3.6.1.2.1.2.2.1.20 # ifOutErrors 出方向出错报文个数
#- 1.3.6.1.4.1.2011.5.25.41.1.7.1.1.2 # hwIfMonitorCrcErrorStatistics CRC错包统计值
#- 1.3.6.1.4.1.2011.5.25.41.1.7.1.1.8 # hwIfMonitorInputRate 接口入方向带宽占用率
#- 1.3.6.1.4.1.2011.5.25.41.1.7.1.1.10 # hwIfMonitorOutputRate 接口出方向带宽占用率
# 光模块信息
#- 1.3.6.1.2.1.47.1.1.1.1.1 # entPhysicalIndex 物理实体索引
- 1.3.6.1.2.1.47.1.1.1.1.7 # entPhysicalName 物理实体名 光模块接口名称
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.8 # hwEntityOpticalRxPower 光模块接收功率 单位 uW
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.9 # hwEntityOpticalTxPower 光模块发送功率 单位 uW
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.20 # hwEntityOpticalRxLowWarnThreshold 光模块接收功率过低的预警门限值 单位 dBm
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.21 # hwEntityOpticalRxHighWarnThreshold 光模块接收功率过高的预警门限值 单位 dBm
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.22 # hwEntityOpticalTxLowWarnThreshold 光模块发送功率过低的预警门限值 单位 dBm
- 1.3.6.1.4.1.2011.5.25.31.1.1.3.1.23 # hwEntityOpticalTxHighWarnThreshold 光模块发送功率过高的预警门限值 单位 dBm
- 1.3.6.1.4.1.2011.5.25.42.2.1.14 # hwMacGlobalStatistics 获取设备上的MAC地址数
- 1.3.6.1.4.1.2011.5.25.42.2.1.1 # hwL2MaxMacLimit MAC地址限定的最大规则数
max_repetitions: 30
retries: 3
timeout: 5s
lookups:
- source_indexes: [ifIndex]
lookup: ifAlias
#drop_source_indexes: false # 如果新的索引唯一 可以删除原来的索引 true
- source_indexes: [ifIndex]
lookup: ifName
- source_indexes: [ifIndex]
lookup: ifOperStatus
- source_indexes: [ifIndex]
lookup: ifHighSpeed
- source_indexes: [entPhysicalIndex]
lookup: entPhysicalName
overrides:
ifAlias:
ignore: true
ifName:
ignore: true
ifOperStatus:
ignore: true
ifHighSpeed:
ignore: true
entPhysicalName:
ignore: true
filters:
dynamic: # 根据接口当前状态收集接口指标
- oid: 1.3.6.1.2.1.2.2.1.7
targets:
- "1.3.6.1.2.1.31.1.1.1.6"
- "1.3.6.1.2.1.31.1.1.1.10"
- "1.3.6.1.2.1.2.2.1.13"
- "1.3.6.1.2.1.2.2.1.19"
- "1.3.6.1.2.1.2.2.1.14"
- "1.3.6.1.2.1.2.2.1.20"
values: ["1"]
模块说明
上面定义了华为交换机不同模块: huawei_common
、 huawei_core
、 huawei_agg
、 huawei_acc
,可以指定模块按需采集,避免全部拉取响应慢
生成采集配置文件
通过编译generator生成二进制可执行文件来生成采集文件
安装go环境
wget https://go.dev/dl/go1.20.5.linux-amd64.tar.gz
tar xf go1.20.5.linux-amd64.tar.gz
mv go /usr/local/
echo export PATH=\$PATH:/usr/local/go/bin > /etc/profile.d/go.sh
source /etc/profile
$ go version
go version go1.20.5 linux/amd64
# 代理加速
$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.cn,direct
编译generator
下载snmp_exporter源码
git clone https://github.com/prometheus/snmp_exporter.git
# 进入generator目录 编译generator
root@mon39:~# cd snmp_exporter/generator
root@mon39:~/snmp_exporter/generator# go build
root@mon39:~/snmp_exporter/generator# ls -lh generator
-rwxr-xr-x 1 root root 8.1M Jul 10 15:55 generator
生成snmp采集文件
# 解压MIB文件
root@mon39:~/snmp_exporter/generator# cp ~/MIB_V200R024C00SPC500.zip .
root@mon39:~/snmp_exporter/generator# unzip MIB_V200R024C00SPC500.zip
root@mon39:~/snmp_exporter/generator# ls -l MIB_V200R024C00SPC500/MIBs/
total 22940
-rw-r--r-- 1 root root 29574 Sep 29 2024 ATM-TC-MIB.mib
...
-rw-r--r-- 1 root root 650012 Sep 29 2024 HUAWEI-AAA-MIB.mib
-rw-r--r-- 1 root root 202807 Sep 29 2024 HUAWEI-ACL-MIB.mib
-rw-r--r-- 1 root root 39998 Sep 29 2024 HUAWEI-ALARM-MIB.mib
...
-rw-r--r-- 1 root root 37638 Sep 29 2024 VRRPV3-MIB.mib
# 备份generator.yml
root@mon39:~/snmp_exporter/generator# mv generator.yml generator.yml.bak
# 复制文件编辑好的采集文件
root@mon39:~/snmp_exporter/generator# cp ~/generator.yml .
# 执行生成采集配置
root@mon39:~/snmp_exporter/generator# ./generator --fail-on-parse-errors generate -m ./MIB_V200R024C00SPC500/MIBs -g ./generator.yml -o ./snmp_huawei_sw.yml
time=2023-07-20T00:34:29.796+08:00 level=INFO source=net_snmp.go:174 msg="Loading MIBs" from=./MIB_V200R024C00SPC500/MIBs
time=2023-07-20T00:34:30.266+08:00 level=INFO source=main.go:57 msg="Generating config for module" module=huawei_common
time=2023-07-20T00:34:30.360+08:00 level=INFO source=main.go:75 msg="Generated metrics" module=huawei_common metrics=13
time=2023-07-20T00:34:30.360+08:00 level=INFO source=main.go:57 msg="Generating config for module" module=huawei_core
time=2023-07-20T00:34:30.534+08:00 level=INFO source=main.go:75 msg="Generated metrics" module=huawei_core metrics=18
time=2023-07-20T00:34:30.534+08:00 level=INFO source=main.go:57 msg="Generating config for module" module=huawei_agg
time=2023-07-20T00:34:30.730+08:00 level=INFO source=main.go:75 msg="Generated metrics" module=huawei_agg metrics=19
time=2023-07-20T00:34:30.730+08:00 level=INFO source=main.go:57 msg="Generating config for module" module=huawei_acc
time=2023-07-20T00:34:30.923+08:00 level=INFO source=main.go:75 msg="Generated metrics" module=huawei_acc metrics=15
time=2023-07-20T00:34:30.930+08:00 level=INFO source=main.go:100 msg="Config written" file=/root/snmp_exporter/generator/snmp_huawei_sw.yml
部署snmp_exporter
root@mon39:~# wget https://github.com/prometheus/snmp_exporter/releases/download/v0.25.0/snmp_exporter-0.25.0.linux-amd64.tar.gz
root@mon39:~# tar xf snmp_exporter-0.25.0.linux-amd64.tar.gz
root@mon39:~# mv snmp_exporter-0.25.0.linux-amd64 /opt/snmp_exporter
root@mon39:~# cd /opt/snmp_exporter
root@mon39:/opt/snmp_exporter# mv snmp.yml snmp.yml.bak
root@mon39:/opt/snmp_exporter# mkdir conf
root@mon39:/opt/snmp_exporter# cp /root/snmp_exporter/generator/snmp_huawei_sw.yml conf/snmp_huawei_sw.yml
# cat snmp_huawei_sw.yml
# WARNING: This file was auto-generated using snmp_exporter generator, manual changes will be lost.
auths:
public_v2: # SNMP Exporter Web 对应 Auth:
community: sunday_public # 团体名
security_level: noAuthNoPriv
auth_protocol: MD5
priv_protocol: DES
version: 2
systemd管理
vim /etc/systemd/system/snmp_exporter.service
[Unit]
Description=snmp_exporter
After=network.target
[Service]
ExecStart=/opt/snmp_exporter/snmp_exporter --config.file=/opt/snmp_exporter/conf/*.yml --snmp.module-concurrency=3
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动服务
systemctl daemon-reload
systemctl start snmp-exporter
systemctl status snmp-exporter
root@mon39:/opt/snmp_exporter# ss -tunlp | grep 9116
tcp LISTEN 0 4096 *:9116 *:* users:(("snmp_exporter",pid=1349319,fd=3))
访问snmp_exporter web查看采集
Target: 交换机IP
Auth: yaml配置的public_v2
Module: 要采集的模块,多个用逗号分隔,如huawei_common,huawei_core
http://192.168.1.39:9116/snmp?target=192.168.1.2&auth=public_v2&module=huawei_common
测试同时采集两个模块
http://192.168.1.39:9116/snmp?target=192.168.1.2&auth=public_v2&module=huawei_common%2Chuawei_core
配置Prometheus
配置 Prometheus
定时从 SNMP Exporter
拉取采集数据,实现华为交换机的多设备任务采集。
mkdir /opt/prometheus/sd_config/
scrape_configs:
- job_name: "huawei_sw"
scrape_interval: 60s
scrape_timeout: 60s
file_sd_configs:
- files:
- /opt/prometheus/sd_config/huawei_sw.yml
refresh_interval: 2m # 热加载间隔
# 将/metrics 改为是 /snmp
metrics_path: /snmp
# 标签relabeling
relabel_configs:
- source_labels: ["__address__"]
target_label: __param_target
- source_labels: ["__param_target"]
target_label: instance
- target_label: __address__
# snmp_exporter 服务IP和端口
replacement: 192.168.1.39:9116
- source_labels: ["module"]
target_label: __param_module
- source_labels: ["auth"]
target_label: __param_auth
通过 file_sd_configs
方式可以热加载新修改的/opt/prometheus/sd_config/huawei_sw.yml
vim /opt/prometheus/sd_config/huawei_sw.yml
- labels:
# generator.yml中定义的指标模块名称 如果有多个可以写多个模块名
module: huawei_common,huawei_core
# generator.yml 中定义的认证模块名
auth: public_v2
# 自定义的标签 可选
brand: Huawei
model: S5720S-28X-LI-AC
targets:
- 192.168.1.2
# 可同时配置其他交换机采集指定模块
- labels:
module: huawei_common
auth: public_v2
brand: Huawei
model: S5720-36C-EI-AC
targets:
- 192.168.1.3
使用 Prometheus api
热加载 Prometheus
配置
curl -X POST localhost:9090/-/reload
curl -X GET localhost:9090/-/healthy
Grafana面板
https://oss.sundayhk.com/file/snmp/huawei_snmp_grafana.json
AlterManager
groups:
- name: 华为交换机告警
rules:
- alert: 交换机设备风扇状态
expr: hwEntityFanSpeed == 0
for: 1m
labels:
alertype: switch
severity: Critical
annotations:
description: "**{{ $labels.hostname }} - 设备风扇转速为 {{ $value }}% ** \n > 风扇状态值:{{ $labels.hwEntityFanState }} - 风扇在位状态值:{{ $labels.hwEntityFanPresent }}"
- alert: CPU使用率超限
expr: 0 < hwEntityCpuUsage{job=~"huawei_sw|huawei_sw"} >= 60
for: 5m
labels:
alertype: switch
severity: Critical
annotations:
description: "**{{ $labels.hostname }} - 交换机CPU使用率超限** \n > 当前使用率 = {{ $value }}%"
- alert: 内存使用率超限
expr: 0 < hwEntityMemUsage{job=~"huawei_sw|huawei_sw"} >= 85
for: 10m
labels:
alertype: switch
severity: Critical
annotations:
description: "**{{$labels.hwWlanIDIndexedApName}} - 交换机内存使用率超限** \n > 当前使用率 = {{ $value }}%"
链接
https://zhuanlan.zhihu.com/p/677630980
https://cloud.tencent.com/developer/article/1943784