监控SpringBoot项目的情况
- http默认只公开了 health 和 info
- exclude 优先级大于 include
- 公开系统注意保护自己的端点
- 定义一个
EndpointFilter来实现实现自己的策略 - 如果引用了
Spring Security,则默认是使用Spring Security的安全策略 - 跨域设置
- 自定义路径
management.endpoints.web.base-path=/manage
- 自定义端口
management.server.port=9001
- 调整默认映射路径
management.endpoints.web.path-mapping.health=healthcheck
- 限制访问地址
management.server.address=127.0.0.1
- 禁用HTTP端点
management.server.port=-1
# 或者
management.endpoints.web.exposure.exclude=*
显示SpringBoot配置和自动装配类上的条件,以及满足或者不满足条件的原因
http://localhost:8080/actuator/conditions
- positiveMatches 满足条件的类或者方法
- negativeMatches 未满足条件的类或者方法
- unconditionalClasses 无需条件判断的自动配置类的名称
提供@ConfigurationProperties注解的Bean信息
http://localhost:8080/actuator/configprops
- prefix 配置前缀
- properties 参数的键值对
env端点提供应用程序相关环境的信息
http://localhost:8080/actuator/env
提供有关应用程序运行状况的详细信息
http://localhost:8080/actuator/health
| 参数 | 描述 |
|---|---|
| status | 应用的总体状态 |
| components | 构成应用健康信息的所有组件 |
| components.*.status | 特定组件的状态 |
| components.*.components | 构成特定组件健康信息的内嵌组件列表 |
| components.*.details | 特定组件的详细状态 |
通过management.endpoint.health.show-details设置是否显示详情,默认不显示:
- never 不显示,默认
- when_authorized 通过授权的用户显示
- always 一直显示
可以查询指定的组件的健康信息,如查看数据库信息
http://localhost:8080/actuator/health/db
提供来自应用程序JVM的堆转储信息
http://localhost:8080/actuator/heapdump
返回的是HPROF格式的二进制数据,并且可能很大。通常将数据保存到磁盘后再分析
显示HTTP跟踪信息(默认情况下,最近100个HTTP请求-响应交换)
http://localhost:8080/actuator/httptrace
提供应用程序的基本信息。Spring boot 提供了build 和git部分
http://localhost:8080/actuator/info
对日志文件内容的访问
当使用第三方日志,如logback或者log4j2的时候不可用
http://localhost:8080/actuator/logfile
通过在header中使用Range来查询部分内容,例如只查询日志文件的前1024字节:
Range: bytes=0-1023
访问日志信息和设置日志级别
http://localhost:8080/actuator/loggers
- configuredLevel 日志配置级别
- effectiveLevel 日志的有效级别
- groups 组信息
# 格式: /actuator/loggers/{logger.name}
http://localhost:8080/actuator/loggers/ROOT
# 格式: /actuator/loggers/{group.name}
http://localhost:8080/actuator/loggers/web
通过POST请求传递一个JSON格式去设置。
- 设置指定日志的级别:
# 格式: /actuator/loggers/{logger.name}
http://localhost:8080/actuator/loggers/ROOT
{
"configuredLevel": "DEBUG"
}
- 设置指定组的日志级别:
# 格式: /actuator/loggers/{group.name}
http://localhost:8080/actuator/loggers/web
{
"configuredLevel": "DEBUG"
}
映射信息
http://localhost:8080/actuator/mappings
指标信息
http://localhost:8080/actuator/metrics
定时任务信息
http://localhost:8080/actuator/scheduledtasks
关闭系统,发送POST请求
http://localhost:8080/actuator/shutdown
查看JVM中的线程信息
