prometheus监控交换机

本例以监控华为交换机为例,prometheus环境搭建见前面的文章。

1. 环境准备

yum install -y gcc gcc-g++ make net-snmp net-snmp-utils net-snmp-libs net-snmp-devel go

2. 交换机配置

snmp-agent
snmp-agent sys-info version v2c
snmp-agent community read cipher zZPBPtYcIZ1tM   # 密码,可修改
snmp-agent target-host trap address udp-domain 192.168.32.146 params securityname cipher zZPBPtYcIZ1tM
snmp-agent trap enable
snmp-agent protocol source-interface vlanif 206

3. 测试snmp

snmpwalk -v2c -c zZPBPtYcIZ1tM sw-ip  .1
# 获取到数据表示成功

4. 配置snmp_exporter_generator

wget https://github.com/prometheus/snmp_exporter/releases/download/v0.21.0/snmp_exporter-0.21.0.linux-amd64.tar.gz
tar -zxvf snmp_exporter-0.21.0.tar.gz
mv snmp_exporter-0.21.0 snmp_exporter-generator
cd snmp_exporter-generator/generator
mkdir mibs  #将mib文件上传至本目录

华为MIB文件下载地址:

https://download.csdn.net/download/m0_60169980/88634577

5. 修改generator.yml

cp generator.yml generator.yml.backup
vim  generator.yml
#generator.yml:
modules:
  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.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.5.25.31.1.1.10.1.7 #hwEntityFanState
      - 1.3.6.1.4.1.2011.5.25.31.1.1.14.1.3 #hwSystemPowerUsedPower
      - 1.3.6.1.4.1.2011.5.25.31.1.1.1.1.9  #hwEntityMemSize
      - 1.3.6.1.4.1.2011.6.9.1.4.2.1.3      #hwStorageSpace
      - 1.3.6.1.4.1.2011.6.9.1.4.2.1.4      #hwStorageSpaceFree 
    #max_repetitions: 3
    #retries: 3
    #timeout: 25s
    version: 2
    auth:
      community: zZPBPtYcIZ1tM
    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

6. 生成snmp.yml

#当前路径:/root/snmp_exporter-generator/generator
export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct
go build
export MIBDIRS=mibs
./generator generate

7. snmp_exporter下载

wget https://github.com/prometheus/snmp_exporter/releases/download/v0.21.0/snmp_exporter-0.21.0.linux-386.tar.gz
tar -zxvf snmp_exporter-0.21.0.linux-386.tar.gz
mv snmp_exporter-0.21.0.linux-386 /home/snmp_exporter

8. 将snmp_exporter的配置文件替换为生成的snmp.yml

cd /home/snmp_exporter/
cp /root/snmp_exporter-generator/generator/snmp.yml .

9. snmp_exporter.service

cat /etc/systemd/system/snmp_exporter.service
-------------------------------------
[Unit]
Description=SNMP Exporter
After=network-online.target

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

[Install]
WantedBy=multi-user.target
-------------------------------------
systemctl daemon-reload
systemctl enable snmp_exporter.service
systemctl start snmp_exporter.service
systemctl status snmp_exporter.service
netstat -tuplan | grep 9116

10. prometheus.yml

  - job_name: 'snmp'
    scrape_interval: 1m
    scrape_timeout: 30s
    static_configs:
      - targets:
        - 200.200.10.2  #交换机ip
        - 192.168.110.2 
      # - ....
    metrics_path: /snmp
    params:
      module: [HUAWEI]  
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 192.168.32.146:9116  
-------------------------------------       
./promtool check config prometheus.yml  #检查配置文件
systemctl restart prometheus.service

11. grafana面板id

Grafana仪表盘用(AKA SNMP Network),通用的仪表盘,h3c也可以
安装id:15473

SNMP_华为交换机
安装id:14634

prometheus监控交换机_第1张图片

你可能感兴趣的:(prometheus,prometheus)