0
点赞
收藏
分享

微信扫一扫

prometheus+Grafana交换机snmp流量-系统搭建

prometheus 收集

Grafana 展示

模块:流量模块snmp_explorter  ping模块 blackbox_explorter  告警模块Alertmanager

下载

下载目录:/opt

​​https://github.com/prometheus/prometheus/releases/download/v2.40.1/prometheus-2.40.1.linux-amd64.tar.gz​​

​​https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.linux-amd64.tar.gz​​

​​https://github.com/prometheus/blackbox_exporter/releases/download/v0.22.0/blackbox_exporter-0.22.0.linux-amd64.tar.gz​​

​​https://github.com/prometheus/snmp_exporter/tags​​


解压:

cd /opt
tar zxvf prometheus-2.40.1.linux-amd64.tar.gz
tar zxvf blackbox_exporter-0.22.0.linux-amd64.tar.gz
tar zxvf alertmanager-0.24.0.linux-amd64.tar.gz
tar zxvf snmp_exporter-0.20.0.tar.gz


prometheus

安装

​​https://prometheus.io/download/​​

#新增用户组
groupadd -r prometheus

#新建用户加入组
useradd -r -g prometheus -d / -s /sbin/nologin -c "prometheus user" prometheus


# 创建配置文件夹、db存放目录、并复制相关配置文件 
mkdir /etc/prometheus
mkdir /home/prometheus
cp /opt/prometheus-2.40.1.linux-amd64/prometheus /usr/local/bin/
cp /opt/prometheus-2.40.1.linux-amd64/prometheus.yml /etc/prometheus/



给相关文件夹赋权

chown -R prometheus:prometheus /etc/prometheus
chown -R prometheus:prometheus /home/prometheus/



创建系统启动脚本


vi /usr/lib/systemd/system/prometheus.service


[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/home/prometheus \
--storage.tsdb.retention=15d \
--web.read-timeout=5m \
--web.max-connections=10 \
--query.max-concurrency=20 \
--query.timeout=2m \
--web.enable-lifecycle
Restart=on-failure
[Install]
WantedBy=multi-user.target

注意:此处为设置选项(只做备注)

名称

作用

ExecStart

运行程序

config.file

配置文件

storage.tsdb.path

指定数据存放路径

storage.tsdb.retention

数据存放时间

web.read-timeou

读取超时时间

web.max-connections

最大连接并发数

query.max-concurrency

最大支持的并发查询量

query.timeout

查询超时时间


调试命令

systemctl enable prometheus
systemctl start prometheus
systemctl restart prometheus
systemctl status prometheus


检查服务是否开启

netstat -anlptu|grep :9090


grafana安装&配置


官网

​​https://grafana.com/grafana/download?pg=get&plcmt=selfmanaged-box1-cta1​​


下载安装

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.2.4-1.x86_64.rpm
yum install grafana-enterprise-9.2.4-1.x86_64.rpm


调试

/sbin/chkconfig --add grafana-server
systemctl enable grafana-server
systemctl start grafana-server
systemctl restart grafana-server
systemctl status grafana-server


验证

netstat -lntp | grep grafana

端口:3000
默认密码:admin
登录后强制改密码
http://172.21.192.24:3000


blackbox_exporter模块

blackbox exporter 可以实现对 ​http​​https​​tcp(可以实现服务器接口是否在线)​​icmp(实现主机探活)​​dns​的探测;


改名字

cd /opt
mv blackbox_exporter-0.22.0.linux-amd64 blackbox_exporter


配置系统服务

vi /etc/systemd/system/blackbox_exporter.service


[Unit]
Description=node_exporter
After=network.target
[Service]
ExecStart=/opt/blackbox_exporter/blackbox_exporter --config.file=/opt/blackbox_exporter/blackbox.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target


调试

systemctl enable blackbox_exporter
systemctl start blackbox_exporter
systemctl restart blackbox_exporter
systemctl status blackbox_exporter



验证

​​http://172.21.192.24​​:9115

netstat -lntp | grep blackbox
netstat -lntp | grep 9115


alertmanager模块

作用:告警模块

参考链接:​​https://www.cnblogs.com/hahaha111122222/p/14247590.html​​


配置

cd /opt
mv alertmanager-0.24.0.linux-amd64 alertmanager


配置系统服务

vi /etc/systemd/system/alertmanager.service


[Unit]
Description=node_exporter
After=network.target
[Service]
ExecStart=/opt/alertmanager/alertmanager --config.file=/opt/alertmanager/alertmanager.yml \
--storage.path=/opt/alertmanager/data \
--data.retention=24h --web.listen-address=0.0.0.0:9093 \
--cluster.listen-address=0.0.0.0:9094 \
--cluster.advertise-address=0.0.0.0:9094
Restart=on-failure
[Install]
WantedBy=multi-user.target


snmp_explorer模块

作用:主要用于对交换机snmp信息收集


安装依赖

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

go编译snmp

mv /opt/snmp_exporter-0.20.0 /opt/snmp_exporter


go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
# 指定为国内代理

cd /opt/snmp_exporter/
go build

cd generator/
go build


修改配置文件

(增加团体字)

vi /opt/snmp_exporter/snmp.yml


# if_mib模块 增加团体字配置
auth:
community: xsyx-2020



配置系统服务


vi /etc/systemd/system/snmp_exporter.service


[Unit]
Description=node_exporter
After=network.target
[Service]
ExecStart=/opt/snmp_exporter/snmp_exporter --config.file=/opt/snmp_exporter/snmp.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target


调试

systemctl enable snmp_exporter
systemctl start snmp_exporter
systemctl restart snmp_exporter
systemctl status snmp_exporter



验证

netstat -lntp | grep 9116

​​http://172.21.192.24:9116​​

测试

curl '​​http://172.21.192.24:9116/snmp?target=172.21.0.1&modu=if_mib​​'




平台

常用命令

用途

prometheus

/etc/prometheus/prometheus.yml

配置文件


curl -X POST ​​http://127.0.0.1:9090/-/reload​​

热重启


systemctl restart prometheus

重启


systemctl status prometheus

状态


netstat -ntlp

查看服务状态

snmp_exporter

/opt/snmp_exporter/snmp.yml

配置文件


systemctl restart snmp_exporter

重启


systemctl status snmp_exporter

状态

blackbox_exporter

/opt/blackbox_exporter/blackbox_ecporter/blackbox.yml

配置文件


systemctl restart blackbox_exporter

重启


systemctl status blackbox_exporter

状态

grafana

/etc/grafana/grafana.ini

配置文件


service grafana-server restart

重启


service grafana-server status

状态

prometheus关联snmp模块


vim /etc/prometheus/prometheus.yml


- job_name: 'L2-S6730'  # 交换机的名称表示采用Job做区分,然后多个交换机写多个Job对应即可
static_configs:
- targets: ['172.21.0.1'] # 交换机的IP地址
metrics_path: /snmp
params:
module: [if_mib] # 如果是其他设备,可以采用其他模块,比如cisco_wlc AP设备, ddwrt 软路由等等
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9116 # The SNMP exporter's real hostname:port.


172.21.192.94:3000




举报

相关推荐

0 条评论