在以往的分布式开发当中,各个服务节点的监控必不可少。监控包含有很多方面,比如说:内存占用情况,节点是否健康等。在spring-boot会给我们提供相关资源监控叫做spring-boot-actuator, 通过执行器可以帮我管理和监控生产环境下的应用服务。
一。添加SpringBoot执行器的依赖
添加gradle配置依赖:
dependencies { compile(‘org.springframework.boot:spring-boot-starter-actuator‘) }
二。关于SpringBoot的端点
端点:可用于监控应用与应用进行交互,springboot包含很多内置内置端点。tips:参考官网的
ID | Description | Sensitive Default |
---|---|---|
|
Provides a hypermedia-based “discovery page” for the other endpoints. Requires Spring HATEOAS to be on the classpath. |
true |
|
Exposes audit events information for the current application. |
true |
|
Displays an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied. |
true |
|
Displays a complete list of all the Spring beans in your application. |
true |
|
Displays a collated list of all |
true |
|
Performs a thread dump. |
true |
|
Exposes properties from Spring’s |
true |
|
Shows any Flyway database migrations that have been applied. |
true |
|
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 |
|
Displays arbitrary application info. |
false |
|
Shows and modifies the configuration of loggers in the application. |
true |
|
Shows any Liquibase database migrations that have been applied. |
true |
|
Shows ‘metrics’ information for the current application. |
true |
|
Displays a collated list of all |
true |
|
Allows the application to be gracefully shutdown (not enabled by default). |
true |
|
Displays trace information (by default the last 100 HTTP requests). |
true |
如果使用spring-mvc时,我们可以访问以下节点:
ID | Description | Sensitive Default |
---|---|---|
|
Displays documentation, including example requests and responses, for the Actuator’s endpoints. Requires |
false |
|
Returns a GZip compressed |
true |
|
Exposes JMX beans over HTTP (when Jolokia is on the classpath). |
true |
|
Returns the contents of the logfile (if |
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