前言
使用springboot进行性能监控简直是一种享受
服务端
服务端的配置简直是0代码,只需要加入一个actuator插件即可
服务端插件依赖
de.codecentric
spring-boot-admin-starter-server
de.codecentric
spring-boot-admin-dependencies
${spring-boot-admin.version}
pom
import
为了区分端口,我在application.properties里面配置了端口号为8090
server.port=8090
此时整个服务端就已经配置完成了,真的是一行代码都不用写,直接启动springboot项目就可以了。
客户端
爽就爽在客户端也是0代码,也是需要加入actuator插件,不过服务端加入的是server,客户端加入的是client,然后连接一下服务端就可以了
客户端配置
de.codecentric
spring-boot-admin-starter-client
为了监控更多一些东西,我加入了redis和mysql的配置
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-data-redis
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.1
org.mybatis
mybatis
3.4.5
compile
mysql
mysql-connector-java
org.springframework.boot
spring-boot-starter-test
test
de.codecentric
spring-boot-admin-dependencies
${spring-boot-admin.version}
pom
import
application.properties的配置如下
spring.redis.host=localhost
spring.redis.port=6379
spring.datasource.url=jdbc:mysql://localhost:3306/socks
spring.datasource.username=root
spring.datasource.password=root
#开启健康检查的完整信息
management.endpoint.health.show-details=always
#暴露监控的所有的节点
management.endpoints.web.exposure.include=*
#健康检查路径更改,默认为actuator
management.endpoints.web.base-path=/hah
spring.boot.admin.client.url=http://localhost:8090
这样就可以启动了
效果
此时打开服务端,地址为http://localhost:8090,就可以看到监控界面了
点击应用进去