在以往的分布式开发当中,各个服务节点的监控必不可少。监控包含有很多方面,比如说:内存占用情况,节点是否健康等。在spring-boot会给我们提供相关资源监控叫做spring-boot-actuator, 通过执行器可以帮我管理和监控生产环境下的应用服务。
一。添加SpringBoot执行器的依赖
添加gradle配置依赖:
dependencies { compile(‘org.springframework.boot:spring-boot-starter-actuator‘) }
二。关于SpringBoot的端点
端点:可用于监控应用与应用进行交互,springboot包含很多内置内置端点。tips:参考官网的
ID | Description | Sensitive Default |
---|---|---|
actuator
|
Provides a hypermedia-based “discovery page” for the other endpoints. Requires Spring HATEOAS to be on the classpath. |
true |
auditevents
|
Exposes audit events information for the current application. |
true |
autoconfig
|
Displays an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied. |
true |
beans
|
Displays a complete list of all the Spring beans in your application. |
true |
configprops
|
Displays a collated list of all @ConfigurationProperties .
|
true |
dump
|
Performs a thread dump. |
true |
env
|
Exposes properties from Spring’s ConfigurableEnvironment .
|
true |
flyway
|
Shows any Flyway database migrations that have been applied. |
true |
health
|
Shows application health information (when the application is secure, a simple ‘status’ when accessed over an unauthenticated connection or full message details when authenticated). |
false |
info
|
Displays arbitrary application info. |
false |
loggers
|
Shows and modifies the configuration of loggers in the application. |
true |
liquibase
|
Shows any Liquibase database migrations that have been applied. |
true |
metrics
|
Shows ‘metrics’ information for the current application. |
true |
mappings
|
Displays a collated list of all @RequestMapping paths.
|
true |
shutdown
|
Allows the application to be gracefully shutdown (not enabled by default). |
true |
trace
|
Displays trace information (by default the last 100 HTTP requests). |
true |
如果使用spring-mvc时,我们可以访问以下节点:
ID | Description | Sensitive Default |
---|---|---|
docs
|
Displays documentation, including example requests and responses, for the Actuator’s endpoints. Requires spring-boot-actuator-docs to be on the classpath.
|
false |
heapdump
|
Returns a GZip compressed hprof heap dump file.
|
true |
jolokia
|
Exposes JMX beans over HTTP (when Jolokia is on the classpath). |
true |
logfile
|
Returns the contents of the logfile (if logging.file or logging.path properties have been set). Supports the use of the HTTP Range header to retrieve part of the log file’s content.
|
true |
有几点要补充说明一下:
1).如果需要访问health端点,那么请在映射中访问http://xxxxx:xxxx/health
.
2) 并不是所有端点都可以访问,在上述表格中如果Sensitive(是否敏感)的值如果为true,则访问会报401错误,不过好在在spring-boot配置文件中可以设置相关端点的敏感值,比如说:endpoints.env.sensitive=false
3) 关于保护敏感端点,首先我们要添加对spring-security的依赖,并设置进行安全验证的用户名,密码以及角色,如果不使用spring-security就要慎重考虑暴露端口的端点了
security.user.name=xxxx security.user.password=xxxx management.security.role=xxxx
时间: 2024-09-29 01:09:48