feat: 接入 Prometheus 监控(放行 /actuator/prometheus + 指标暴露 + compose 编排)
This commit is contained in:
1 parent
42dd68f266
commit
32710c2e06
5 files changed
+70
-2
No files matched your search
@@ -145,7 +145,34 @@ services:
|
|||||||
start_period: 40s
|
start_period: 40s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|
||||||
|
# ─────────── 监控 ───────────
|
||||||
|
prometheus:
|
||||||
|
image: prom/prometheus:latest
|
||||||
|
container_name: fruitshorts-prometheus
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "9090:9090"
|
||||||
|
volumes:
|
||||||
|
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||||
|
- prometheus-data:/prometheus
|
||||||
|
command:
|
||||||
|
- "--config.file=/etc/prometheus/prometheus.yml"
|
||||||
|
|
||||||
|
grafana:
|
||||||
|
image: grafana/grafana:latest
|
||||||
|
container_name: fruitshorts-grafana
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
volumes:
|
||||||
|
- grafana-data:/var/lib/grafana
|
||||||
|
environment:
|
||||||
|
- GF_SECURITY_ADMIN_USER=admin
|
||||||
|
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
# 命名卷:跟着 compose 项目走,`docker compose down -v` 才会删
|
# 命名卷:跟着 compose 项目走,`docker compose down -v` 才会删
|
||||||
db-data:
|
db-data:
|
||||||
redis-data:
|
redis-data:
|
||||||
|
prometheus-data:
|
||||||
|
grafana-data:
|
||||||
@@ -66,3 +66,15 @@ springdoc:
|
|||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.fruitshorts: debug
|
com.fruitshorts: debug
|
||||||
|
|
||||||
|
management:
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: prometheus,health
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
show-details: always
|
||||||
|
metrics:
|
||||||
|
tags:
|
||||||
|
application: ${spring.application.name}
|
||||||
@@ -97,3 +97,15 @@ fruitshorts:
|
|||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.fruitshorts: info
|
com.fruitshorts: info
|
||||||
|
|
||||||
|
management:
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: prometheus,health
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
show-details: always
|
||||||
|
metrics:
|
||||||
|
tags:
|
||||||
|
application: ${spring.application.name}
|
||||||
+3
-2
@@ -53,9 +53,10 @@ public class SecurityConfig {
|
|||||||
"/swagger-ui/**",
|
"/swagger-ui/**",
|
||||||
"/swagger-ui.html",
|
"/swagger-ui.html",
|
||||||
"/v3/api-docs/**",
|
"/v3/api-docs/**",
|
||||||
/* 健康检查:给容器编排与冒烟脚本用(本项目没引 actuator,见 HealthController 注释) */
|
/* 健康检查与监控:/actuator/health 给容器编排,/actuator/prometheus 给 Prometheus 抓取指标 */
|
||||||
"/healthz",
|
"/healthz",
|
||||||
"/actuator/health"
|
"/actuator/health",
|
||||||
|
"/actuator/prometheus"
|
||||||
};
|
};
|
||||||
|
|
||||||
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# Author: fruit.com.cn
|
||||||
|
# Prometheus 抓取配置:抓取后端双服务的 actuator 指标(服务名走 compose 网络)
|
||||||
|
global:
|
||||||
|
scrape_interval: 15s
|
||||||
|
evaluation_interval: 15s
|
||||||
|
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: "fruitshorts-app-api"
|
||||||
|
metrics_path: "/actuator/prometheus"
|
||||||
|
static_configs:
|
||||||
|
- targets: ["app-api:8081"]
|
||||||
|
|
||||||
|
- job_name: "fruitshorts-admin-api"
|
||||||
|
metrics_path: "/actuator/prometheus"
|
||||||
|
static_configs:
|
||||||
|
- targets: ["admin-api:8080"]
|
||||||
Reference in new issue
Block a user