prometheus搭建服务监控

ops/2025/3/6 14:38:17/

Prometheus Server安装

创建目录
mkdir /apps解压安装包
tar xvf prometheus-2.55.0.linux-amd64.tar.gz创建软链接
ln -sv /apps/prometheus-2.55.0.linux-amd64 /apps/prometheus
‘/apps/prometheus’ -> ‘/apps/prometheus-2.55.0.linux-amd64’cd /apps/prometheus
检测prometheus配置
./promtool check config prometheus.yml创建启动脚本
vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target[Service]
Restart=on-failure
WorkingDirectory=/apps/prometheus/
ExecStart=/apps/prometheus/prometheus   
config.file=/apps/prometheus/prometheus.yml[Install]
WantedBy=multi-user.target启动服务
systemctl daemon-reload && systemctl  restart prometheus

验证服务是否启动成功访问地址:http://localhost:9090/targets

rabbitmq-exporter安装(高版本不需要安装收集,已经暴露)

高版本注意:检查rabbitmq 是否开启对prometheus支持(http://localhost:15692/metrics)

配置收集节点数据:

vim /apps/prometheus/prometheus.yml修改参数- job_name: 'promethues-node'static_configs:- targets: ['172.31.7.111:9100']

Grafana添加Prometheus数据源
在这里插入图片描述
导入Grafana展示rabbitmq的模板
在这里插入图片描述

rabbitmq告警规则配置

设置告警规则:
- 'rules/*.yml'新建目录
mkdir rules目录新生成rabbitmq_rules.yml检查rules语法
/apps/prometheus/promtool check rules /apps/prometheus/rules/rabbitmq_rules.yml重新加载Prometheus (需支持热加载)
curl -X POST http://localhost:9090/-/reload

目前告警规则:

  • 队列已就绪的消息不超过500
  • RabbitMQ⽂件描述符使用率过高 60%
  • RabbitMQ实例的磁盘空间 未来10天内磁盘的可用空间可能低于默认配置的50MB
  • TCP套接字使用率高于60%
groups:- name: rabbitmq告警规则rules:- alert: RabbitMQ队列已就绪的消息过多expr: avg_over_time(rabbitmq_queue_messages_ready[5m]) > 500for: 5mlabels:severity: warningannotations:summary: '{{ $labels.instance }} RabbitMQ实例的队列消息准备过多'description: '{{ $labels.instance }}实例中平均准备好待消费的消息数量超过500,当前平均值为{{ $value }}。'- alert: RabbitMQ队列中已消费但未确认的消息过多expr: avg_over_time(rabbitmq_queue_messages_unacked[5m]) > 500for: 5mlabels:severity: warningannotations:summary: '{{ $labels.instance }} RabbitMQ实例的队列消息确认存在延迟'description: '{{ $labels.instance }} 实例中平均已被消费但未被确认的消息数量超过500,当前平均值为{{ $value }}。'- alert: RabbitMQ磁盘空间预测不足expr: predict_linear(rabbitmq_disk_space_available_bytes[24h], 60*60*24*10) < rabbitmq_disk_space_available_limit_bytesfor: 1hlabels:severity: criticalannotations:summary: '{{ $labels.instance }} RabbitMQ实例的磁盘空间预测不足。'description: '基于过去24小时磁盘可用空间数据预测,未来10天内磁盘的可用空间可能低于默认配置的50MB。'- alert: RabbitMQ⽂件描述符使用率过高expr: max_over_time(rabbitmq_process_open_fds[5m]) / rabbitmq_process_max_fds * 100 > 60for: 5mlabels:severity: warningannotations:summary: '{{ $labels.instance }} RabbitMQ实例的文件描述符使用率过高'description: '{{ $labels.instance }} 实例打开的文件描述符数量最大值,占文件描述限制的比率超过60%,当前比率为{{ $value }}%。'- alert: RabbitMQ TCP套接字使用率过高expr: max_over_time(rabbitmq_process_open_tcp_sockets[5m]) / rabbitmq_process_max_tcp_sockets * 100 > 60for: 5mlabels:severity: warningannotations:summary: '{{ $labels.instance }} RabbitMQ实例的TCP套接字使用率过高'description: '{{ $labels.instance }} 实例打开的TCP套接字数量最大值,占操作系统允许的TCP连接数限制的比率超过60%,当前比率为{{ $value }}%。'

在这里插入图片描述

Alertmanager安装配置

解压安装包
tar xvf alertmanager-0.27.0.linux-amd64.tar.gz创建软链接
ln -sv /apps/alertmanager-0.27.0.linux-amd64 /apps/alertmanager
'/apps/alertmanager' -> '/apps/alertmanager-0.27.0.linux-amd64'创建启动脚本
vim /etc/systemd/system/alertmanager.service[Unit] 
Description=Prometheus alertmanager 
After=network.target 
[Service]
Restart=on-failure
WorkingDirectory=/apps/alertmanager/
ExecStart=/apps/alertmanager/alertmanager 
config.file=/apps/alertmanager/alertmanager.yml 
[Install]
WantedBy=multi-user.target设置启动服务
systemctl daemon-reload && systemctl restart alertmanager && systemctl enable alertmanager启动服务
systemctl restart alertmanager验证链接:http://localhost:9093/#/status

Prometheus配置Alertmanager

配置alertmanageralerting:alertmanagers:- static_configs:- targets:- 192.168.15.70:9093

安装PrometheusAlert

解压文件   tar xvf
unzip prometheus-alert-linux.zip重命名文件
mv linux prometheusalert修改配置文件(账号,密码,端口,设置飞书通知)
vim /apps/prometheusalert/conf/app.conf创建启动脚本
vim /etc/systemd/system/prometheusalert.service[Unit] 
Description=Prometheus alert 
After=network.target 
[Service]
Restart=on-failure
WorkingDirectory=/apps/prometheusalert/
ExecStart=/apps/prometheusalert/PrometheusAlert --config.file=/apps/prometheusalert/conf/app.conf 
[Install]
WantedBy=multi-user.target启动服务
systemctl daemon-reload && systemctl restart prometheusalert问题点:应用程序权限不足(加权)
cd /apps/prometheusalertchmod +x PrometheusAlert 

配置告警通道

open-feishu=1
#默认飞书机器人地址
#fsurl=https://open.feishu.cn/open-apis/bot/hook/xxxxxxxxx
fsurl=https://open.feishu.cn/open-apis/bot/v2/hook/839fd0b3-51de-49df-9db0-a014c95c179d
# webhook 发送 http 请求的 contentType, 如 application/json, application/x-www-form-urlencoded,不配置默认 application/json
wh_contenttype=application/json

Alertmanager配置PrometheusAlert

receivers:- name: 'web.hook'webhook_configs:- url: 'http://127.0.0.1:8088/prometheusalert?type=fs&tpl=prometheus-fs&fsurl=https://open.feishu.cn/open-apis/bot/v2/hook/839fd0b3-51de-49df-9db0-a014c95c179d'

资源下载链接:
PrometheusAlert安装包
alertmanager安装包
grafana中rabbitmq模板
prometheus安装包


http://www.ppmy.cn/ops/163618.html

相关文章

开放鸿蒙OpenHarmony 5.0.0 Release 兼容性测试实战经验分享

OpenHarmony 5.0版本的发布时间是2024年12月20日至21日。这个版本带来了许多新特性和改进。现在5.0出了两个release 版本&#xff0c;分别是5.0.0和5.0.1。 就在5.0版本发布不到2周的时间内&#xff0c;2025年01月01日起&#xff0c;不支持新产品基于老分支&#xff08;OpenHar…

重塑用户体验:用户界面设计、交互设计及视觉体验优化的融合策略

在数字化时代&#xff0c;用户体验&#xff08;UX&#xff09;已成为衡量产品成功与否的关键指标之一。一个优秀的产品不仅需要在功能上满足用户需求&#xff0c;更需在用户界面设计&#xff08;UI&#xff09;、交互设计&#xff08;IXD&#xff09;以及视觉体验上达到高度的和…

PyCharm环境配置实战:从搭建到优化的完整指南

PyCharm作为Python开发的旗舰IDE,其环境配置的合理性直接影响开发效率。本文将结合2025年最新实践,详解环境搭建、虚拟环境管理、性能优化等全流程技巧,助你打造高效开发环境。 © ivwdcwso (ID: u012172506) 一、环境搭建基础篇 1. Python解释器安装 版本选择:推荐P…

【Python爬虫】爬取公共交通路网数据

程序来自于Github&#xff0c;以下这篇博客作为完整的学习记录&#xff0c;也callback上一篇爬取公共交通站点的博文。 Bardbo/get_bus_lines_and_stations_data_from_gaode: 这个项目是基于高德开放平台和公交网获取公交线路及站点数据&#xff0c;并生成shp文件&#xff0c;…

揭开Android View的神秘面纱:深入探索工作原理

引言&#xff1a;View 在 Android 世界的角色 在 Android 开发的广袤天地中&#xff0c;View 无疑是构建用户界面的基石&#xff0c;发挥着举足轻重的作用。从简单的文本显示、按钮点击&#xff0c;到复杂的动画效果、交互设计&#xff0c;View 无处不在&#xff0c;是连接用户…

中间件专栏之Redis篇——Redis中过期key删除和内存淘汰策略

在Redis中&#xff0c;过期键的删除和内存淘汰策略是管理Redis内存的重要机制&#xff0c;确保Redis可以高效地使用内存&#xff0c;并避免由于内存不足导致的性能问题。以下是这两个概念的详细介绍&#xff1a; 一、过期键删除机制 Redis支持对存储的键设置过期时间&#xf…

C#实现语音合成播报器——基于System.Speech的语音交互方案,在windows上实现语音播报指定文本

——基于System.Speech的语音交互方案&#xff0c;在windows上实现语音播报指定文本 一、语音合成播报应用场景 语音合成播报器广泛应用于以下领域&#xff1a; 工业控制&#xff1a;生产线异常报警、设备状态实时播报&#xff08;如网页4中的WinCC语音报警插件&#xff09;…

Linux的缓存I/O和无缓存IO

一、I/O缓存的背景 I/O缓存是指在内存里开辟一块区域&#xff0c;存放用来接收用户输入和用于计算机输出的数据&#xff0c;以减小系统开销和提高外设效率。linux对IO文件的操作分为不带缓存的IO操作和带缓存的IO操作&#xff08;标准IO操作&#xff09;。为什么存在C标准I/O库…