0
点赞
收藏
分享

微信扫一扫

prometheus 监控华为交换机

回溯 2023-03-02 阅读 49

一、环境

交换机:huawei S5735 prometheus: 使用docker镜像,监听 9090 端口

granfana: 使用docker镜像,监听 3000 端口(华为交换机 使用11169模板)

snmp-exporter: ​​https://github.com/prometheus/snmp_exporter​​​下载最新版,监听 9116 端口

alertmanager: ​​​https://github.com/prometheus/alertmanager​​下载最新版,监听 9093, 9094 端口

下载华为交换机的mib信息:华为官方网站的软件下载可以找到

​​​​https://support.huawei.com/enterprise/zh​​

搜索你的型号

二、配置交换机

详细配置说明可参考官网:​​https://support.huawei.com/enterprise/zh/doc/EDOC1000178160/40dfdfef​​

##进入system-view模式
system-view

##开启snmp-agent:
snmp-agent

##设置团体名称(有复杂性要求):
snmp-agent community read cipher Tbkswitch

##开启snmp所有版本:
snmp-agent sys-info version all

##设置接受snmp trap信息的服务器:
snmp-agent target-host trap address udp-domain 192.168.1.200 params securityname cipher Tbkswitch

##开启snmp trap:
snmp-agent trap enable

##打开snmp接口访问:
snmp-agent protocol source-status all-interface

三、配置服务器

1、安装依赖:

yum install gcc make net-snmp net-snmp-utils net-snmp-libs net-snmp-devel

2、测试能否获取交换机snmp信息:

snmpwalk -v 2c -c Tbkswitch 192.168.101.1

3、安装go语言环境:

yum install go

4、修改go环境变量国内代理地址:

go env -w GO111MODULE=on

go env -w GOPROXY=https://goproxy.cn,direct

5、获取snmp-exporter源码包,包括generator源码包。

go get github.com/prometheus/snmp_exporter/generator

6、默认go安装到当前用户目录下,如当前用户为root,则下载的的源码包则会放到

/root/go/pkg/mod/github.com/prometheus/snmp_exporter@v0.20.0下

7、进入下载的generator目录

cd /root/go/pkg/mod/github.com/prometheus/snmp_exporter@v0.20.0/generator

8、通过rzsz工具拷贝mib文件到当前目录,解压得到MIBS目录,把目录重命名为mibs

9、编译generator:

go build

10、设置环境变量:


export MIBDIRS=mib

11、备份原generator.yml文件:


mv generator.yml generator.yml.bak

12、重新建立一个新的generator.yml:

配置模板参考/root/go/src/github.com/prometheus/snmp_exporter/generator目录下的README.md文档


modules:
huawei_mib:
walk:
- sysUpTime
- interfaces
- ifXTable
- sysDescr
- sysName
- 1.3.6.1.2.1.31.1.1.1.1
version: 2
auth:
community: Tbkswitch
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
overrides:
ifAlias:
ignore: true
ifDescr:
ignore: true
ifName:
ignore: true
ifType:
type: EnumAsInfo

13、使用./generator生成snmp.yml:

./generator generate

14、进入snmp_exporter目录并替换snmp.yml文件(本例放到/app/snmp_exporter下)


cd /app/snmp_exporter

mv snmp.yml snmp.yml.bak

cp /root/go/src/github.com/prometheus/snmp_exporter/generator/snmp.yml ./

15、添加snmp_exporter到服务:


vim /etc/systemd/system/snmp_exporter.service
[Unit]
Description=snmp_exporter
After=network.target

[Service]
ExecStart=/app/snmp_exporter/snmp_exporter --config.file=/app/snmp_exporter/snmp.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target

16、启动snmp_exporter:

systemctl start snmp_exporter

查看状态和端口:


systemctl status snmp_exporter

ss -tunlp | grep snmp_exporter

17、访问http://192.168.1.200:9116 打开snmp exporter的测试页面:

四、在Prometheus配置文件中添加数据节点

1、vim /srv/docker_data/prometheus/conf/prometheus.yml

- job_name: 'TBK-S5375-CK4F'
static_configs:
- targets: ['192.168.101.1']
metrics_path: /snmp
params:
module: [huawei_mib]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.1.200:9116

2、重启prometheus读取新配置:

docker restart 2fc6f0e49b7c

3、访问http://192.168.1.200:9090/targets

4、ganfana添加dashboard:

登录ganfana:http://192.168.1.200:3000

通过搜索import官网的dashboard,如这里添加11169


举报

相关推荐

0 条评论