当前位置: 首页 > news >正文

Prometheus学习

监控架构介绍:

基本架构:

Prometheus 和 Zabbix 的对比:

安装和使用:

  • Prometheus 采集、存储数据
  • Grafana 用于图表展示
  • alertmanager 用于接收 Prometheus 发送的警告信息
  • node-exporter 用于收集操作系统和硬件信息的 metrics
# 从创建一个专门的 prometheus 用户
useradd -M -s /usr/sbin/nologin prometheus
# 更改 prometheus 用户的文件权限
chown prometheus:prometheus -R /opt/prometheus#  Prometheus 以 prometheus 用户身份运行
sudo chown -R prometheus:prometheus /opt/prometheus/prometheus/data
# 755 权限设置允许 Prometheus 用户读写目录,但其他用户只能读和执行(进入目录) 
sudo chmod -R 755 /opt/prometheus/prometheus/data

在这里插入图片描述
在这里插入图片描述

Prometheus Server 安装:

在这里插入图片描述

# 下载 prometheus 二进制压缩包
wget https://github.com/prometheus/prometheus/releases/download/v2.53.2/prometheus-2.53.2.linux-amd64.tar.gz# 解压
tar -zxvf prometheus-2.53.2.linux-amd64.tar.gzmkdir /opt/prometheus -p
mv prometheus-2.53.2.linux-amd64 /opt/prometheus/prometheus# 创建 systemd 服务
cat > /etc/systemd/system/prometheus.service << "EOF"
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview
After=network-online.target[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/prometheus/prometheus \-- config.file=/opt/prometheus/prometheus/prometheus.yml \-- storage.tsdb.path=/opt/prometheus/prometheus/data \  # 数据存储的路径-- storage.tsdb.retention.time=60d \  # 数据存储的时长-- wed.enable-lifecycle  # 热加载配置[Install]
WantedBy=multi-user.target
EOF

在这里插入图片描述

# 重启 Prometheus
systemctl daemon-reload
systemctl start prometheus.service
# 设置 Prometheus 为开机自启
systemctl enable prometheus.service
# 检查 Prometheus 服务的开启状态
systemctl status prometheus.service# 查看 Prometheus 服务的日志,进行故障排除
journalctl -u prometheus.service -f 

在这里插入图片描述
prometheus 监控指标:http://192.168.10.6:9090/metrics

Alert Manager 安装:

wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz
# 或者在本地下载,通过 scp 命令拷贝到远程 linux 服务端# 解压
tar -zxvf alertmanager-0.27.0.linux-amd64.tar.gzmkdir /opt/prometheus -p
mv alertmanager-0.27.0.linux-amd64 /opt/prometheus/alertmanager# 更改 alertmanager 文件夹权限
chown prometheus:prometheus -R /opt/prometheus/alertmanager# 创建 systemd 服务
cat > /etc/systemd/system/alertmanager.service << "EOF"[Unit]
Description=Alert Manager
Wants=network-online.target
After=network-online.target[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/opt/prometheus/alertmanager/alertmanager \--config.file=/opt/prometheus/alertmanager/alertmanager.yml \--storage.path=/opt/prometheus/alertmanager/data[Install]
WantedBy=multi-user.targetEOF

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

# 重启 Prometheus
systemctl daemon-reload
systemctl start alertmanager.service
# 设置 Prometheus 为开机自启
systemctl enable alertmanager.service
# 检查 Prometheus 服务的开启状态
systemctl status alertmanager.service# 查看 alertmanager 服务的日志,进行故障排除
journalctl -u alertmanager.service -f 

在这里插入图片描述
Alertmanager 的指标:http://192.168.10.6:9093/metrics

# 修改 prometheus 配置:/opt/prometheus/prometheus/prometheus.yml
alerting:alertmanagers:- static_configs:- targets:- localhost:9093 # 需根据实际情况填写 alertmanager 的地址rule_files:- "alert.yml"   # 需根据实际修改文件名# 增加触发器配置文件 /opt/prometheus/prometheus/alert.yml
cat > /opt/prometheus/prometheus/alert.yml << "EOF"
groups:
- name : Prometheus alertrules:# 对任何实例超过30s无法联系的情况,发送警报- alert: 服务警告expr: up == 0for: 30slabels:severity: criticalannotations:instance: "{{ $labels.instance }}"description: "{{ $labels.job }} 服务已关闭"
EOF
# 检查配置
cd /opt/prometheus/prometheus
./prometheus check config prometheus.yml

在这里插入图片描述
重启 prometheus 或 重新加载配置文件:

# 重启
systemctl restart prometheus# 重载,需要 --web.enable-lifecycle 配置
curl -x POST http://localhost:9090/-/reload

Grafana 安装:

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.4.3.linux-amd64.tar.gz
tar -zxvf grafana-enterprise-9.4.3.linux-amd64.tar.gzmv grafana-9.4.3 /opt/prometheus/grafanachown prometheus:prometheus -R /opt/prometheus/grafanacat > /etc/systemd/system/grafana-server.service << "EOF"
[Unit]
Description=Grafana Server
Documentation=http://docs.grafana.org[Service]
Type=simple
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/grafana/bin/grafana-server \--config=/opt/prometheus/grafana/conf/defaults.ini \--homepath=/opt/prometheus/grafana[Install]
WantedBy=multi-user.target
EOFsystemctl daemon-reload
systemctl start grafana-server
systemctl status grafana-server# 查看 alertmanager 服务的日志,进行故障排除
journalctl -u grafana-server.service -f

在这里插入图片描述
Grafana 的访问地址:http://192.168.10.6:3000

通过 gitee 下载安装:

使用 grafana 展示 prometheus 的图形

PromQL:

快速入门:


http://www.mrgr.cn/news/8678.html

相关文章:

  • 如何巧妙减小Uniapp打包后的小程序体积?
  • Spring中ImportBeanDefinitionRegistrar
  • 鸿蒙 next 实现摄像头视频预览编码(一)
  • Java笔试面试题之多线程常见考点总结
  • Ruby遇上GUI:探索Ruby桌面应用开发的新天地
  • 使用Java和XPath在XML文档中精准定位数据
  • ollma 本地部署大模型
  • 微信小程序vue3父组件调用vue2子组件传多个参数方法
  • .NET 开发的高性能内网穿透工具
  • 莫队算法C/C++实现
  • Simple RPC - 07 从零开始设计一个服务端(下)_RPC服务的实现
  • 下载的word中的mathtype公式双击无法打开编辑器
  • 【Java】/* 双向链表 - 底层实现 */
  • 热补丁简介
  • 力扣题/图论/课程表
  • 【ROS2】local_setup.bash和setup.bash的区别
  • gptk是什么意思?Mac电脑如何在crossover里安装gptk2.0测试版?借助GPTK玩《原神》《黑神话悟空》游戏
  • SQLserver在SQL Server Management Studio 20中的默认值和设置主键自增
  • C++ | Leetcode C++题解之第371题两整数之和
  • 5.1二叉树——基本概念梳理