Prometheus 采集snmp监控数据

Posted CIAS

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Prometheus 采集snmp监控数据相关的知识,希望对你有一定的参考价值。

download  snmp_exporter

snmp_exporter 一键监控安装脚本

vim /snmp_exporter.sh
#!/bin/sh
# -*- coding: utf-8 -*-
# Date: 2022/11/18

echo "download snmp_exporter"
sleep 2
wget -N -P /root/ https://github.com/prometheus/snmp_exporter/releases/download/v0.20.0/snmp_exporter-0.20.0.linux-amd64.tar.gz

echo "decompression snmp_exporter"
sleep 2
tar -zxf /root/snmp_exporter-0.20.0.linux-amd64.tar.gz -C /usr/local/

echo "services scenarios snmp_exporter"
sleep 2
cat >>/usr/lib/systemd/system/snmp_exporter.service<<EOF
[Unit]
Description=snmp_exporter
Documentation=https://github.com/prometheus/snmp_exporter
After=network.target

[Service]
ExecStart=/usr/local/snmp_exporter-0.20.0.linux-amd64/snmp_exporter \\
--config.file=/usr/local/snmp_exporter-0.20.0.linux-amd64/snmp.yml \\
--web.listen-address=:9116
--snmp.wrap-large-counters \\
--log.level=info
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

echo "firewall snmp_exporter port"
sleep 2
firewall-cmd —zone=public —add-port=9116/tcp —permanent && firewall-cmd —reload

echo "start snmp_exporter"
sleep 2
systemctl daemon-reload && systemctl enable --now snmp_exporter

执行安装

sh /snmp_exporter.sh

配置snmp.yml 

vim /usr/local/snmp_exporter-0.20.0.linux-amd64/snmp.yml
  • 增加以下内容到6088行
 version: 2  # SNMP版本,交换机配置多少就是多少,如果配置all ,那就随意选择
 auth:
    community: 1234.com # SNMP 认证密钥

重启服务

systemctl restart snmp_exporter

查看采集情况 

curl 'http://YOU_snmp_exporter_IP:9116/snmp?module=if_mib&target=YOU_SW_IP'

查看是否可以看到数据 

  • http://YOU_snmp_exporter_ip:9116
  • Target #是交换机IP
  • Module #是你的snmp.yml 配置文件内部定义的名称

Prometheus 配置文件配置

  • prometheus.yml
  • replacement 是snmp_exporter地址和端口
  - job_name: 'snmp_exporter'
    scrape_interval: 30s
    scrape_timeout: 30s
    static_configs:
      - targets: 
        - 192.168.14.3
        - 192.168.14.2
        - 192.168.14.1
    metrics_path: /snmp
    params:
      module: [if_mib] 
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: YOU_snmp_exporter_IP:9116

以上是关于Prometheus 采集snmp监控数据的主要内容,如果未能解决你的问题,请参考以下文章

prometheus数据采集exporter全家桶

Prometheus SNMP Exporter

Prometheus 监控思科交换机---snmp_exporter配置文件修改

Prometheus:Prometheus监控交换机(snmp)

prometheus监控系统之snmp-exporter部署来监控交换机端口流量

prometheus监控系统之snmp-exporter部署来监控交换机端口流量