Actuator 端点
Spring Boot Actuator 提供监控和管理端点。
基础路径: /actuator
认证: ❌ 已配置为公开访问(生产环境建议限制)
常用端点
| 端点 | 方法 | 功能 |
|---|---|---|
/actuator/health | GET | 健康检查 |
/actuator/info | GET | 应用信息 |
/actuator/metrics | GET | 指标列表 |
/actuator/metrics/{name} | GET | 特定指标 |
/actuator/prometheus | GET | Prometheus 格式 |
/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.used | JVM 内存使用 |
jvm.threads.live | 活跃线程数 |
http.server.requests | HTTP 请求统计 |
jdbc.connections.active | 数据库连接数 |
system.cpu.usage | CPU 使用率 |
动态日志级别
# 开启 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