依赖模块进行安装
1、yum install -y epel-release.noarch 2、yum -y groupinstall Development tools 3、yum install -y wget net-snmp net-snmp-utils net-snmp-libs net-snmp-devel golang p7zip*
2、测试snmp连通性
[root@node-2 ~]# snmpwalk -v 3 -u 5gmec -l authPriv -a md5 -A 5G-MEC-net -x aes -X 5G-MEC-net 1.41.X.X sysname SNMPv2-MIB::sysName.0 = STRING: xxx-xxx-xxx [root@node-2 ~]#
经验证,snmp设备信息可以正常获取
3、通过git 下载snmp_exporter
切换到根目录,git下载完成后,您可以看到根目录了一个 snmp_exporter的目录
[root@node-2 ~]# cd /opt [root@node-2 /opt]# git clone https://github.com/prometheus/snmp_exporter.git Cloning into 'snmp_exporter'... remote: Enumerating objects: 7038, done. remote: Counting objects: 100% (6/6), done. remote: Compressing objects: 100% (6/6), done. remote: Total 7038 (delta 1), reused 1 (delta 0), pack-reused 7032 Receiving objects: 100% (7038/7038), 8.90 MiB | 2.03 MiB/s, done. Resolving deltas: 100% (3877/3877), done. [root@node-2 /opt]# ls -al | grep snmp drwxr-xr-x 11 root root 4096 May 17 11:18 snmp_exporter [root@node-2 /opt]#
4、设置go国内代理
go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn,direct
5、编译生成snmp_exportr
[root@node-2 snmp_exporter]# go build
go: downloading github.com/prometheus/exporter-toolkit v0.7.1
go: downloading github.com/prometheus/client_model v0.2.0
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/cespare/xxhash/v2 v2.1.2
go: downloading github.com/golang/protobuf v1.5.2
go: downloading github.com/prometheus/procfs v0.7.3
go: downloading google.golang.org/protobuf v1.26.0
go: downloading github.com/pkg/errors v0.9.1
go: downloading golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
go: downloading golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
go: downloading github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
go: downloading golang.org/x/net v0.0.0-20220225172249-27dd8689420f
go: downloading golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b
go: downloading github.com/jpillora/backoff v1.0.0
go: downloading golang.org/x/text v0.3.7
[root@node-2 snmp_exporter]# ls -al | grep snmp_exporter
-rwxr-xr-x 1 root root 15312819 May 18 13:02 snmp_exporter
[root@node-2 snmp_exporter]#
6、snmp_exporter目录结构与snmp_generator编译
[root@node-1 snmp_exporter]# tree
.
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── collector
│ ├── collector.go
│ └── collector_test.go
├── config
│ └── config.go
├── config_test.go
├── CONTRIBUTING.md
├── Dockerfile
├── examples
│ └── systemd
│ └── snmp_exporter.service
├── generator
│ ├── config.go
│ ├── Dockerfile
│ ├── FORMAT.md
│ ├── generator.yml
│ ├── main.go
│ ├── Makefile
│ ├── net_snmp.go
│ ├── README.md
│ ├── tree.go
│ └── tree_test.go
├── go.mod
├── go.sum
├── LICENSE
├── main.go
├── MAINTAINERS.md
├── Makefile
├── Makefile.common
├── NOTICE
├── README.md
├── SECURITY.md
├── snmp-mixin
│ ├── alerts
│ │ ├── snmp_general.yml
│ │ └── snmp_ubiquiti_wifi.yml
│ ├── dashboards
│ │ ├── snmp_ubiquiti_access_point.json
│ │ └── snmp_ubiquiti_wifi.json
│ ├── Makefile
│ ├── mixin.libsonnet
│ ├── README.md
│ └── rules
│ └── rules.yaml
├── snmp.yml
├── testdata
│ ├── snmp-auth.yml
│ └── snmp-with-overrides.yml
└── VERSION
10 directories, 41 files
[root@node-1 snmp_exporter]#
至此,可以看到 /snmp_exporter路径下有一个generator的目录,该目录下在编译前是没有generator文件和mibs文件夹的,编译,生成mibs文件夹后
[root@node-2 /]# cd opt/snmp_exporter/generator/
go build
make mibs
[root@node-2 generator]# ls -al
total 6564
drwxr-xr-x 3 root root 210 May 18 12:40 .
drwxr-xr-x 11 root root 4096 May 18 13:02 ..
-rw-r--r-- 1 root root 1931 May 17 11:15 config.go
-rw-r--r-- 1 root root 255 May 17 11:15 Dockerfile
-rw-r--r-- 1 root root 2492 May 17 11:15 FORMAT.md
-rwxr-xr-x 1 root root 6569264 May 17 11:29 generator
-rw-r--r-- 1 root root 13282 May 18 10:30 generator.yml
-rw-r--r-- 1 root root 4920 May 17 11:15 main.go
-rw-r--r-- 1 root root 10950 May 17 11:15 Makefile
drwxr-xr-x 5 root root 110 May 17 18:08 mibs
-rw-r--r-- 1 root root 6722 May 17 11:15 net_snmp.go
-rw-r--r-- 1 root root 9789 May 17 11:15 README.md
-rw-r--r-- 1 root root 14326 May 17 11:15 tree.go
-rw-r--r-- 1 root root 58192 May 17 11:15 tree_test.go
[root@node-2 generator]#
可以看到/opt/snmp_exporter/generator目录下多了一个generator文件和mibs文件夹,然后我们可以去H3C官网 link把需要的mib文件全部下载下来,然后放到mibs文件夹里,总共是有439个文件之多。
[root@node-2 mibs]# ls -al | wc -l
439
[root@node-2 mibs]#
7、创建新的generator.yml文件,并删除原文件
[root@node-2 generator]# rm -rf generator.yml
[root@node-2 generator]# vim generator.yml
[root@node-2 generator]#
附上完整的generator.yml,该模板用的是snmp v3协议。
modules: H3C: walk: - 1.3.6.1.2.1.1.1 #sysDescr - 1.3.6.1.2.1.1.3 #sysUpTimeInstance - 1.3.6.1.2.1.1.5 #sysName - 1.3.6.1.2.1.2.1 #ifNumber - 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.2.2.1.3 #ifType - 1.3.6.1.2.1.2.2.1.5 #ifSpeed - 1.3.6.1.2.1.31.1.1.1.15 #ifHighSpeed - 1.3.6.1.2.1.31.1.1.1.18 #ifAlias - 1.3.6.1.2.1.2.2.1.8 #ifOperStatus - 1.3.6.1.2.1.2.2.1.13 #ifInDiscards - 1.3.6.1.2.1.2.2.1.14 #ifInErrors - 1.3.6.1.2.1.2.2.1.19 #ifOutDiscards - 1.3.6.1.2.1.2.2.1.20 #ifOutErrors - 1.3.6.1.2.1.31.1.1.1.1 #ifName - 1.3.6.1.2.1.2.2.1.10 #ifInOctets - 1.3.6.1.2.1.2.2.1.16 #ifOutOctets - 1.3.6.1.2.1.31.1.1.1.6 #ifHCInOctets - 1.3.6.1.2.1.31.1.1.1.10 #ifHCOutOctets - 1.3.6.1.2.1.47.1.1.1.1.2 #entPhysicalDescr - 1.3.6.1.2.1.47.1.1.1.1.5 #entPhysicalClass - 1.3.6.1.2.1.47.1.1.1.1.7 #entPhysicalName - 1.3.6.1.4.1.25506.2.6.1.1.1.1.6 #hh3cEntityExtCpuUsage - 1.3.6.1.4.1.25506.2.6.1.1.1.1.8 #hh3cEntityExtMemUsage - 1.3.6.1.4.1.25506.2.6.1.1.1.1.12 #hh3cEntityExtTemperature - 1.3.6.1.4.1.25506.2.149.1.1.1.4 #hh3cSessionStatCount FW - 1.3.6.1.4.1.25506.8.35.9.1.1.1.2 #hh3cDevMFanStatus - 1.3.6.1.4.1.25506.8.35.9.1.2.1.2 #hh3cDevMPowerStatus max_repetitions: 3 retries: 3 timeout: 25s version: 3 auth: username: 5gmec password: 此处填写自己的密码 auth_protocol: MD5 priv_protocol: AES priv_password: 此处填写自己的密码 security_level: authPriv lookups: - source_indexes: [ifIndex] lookup: ifAlias - source_indexes: [ifIndex] lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr - source_indexes: [ifIndex] lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName - source_indexes: [hh3cEntityExtPhysicalIndex] lookup: 1.3.6.1.2.1.47.1.1.1.1.2 #entPhysicalDescr - source_indexes: [hh3cEntityExtPhysicalIndex] lookup: 1.3.6.1.2.1.47.1.1.1.1.5 #entPhysicalClass - source_indexes: [hh3cEntityExtPhysicalIndex] lookup: 1.3.6.1.2.1.47.1.1.1.1.7 #entPhysicalName overrides: ifAlias: ignore: true # Lookup metric ifDescr: ignore: true # Lookup metric ifName: ignore: true # Lookup metric ifType: ignore: true # Lookup metric entPhysicalDescr: ignore: true # Lookup metric entPhysicalName: ignore: true # Lookup metric entPhysicalClass: ignore: true # Lookup metric HUAWEI: walk: - 1.3.6.1.2.1.1.1 #sysDescr - 1.3.6.1.2.1.1.3 #sysUpTimeInstance - 1.3.6.1.2.1.1.5 #sysName - 1.3.6.1.2.1.2.1 #ifNumber - 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.2.2.1.3 #ifType - 1.3.6.1.2.1.2.2.1.5 #ifSpeed - 1.3.6.1.2.1.31.1.1.1.15 #ifHighSpeed - 1.3.6.1.2.1.31.1.1.1.18 #ifAlias - 1.3.6.1.2.1.2.2.1.8 #ifOperStatus - 1.3.6.1.2.1.2.2.1.13 #ifInDiscards - 1.3.6.1.2.1.2.2.1.14 #ifInErrors - 1.3.6.1.2.1.2.2.1.19 #ifOutDiscards - 1.3.6.1.2.1.2.2.1.20 #ifOutErrors - 1.3.6.1.2.1.31.1.1.1.1 #ifName - 1.3.6.1.2.1.2.2.1.10 #ifInOctets - 1.3.6.1.2.1.2.2.1.16 #ifOutOctets - 1.3.6.1.2.1.31.1.1.1.6 #ifHCInOctets - 1.3.6.1.2.1.31.1.1.1.10 #ifHCOutOctets - 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.1.1.5 #hwEntityCpuUsage - 1.3.6.1.4.1.2011.5.25.31.1.1.1.1.7 #hwEntityMemUsage - 1.3.6.1.4.1.2011.5.25.31.1.1.1.1.11 #hwEntityTemperature - 1.3.6.1.4.1.2011.6.122.15.1.2.1.4 #hwSecStatMonTotalSess FW - 1.3.6.1.4.1.2011.5.25.31.1.1.10.1.7 #hwEntityFanState max_repetitions: 3 retries: 3 timeout: 25s version: 3 auth: username: 5gmec password: 此处填写自己的密码 auth_protocol: MD5 priv_protocol: AES priv_password: 此处填写自己的密码 security_level: authPriv lookups: - source_indexes: [ifIndex] lookup: ifAlias - source_indexes: [ifIndex] lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr - source_indexes: [ifIndex] lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName - source_indexes: [entPhysicalIndex] lookup: 1.3.6.1.2.1.47.1.1.1.1.7 #entPhysicalName overrides: ifAlias: ignore: true # Lookup metric ifDescr: ignore: true # Lookup metric ifName: ignore: true # Lookup metric ifType: ignore: true # Lookup metric entPhysicalIndex: ignore: true # Lookup metric entPhysicalName: ignore: true # Lookup metric if_mib: walk: - 1.3.6.1.2.1.1.1 #sysDescr - 1.3.6.1.2.1.1.3 #sysUpTimeInstance - 1.3.6.1.2.1.1.5 #sysName - 1.3.6.1.2.1.2.1 #ifNumber - 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.2.2.1.3 #ifType - 1.3.6.1.2.1.2.2.1.5 #ifSpeed - 1.3.6.1.2.1.31.1.1.1.15 #ifHighSpeed - 1.3.6.1.2.1.31.1.1.1.18 #ifAlias - 1.3.6.1.2.1.2.2.1.8 #ifOperStatus - 1.3.6.1.2.1.2.2.1.13 #ifInDiscards - 1.3.6.1.2.1.2.2.1.14 #ifInErrors - 1.3.6.1.2.1.2.2.1.19 #ifOutDiscards - 1.3.6.1.2.1.2.2.1.20 #ifOutErrors - 1.3.6.1.2.1.31.1.1.1.1 #ifName - 1.3.6.1.2.1.2.2.1.10 #ifInOctets - 1.3.6.1.2.1.2.2.1.16 #ifOutOctets - 1.3.6.1.2.1.31.1.1.1.6 #ifHCInOctets - 1.3.6.1.2.1.31.1.1.1.10 #ifHCOutOctets max_repetitions: 3 retries: 3 timeout: 25s version: 3 auth: username: 5gmec password: 此处填写自己的密码 auth_protocol: MD5 priv_protocol: AES priv_password: 此处填写自己的密码 security_level: authPriv lookups: - source_indexes: [ifIndex] lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr - source_indexes: [ifIndex] 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: ignore: true # Lookup metric HILLSTONE: walk: - 1.3.6.1.4.1.28557.2.2.1.7 - 1.3.6.1.4.1.28557.2.2.1.3 #sysCPU HILLSTONE - 1.3.6.1.4.1.28557.2.2.1.17 #sysMemRatio HILLSTONE - 1.3.6.1.4.1.28557.2.28.1.2.1.1 #hillstoneTemperatureIndex - 1.3.6.1.4.1.28557.2.28.1.2.1.2 #hillstoneTemperatureDescr - 1.3.6.1.4.1.28557.2.28.1.2.1.3 #hillstoneTemperatureValue - 1.3.6.1.4.1.28557.2.30.1.1.1.6 #hillstoneVsysCurSession FW max_repetitions: 3 retries: 3 timeout: 10s version: 3 auth: username: 5gmec1 password: 此处填写自己的密码 auth_protocol: MD5 priv_protocol: AES priv_password: 此处填写自己的密码 security_level: authPriv lookups: - source_indexes: [hillstoneTemperatureIndex] lookup: 1.3.6.1.4.1.28557.2.28.1.2.1.2 #hillstoneTemperatureDescr - source_indexes: [hillstoneTemperatureIndex] lookup: 1.3.6.1.4.1.28557.2.28.1.2.1.3 #hillstoneTemperatureValue overrides: hillstoneTemperatureIndex: ignore: true hillstoneTemperatureDescr: ignore: true HILLSTONE_new: walk: - 1.3.6.1.2.1.1.1 #sysDescr - 1.3.6.1.2.1.1.3 #sysUpTimeInstance - 1.3.6.1.2.1.1.5 #sysName - 1.3.6.1.2.1.2.1 #ifNumber - 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.2.2.1.3 #ifType - 1.3.6.1.2.1.2.2.1.5 #ifSpeed - 1.3.6.1.2.1.31.1.1.1.15 #ifHighSpeed - 1.3.6.1.2.1.31.1.1.1.18 #ifAlias - 1.3.6.1.2.1.2.2.1.8 #ifOperStatus - 1.3.6.1.2.1.2.2.1.13 #ifInDiscards - 1.3.6.1.2.1.2.2.1.14 #ifInErrors - 1.3.6.1.2.1.2.2.1.19 #ifOutDiscards - 1.3.6.1.2.1.2.2.1.20 #ifOutErrors - 1.3.6.1.2.1.31.1.1.1.1 #ifName - 1.3.6.1.2.1.2.2.1.10 #ifInOctets - 1.3.6.1.2.1.2.2.1.16 #ifOutOctets - 1.3.6.1.2.1.31.1.1.1.6 #ifHCInOctets - 1.3.6.1.2.1.31.1.1.1.10 #ifHCOutOctets - 1.3.6.1.4.1.28557.2.2.1.7 - 1.3.6.1.4.1.28557.2.2.1.3 #sysCPU HILLSTONE - 1.3.6.1.4.1.28557.2.2.1.17 #sysMemRatio HILLSTONE - 1.3.6.1.4.1.28557.2.28.1.2.1.1 #hillstoneTemperatureIndex - 1.3.6.1.4.1.28557.2.28.1.2.1.2 #hillstoneTemperatureDescr - 1.3.6.1.4.1.28557.2.28.1.2.1.3 #hillstoneTemperatureValue - 1.3.6.1.4.1.28557.2.30.1.1.1.6 #hillstoneVsysCurSession FW max_repetitions: 3 retries: 3 timeout: 25s version: 3 auth: username: 5gmec password: 此处填写自己的密码 auth_protocol: MD5 priv_protocol: AES priv_password: 此处填写自己的密码 security_level: authPriv lookups: - source_indexes: [ifIndex] lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr - source_indexes: [ifIndex] lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName - source_indexes: [hillstoneTemperatureIndex] lookup: 1.3.6.1.4.1.28557.2.28.1.2.1.2 #hillstoneTemperatureDescr - source_indexes: [hillstoneTemperatureIndex] lookup: 1.3.6.1.4.1.28557.2.28.1.2.1.3 #hillstoneTemperatureValue overrides: ifAlias: ignore: true # Lookup metric ifDescr: ignore: true # Lookup metric ifName: ignore: true # Lookup metric ifType: ignore: true # Lookup metric hillstoneTemperatureIndex: ignore: true hillstoneTemperatureDescr: ignore: true SHHUAWEI: walk: - 1.3.6.1.2.1.1.1 #sysDescr - 1.3.6.1.2.1.1.3 #sysUpTimeInstance - 1.3.6.1.2.1.1.5 #sysName - 1.3.6.1.2.1.2.1 #ifNumber - 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.2.2.1.3 #ifType - 1.3.6.1.2.1.2.2.1.5 #ifSpeed - 1.3.6.1.2.1.31.1.1.1.15 #ifHighSpeed - 1.3.6.1.2.1.31.1.1.1.18 #ifAlias - 1.3.6.1.2.1.2.2.1.8 #ifOperStatus - 1.3.6.1.2.1.2.2.1.13 #ifInDiscards - 1.3.6.1.2.1.2.2.1.14 #ifInErrors - 1.3.6.1.2.1.2.2.1.19 #ifOutDiscards - 1.3.6.1.2.1.2.2.1.20 #ifOutErrors - 1.3.6.1.2.1.31.1.1.1.1 #ifName - 1.3.6.1.2.1.31.1.1.1.6 #ifHCInOctets - 1.3.6.1.2.1.31.1.1.1.10 #ifHCOutOctets - 1.3.6.1.2.1.2.2.1.10 #ifInOctets - 1.3.6.1.2.1.2.2.1.16 #ifOutOctets - 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.1.1.5 #hwEntityCpuUsage huawei - 1.3.6.1.4.1.2011.5.25.31.1.1.1.1.7 #hwEntityMemUsage huawei - 1.3.6.1.4.1.2011.5.25.31.1.1.1.1.11 #hwEntityTemperature - 1.3.6.1.4.1.2011.6.122.15.1.2.1.4 #hwSecStatMonTotalSess FW - 1.3.6.1.4.1.2011.5.25.31.1.1.10.1.7 #hwEntityFanState max_repetitions: 3 retries: 3 timeout: 25s version: 2 auth: community: 此处填写自己的community lookups: - source_indexes: [ifIndex] lookup: ifAlias - source_indexes: [ifIndex] lookup: 1.3.6.1.2.1.2.2.1.2 # ifDescr - source_indexes: [ifIndex] lookup: 1.3.6.1.2.1.31.1.1.1.1 # ifName - source_indexes: [entPhysicalIndex] lookup: 1.3.6.1.2.1.47.1.1.1.1.7 #entPhysicalName overrides: ifAlias: ignore: true # Lookup metric ifDescr: ignore: true # Lookup metric ifName: ignore: true # Lookup metric ifType: ignore: true # Lookup metric entPhysicalIndex: ignore: true # Lookup metric entPhysicalName: ignore: true # Lookup metric dp: walk: - 1.3.6.1.2.1.1.1 #sysDescr - 1.3.6.1.2.1.1.3 #sysUpTimeInstance - 1.3.6.1.2.1.1.5 #sysName - 1.3.6.1.2.1.2.1 #ifNumber - 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.2.2.1.3 #ifType - 1.3.6.1.2.1.2.2.1.5 #ifSpeed - 1.3.6.1.2.1.31.1.1.1.15 #ifHighSpeed - 1.3.6.1.2.1.31.1.1.1.18 #ifAlias - 1.3.6.1.2.1.2.2.1.8 #ifOperStatus - 1.3.6.1.2.1.2.2.1.13 #ifInDiscards - 1.3.6.1.2.1.2.2.1.14 #ifInErrors - 1.3.6.1.2.1.2.2.1.19 #ifOutDiscards - 1.3.6.1.2.1.2.2.1.20 #ifOutErrors - 1.3.6.1.2.1.31.1.1.1.1 #ifName - 1.3.6.1.2.1.2.2.1.10 #ifInOctets - 1.3.6.1.2.1.2.2.1.16 #ifOutOctets - 1.3.6.1.2.1.31.1.1.1.6 #ifHCInOctets - 1.3.6.1.2.1.31.1.1.1.10 #ifHCOutOctets - 1.3.6.1.4.1.31648.3.15.3 #dpCpuRatio - 1.3.6.1.4.1.31648.3.15.5 #dpMemRatio - 1.3.6.1.4.1.31648.3.15.4 #dpCpuTemperature - 1.3.6.1.4.1.31648.3.15.9 #dpSession - 1.3.6.1.4.1.31648.3.15.11.1.3 #dpPowerStatus - 1.3.6.1.4.1.31648.3.15.12.1.3 #dpFanStatus max_repetitions: 3 retries: 3 timeout: 25s version: 3 auth: username: 5gmec password: 此处填写自己的密码 auth_protocol: MD5 priv_protocol: AES priv_password: 此处填写自己的密码 security_level: authPriv 标签:
ymp4系列圆形电连接器