如何监控springboot的健康状况
SpringBoot1.5.19.RELEASE
一、使用Actuator检查与监控
actuaotr是spring boot项目中非常强大的一个功能,有助于对应用程序进行监控和管理,通过restful api请求来监管、审计、收集应用的运行情况,针对微服务而言它是必不可少的一个环节。
-
在pom文件中添加Actuator坐标
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
-
在全局配置文件中设置关闭安全限制
management.security.enabled=false
-
运行,会发现控制台打印信息变多了

- 直接访问
eg: http://localhost:8080/health http://localhost:8080/dump http://localhost:8080/beans 等
具体可参考:https://www.cnblogs.com/baidawei/p/9183531.html
二、Spring Boot Admin
Spring Boot Admin 提供了很多功能,如显示 name、id 和 version,显示在线状态,Loggers 的日志级别管理,Threads 线程管理,Environment 管理等。
-
访问spring boot admin的github页面:https://github.com/codecentric/spring-boot-admin
-------以下内容在服务端操作:
-
在pom文件中添加spring boot admin 坐标
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>1.5.7</version>
</dependency>
</dependencies>
-
在启动类中增加注解:@EnableAdminServer
@SpringBootApplication
@EnableAdminServer
public class SpringbootHelloworldApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootHelloworldApplication.class,args);
}
}
-------以下内容在客户端操作:
-
在客户端(另一个项目)pom文件添加依赖
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>1.5.7</version>
</dependency>
-
修改properties文件
#服务端的ip地址和端口
spring.boot.admin.url: http://localhost:8383
management.security.enabled=false
-
此时客户端的端口是:8080 ; 服务端的端口是8383
-
先启动服务端,打开网页:http://localhost:8383 (什么都没有,因为客户端还没启动)

- 启动客户端
 (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|