fundplatform/docker/prometheus/prometheus.yml
zhangjf 5b80e237b9 feat: Docker容器化部署和Prometheus+Grafana监控
## Docker 容器化部署

### 新增文件
- Dockerfile: 多阶段构建镜像,支持 Java 21
- docker-compose.yml: 完整服务编排配置
  - 基础设施: MySQL 8.0, Redis 7, Nacos 3.0
  - 监控: Prometheus, Grafana
  - 业务服务: Gateway + 9个微服务
- docker/.env: 环境变量配置
- docker/mysql/init/01-init.sql: 数据库初始化脚本

### Docker 特性
- 多阶段构建优化镜像大小
- 非 root 用户运行服务
- 健康检查配置
- 统一时区设置 (Asia/Shanghai)

## Prometheus + Grafana 监控

### Prometheus 配置
- docker/prometheus/prometheus.yml: 服务发现配置
- docker/prometheus/rules/alerts.yml: 告警规则
  - 服务可用性告警
  - JVM 内存告警
  - HTTP 请求告警
  - 数据库连接池告警
  - 系统资源告警

### Grafana 配置
- docker/grafana/provisioning/: 数据源和Dashboard自动导入
- docker/grafana/dashboards/fund-platform-dashboard.json
  - 服务概览面板
  - JVM 内存监控
  - 数据库连接池监控

### Spring Boot Actuator 集成
- pom.xml: 添加 spring-boot-starter-actuator 和 micrometer-registry-prometheus
- application-docker.yml: Prometheus 端点配置

## 服务端口规划
- Gateway: 8000
- fund-sys: 8100
- fund-cust: 8200
- fund-proj: 8300
- fund-req: 8400
- fund-exp: 8500
- fund-receipt: 8600
- fund-report: 8700
- fund-file: 8800
- Prometheus: 9090
- Grafana: 3000
- Nacos: 8848
2026-02-19 18:48:15 +08:00

160 lines
4.0 KiB
YAML

# Prometheus 配置文件
# 资金服务平台监控配置
global:
scrape_interval: 15s # 抓取间隔
evaluation_interval: 15s # 规则评估间隔
external_labels:
monitor: 'fund-platform'
# 告警管理器配置(可选)
# alerting:
# alertmanagers:
# - static_configs:
# - targets:
# - alertmanager:9093
# 规则文件
rule_files:
- /etc/prometheus/rules/*.yml
# 抓取配置
scrape_configs:
# ==================== 基础设施监控 ====================
# Prometheus 自身监控
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
labels:
instance: 'prometheus'
# MySQL 监控 (需要 mysqld_exporter)
# - job_name: 'mysql'
# static_configs:
# - targets: ['mysql-exporter:9104']
# Redis 监控 (需要 redis_exporter)
# - job_name: 'redis'
# static_configs:
# - targets: ['redis-exporter:9121']
# ==================== Spring Boot 微服务监控 ====================
# API 网关
- job_name: 'fund-gateway'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['gateway:8000']
labels:
application: 'fund-gateway'
service: 'gateway'
relabel_configs:
- source_labels: [__address__]
target_label: instance
replacement: 'fund-gateway'
# 系统服务
- job_name: 'fund-sys'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['fund-sys:8100']
labels:
application: 'fund-sys'
service: 'business'
relabel_configs:
- source_labels: [__address__]
target_label: instance
replacement: 'fund-sys'
# 客户服务
- job_name: 'fund-cust'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['fund-cust:8200']
labels:
application: 'fund-cust'
service: 'business'
relabel_configs:
- source_labels: [__address__]
target_label: instance
replacement: 'fund-cust'
# 项目服务
- job_name: 'fund-proj'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['fund-proj:8300']
labels:
application: 'fund-proj'
service: 'business'
relabel_configs:
- source_labels: [__address__]
target_label: instance
replacement: 'fund-proj'
# 需求工单服务
- job_name: 'fund-req'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['fund-req:8400']
labels:
application: 'fund-req'
service: 'business'
relabel_configs:
- source_labels: [__address__]
target_label: instance
replacement: 'fund-req'
# 支出服务
- job_name: 'fund-exp'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['fund-exp:8500']
labels:
application: 'fund-exp'
service: 'business'
relabel_configs:
- source_labels: [__address__]
target_label: instance
replacement: 'fund-exp'
# 收款服务
- job_name: 'fund-receipt'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['fund-receipt:8600']
labels:
application: 'fund-receipt'
service: 'business'
relabel_configs:
- source_labels: [__address__]
target_label: instance
replacement: 'fund-receipt'
# 报表服务
- job_name: 'fund-report'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['fund-report:8700']
labels:
application: 'fund-report'
service: 'business'
relabel_configs:
- source_labels: [__address__]
target_label: instance
replacement: 'fund-report'
# 文件服务
- job_name: 'fund-file'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['fund-file:8800']
labels:
application: 'fund-file'
service: 'business'
relabel_configs:
- source_labels: [__address__]
target_label: instance
replacement: 'fund-file'