一、为项目整合Spring Boot Actuator
Spring Boot Actuator 提供了很多监控的端点,可以通过http://{ip}:{port}/{endPoint}的形式来访问这些端点,通过访问这些端点来查看应用的健康状况。
添加actuator依赖:
<!-- 整合actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.1.14.RELEASE</version>
</dependency>
springcloud版本为: Greenwich.SR5
1. 查看health端点
访问localhost:8081/actuator/health 如果是up表示正常。
可以直接使用 /health端点来查看应用是否正常。
如果返回的是 {"status":"down"}, 请检查后台相关联的服务器是否都正常启动,比如redis服务器是否已启动并可以连接,mysql数据库有没有连接好。
把有问题的连接解决后,重写访问 /actuator/health,就能是up。
2.查看Info端点:
访问localhost:8081/actuator/info
可以发现info端点没有返回任何数据给我们。我们可以通过配置info.*属性来定义info端点公开的应用信息数据。在application.properties或者application.yml文件中添加如下配置:
[email protected]@
[email protected]@
[email protected]@
[email protected]@
配置好属性后,再次访问地址:
可以发现,这边的应用属性清晰的展现在我们眼前!