Spring Boot Actuator提供了一组http接口,用于在应用运行时,监控和管理应用的运行情况。
Spring boot Actuator内置EndPoints
Spring boot Actuator提供了一组基于HTTP和JMX内置的EndPoints用于在系统运行时监控系统的运行情况。详情可以参见Spring boot官网在此列举一些常用的内置EndPoints:
- beans:显示当前系统的Spring容器中的所有beans,包括容器运行所需的bean和用户自己定义的bean。并展示bean的类型,例如:singleton
- env 显示系统的所有环境配置,包括application.properties(yml)中的相关配置以及用户自己定义的环境配置。对于应用于配置分离的项目,通过该条可以十分便捷的确定当前系统运行时使用的生效的环境变量以及其值。敏感数据例如password会被Spring Boot Actuator直接隐私化处理:
- httptrace,展示最近100条当前运行系统的http访问踪迹日志信息(spring boot 2.x是httptrace,1.5.x是trace)
- mappings,显示当前web应用所有http接口信息
Spring boot Actuator集成
1.在Spring boot项目中导入依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2.开启Spring boot Actuator
在application.properties中进行配置
a.Spring boot 2.x
management.endpoints.web.exposure.include=*(*指暴露所有内置EndPoints,也可使用“httptrace,env ”暴露指定EndPoints)
b.Spring boot 1.5.x
management.security.enabled=true
3.关闭Spring boot Actuator
a.Spring boot 2.x
//method 1:
management.endpoints.web.exposure.exclude=*
//method 2:
management.server.port=-1
b.Spring boot 1.5.x
management.security.enabled=false
4.设置Actuator的http访问前缀和端口
开启Spring boot Actuator后,Spring boot 2.x默认使用/acutuator前缀+/{id}的方式
ep:http://ip:port/应用servletPath/acutuator/{EndPoint id}
Spring boot直接使用/{id}的方式
ep:http://ip:port/应用servletPath/{EndPoint id}
Spring boot 2.x中:
management.server.port=8081 //Spring Boot Actuator http endPoints监听端口
management.endpoints.web.base-path=/manage //设置Actuator前缀替换默认/acutuator