springboot 07 Spring Boot Actuator: Production-ready features

Spring Boot Actuator: Production-ready features

当你的应用发布后,spring-boot包含很多的功能来帮你监控和管理应用;你可以选择通过http,JMX,或者一些远程的shell

1. Enabling production-ready features

spring-boot-actuator 提供了spring boot所有的监控管理功能。最简单的安装方式是添加依赖spring-boot-starter-actuator。


    
        org.springframework.boot
        spring-boot-starter-actuator
    

2. Endpoints

Actuator endpoints 允许你监控管理你的应用,Spring-boot已经内嵌了一系列的endpoints。使用什么方式来展示这些监控信息依赖于你选择的什么技术,大多数情况会选择HTTP monitoring,每一个endpoint有一个id,映射到url。eg: health endpoint will be mapped to /health.
下面将展示出提供的监控以及ID:

ID Description Sensitive Default
actuator 展示其他的endpoints. 需要Spring HATEOAS在classpath. true
autoconfig 显示自动配置报表,展示所有自动配置的条件以及原因 true
beans 显示出Spring 容器中所有的Bean信息 true
configprops 显示出所有的配置信息 true
dump 执行一次线程快照 true
env 的参数 true
flyway Shows any Flyway database migrations that have been applied. true
health 展示出应用当前的健康信息 false
info 当前应用的信息 false
liquibase Shows any Liquibase database migrations that have been applied. true
metrics 显示当前应用的JVM信息,内存情况,GC… true
mappings 列出当前应用的 true
shutdown 运行引用被优雅的shutdown true
trace 显示最近的请求信息,默认存储最近100条 HTTP requests true
如果你使用的是 Spring Mvc,还有一些额外的endpoints可以使用:

ID Description Sensitive Default
docs 需要 false
heapdump hprof true
jolokia Exposes JMX beans over HTTP (when Jolokia is on the classpath). true
logfile properties have been set). Supports the use of the HTTP true
Sensitive 的意思是说 是否敏感,在一些web security开启的情况下,Sensitive为true的endpoint需要输入username/password才能够查看

2.1 Customizing endpoints

endpoint能够被自定义,在application.properties中配置,eg:
endpoints.beans.id=springbeans #修改id
endpoints.beans.sensitive=false #是否敏感
endpoints.shutdown.enabled=true #是否开启

2.2 CORS support

endpoints.cors.allowed-origins=http://example.com
endpoints.cors.allowed-methods=GET,POST

2.3 Adding custom endpoints

http://docs.spring.io/spring-boot/docs/1.4.2.RELEASE/reference/htmlsingle/#production-ready-customizing-endpoints-programmatically

2.4 Securing sensitive endpoints

如果你项目中使用到了Spring-security,那么所有敏感的endpoint都将会保护起来,需要使用username and password才能够访问
security.user.name=admin
security.user.password=secret
management.security.roles=SUPERUSER

2.5 Customizing the management endpoint paths

有时候你需要分组管理endpoint,使用一个单独的path,eg:如果你项目中已经存在了一个/info,你可以使用management.context-path配置一个前缀
management.context-path=/manage
The application.properties example above will change the endpoint from /{id} to /manage/{id} (e.g./manage/info).
endpoints.{name}.id : 修改id
endpoints.{name}.path:修改path eg:endpoints.health.path=/ping/me => /ping/me

2.6 Customizing the management server port

management.port=8081 : 配置 Managerment server的端口
management.security.enabled=false : 不使用安全管理,即使项目中使用了spring-security,也不使用username ,password
management.address=127.0.0.1
management.port=-1 : disabling HTTP endpoints
The end

你可能感兴趣的:(springboot 07 Spring Boot Actuator: Production-ready features)