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 |
prometheus
安装
https://prometheus.io/download/
#新增用户组 |
# 创建配置文件夹、db存放目录、并复制相关配置文件 |
给相关文件夹赋权
chown -R prometheus:prometheus /etc/prometheus |
创建系统启动脚本
vi /usr/lib/systemd/system/prometheus.service |
[Unit] |
注意:此处为设置选项(只做备注)
名称 | 作用 |
ExecStart | 运行程序 |
config.file | 配置文件 |
storage.tsdb.path | 指定数据存放路径 |
storage.tsdb.retention | 数据存放时间 |
web.read-timeou | 读取超时时间 |
web.max-connections | 最大连接并发数 |
query.max-concurrency | 最大支持的并发查询量 |
query.timeout | 查询超时时间 |
调试命令
systemctl enable 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 |
调试
/sbin/chkconfig --add 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 |
配置系统服务
vi /etc/systemd/system/blackbox_exporter.service |
[Unit] |
调试
systemctl enable blackbox_exporter |
验证
http://172.21.192.24:9115
netstat -lntp | grep blackbox |
alertmanager模块
作用:告警模块
参考链接:https://www.cnblogs.com/hahaha111122222/p/14247590.html
配置
cd /opt |
配置系统服务
vi /etc/systemd/system/alertmanager.service |
[Unit] |
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 |
修改配置文件
(增加团体字)
vi /opt/snmp_exporter/snmp.yml |
# if_mib模块 增加团体字配置 |
配置系统服务
vi /etc/systemd/system/snmp_exporter.service |
[Unit] |
调试
systemctl enable 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对应即可 |
172.21.192.94:3000