跳到主要内容

Actuator 端点

Spring Boot Actuator 提供监控和管理端点。

基础路径: /actuator
认证: ❌ 已配置为公开访问(生产环境建议限制)


常用端点

端点方法功能
/actuator/healthGET健康检查
/actuator/infoGET应用信息
/actuator/metricsGET指标列表
/actuator/metrics/{name}GET特定指标
/actuator/prometheusGETPrometheus 格式
/actuator/loggers/{name}POST修改日志级别

健康检查

curl http://localhost:8080/actuator/health
{
"status": "UP",
"components": {
"db": {"status": "UP"},
"redis": {"status": "UP"},
"diskSpace": {"status": "UP"}
}
}

状态码: UP | DOWN | OUT_OF_SERVICE


应用信息

curl http://localhost:8080/actuator/info

返回应用名称、版本、Git 信息等。


指标查询

# 查看所有指标
curl http://localhost:8080/actuator/metrics

# 查看 JVM 内存
curl http://localhost:8080/actuator/metrics/jvm.memory.used

# 按标签过滤
curl http://localhost:8080/actuator/metrics/jvm.memory.used?tag=area:heap

常用指标

指标描述
jvm.memory.usedJVM 内存使用
jvm.threads.live活跃线程数
http.server.requestsHTTP 请求统计
jdbc.connections.active数据库连接数
system.cpu.usageCPU 使用率

动态日志级别

# 开启 DEBUG 日志
curl -X POST http://localhost:8080/actuator/loggers/com.blog \
-H "Content-Type: application/json" \
-d '{"configuredLevel":"DEBUG"}'

无需重启应用,适合线上问题排查。


Prometheus 集成

curl http://localhost:8080/actuator/prometheus

返回 Prometheus Text Format,可配置采集:

scrape_configs:
- job_name: 'blog-app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:8080']

Kubernetes 探针

livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 8080
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 8080

Spring Boot Admin

可视化监控界面:http://localhost:9000

👉 Spring Boot Admin 文档