Prometheus Automated Inspection
这是一个基于 Prometheus 的监控报告自动生成工具,可以自动收集、分析指标数据并生成可视化的 HTML 报告。该工具旨在简化监控数据的收集和展示过程,帮助运维人员快速了解系统状态。
http://localhost:8091/api/promai/getreport
http://localhost:8091/api/promai/status
- 支持多种指标类型的监控(基础资源、Kubernetes、应用服务等)
- 自动计算指标状态和告警级别(正常、警告、严重)
- 生成包含数据表格和图表的 HTML 报告
- 支持自定义指标阈值和标签别名
- 灵活的配置文件系统
- 支持多维度数据分析和展示
- 自动计算关键统计指标(最大值、最小值、平均值等)
- 美观的可视化界面,支持响应式布局
- 新增:支持多数据源配置,可通过datasource参数动态切换Prometheus集群
- Go 1.22 或更高版本
- 可访问的 Prometheus 服务器
- 现代浏览器(支持 HTML5 和 JavaScript)
- 至少 512MB 可用内存
- 50MB 可用磁盘空间
配置文件采用 YAML 格式,主要包含以下几个部分:
在 config/config.yaml 中配置 Prometheus 服务器地址和监控指标。
prometheus_url: "http://prometheus.k8s.kubehan.cn"
metric_types:
- type: "基础资源使用情况"
metrics:
- name: "CPU使用率"
description: "节点CPU使用率统计"
query: "100 - (avg by(instance) (irate(node_cpu_seconds_total{mode='idle'}[5m])) * 100)"
trend_query: "100 - (avg by(instance) (irate(node_cpu_seconds_total{mode='idle'}[5m])) * 100)[6h:5m]"
threshold: 80
unit: "%"
labels:
instance: "节点"
# 其他指标...每个指标可以配置以下内容:
-
name: 指标名称 -
description: 指标描述 -
query: 用于表格显示的即时查询 -
trend_query: 用于图表显示的趋势查询 -
threshold: 指标阈值 -
unit: 指标单位 -
labels: 标签别名 -
threshold_type: 阈值比较方式: "greater", "greater_equal", "less", "less_equal", "equal", "not_equal"greater: 当值大于阈值时告警 (例如:CPU使用率 > 80% 告警)greater_equal: 当值大于等于阈值时告警 (例如:CPU使用率 >= 80% 告警)less: 当值小于阈值时告警 (例如:可用节点数 < 3 告警)less_equal: 当值小于等于阈值时告警 (例如:可用节点数 <= 3 告警)equal: 值必须等于阈值才正常 (例如:版本号必须匹配)not_equal: 值不等于阈值才正常 (例如:版本号不匹配时告警) -
threshold_status: 阈值状态: "normal", "critical" 根据阈值类型不同,告警状态也不同
-
克隆仓库:
git clone https://github.com/kubehan/PromAI.git cd PromAI -
安装依赖:
go mod download
-
修改配置文件:
cp config/config.yaml config/config.yaml # 编辑 config.yaml 设置 Prometheus 服务器地址和监控指标 -
构建并运行:
go build -o PromAI main.go ./PromAI -config config/config.yaml
-
查看报告: 生成的报告将保存在
reports目录下。
docker run -d --name PromAI -p 8091:8091 kubehan/promai:latestkubectl create namespace promai
kubectl create configmap config --from-file=config/config.yaml -n promai
kubectl apply -f deploy/deployment.yaml在配置文件中添加所需的监控指标后,运行程序将生成 HTML 报告。报告中将包含各个指标的当前状态、历史趋势图表以及详细的表格数据。
- 修改配置文件中的Prometheus地址为自己的地址
- 修改配置文件中的指标
- 运行程序 默认运行在8091端口,通过访问http://localhost:8091/getreport 查看报告
go build -o PromAI main.go
./PromAI -config config/config.yaml -port :8091支持通过URL参数 datasource动态切换不同的Prometheus集群:
- 在配置文件中配置多个数据源:
data_sources:
- name: "cluster1"
url: "http://prometheus.cluster1.example.com"
- name: "cluster2"
url: "http://prometheus.cluster2.example.com"
- name: "test-cluster"
url: "http://prometheus.test.example.com"- 使用datasource参数访问特定集群的报告:
# 获取cluster1的报告
http://localhost:8091/api/promai/getreport?datasource=cluster1
# 获取cluster2的报告
http://localhost:8091/api/promai/getreport?datasource=cluster2
# 查看cluster1的状态页面
http://localhost:8091/api/promai/status?datasource=cluster1
# 不带datasource参数时使用默认的prometheus_url
http://localhost:8091/api/promai/getreport
#自定义数据源
http://localhost:8091/api/promai/getreport?datasource=http://prometheus.test.example.com✅ 已实现的核心功能
- ✅ 多数据源支持
- ✅ 自定义仪表板
- ✅ 智能告警(警告、严重两级告警)
- ✅ API 接口 (/getreport, /status, /health)
- ✅ 用户角色和权限管理
- ✅ 数据导出功能(HTML报告)
- ✅ 响应式设计(移动端支持)
- ✅ 实时状态监控看板
- ✅ 灵活的阈值配置系统
- ✅ 完整的指标统计分析
支持多种阈值比较方式,适应不同监控场景需求:
- 数值范围监控(CPU、内存使用率)
- 计数监控(可用节点数、连接数)
- 精确匹配监控(版本号、状态检查)
自动生成包含统计信息、趋势图表和详细数据的HTML报告:
- 概览统计卡片
- 资源使用情况图表
- 按状态筛选的数据表格
- 响应式设计,支持各种设备
提供服务健康状态看板,实时显示:
- 各类别巡检结果统计
- 异常指标详情
- 总体健康度评估
支持YAML配置文件,可自定义:
- Prometheus数据源
- 监控指标类型
- 阈值和告警规则
- 标签别名显示
欢迎任何形式的贡献!请提交问题、建议或拉取请求。
|
Kubehan |
Junlintianxiazhifulinzhongguo |
KingsBa |
Shiju Liu |
Wilson_wu |
了凡 |
微信扫码添加我为好友,备注“PromAI”,即可加入PromAI交流群。 微信号:Kubehan
该项目采用 MIT 许可证,详细信息请查看 LICENSE 文件。