官方原话:
codecentric’s Spring Boot Admin is a community project to manage and monitor your Spring Boot ® applications. The applications register with our Spring Boot Admin Client (via HTTP) or are discovered using Spring Cloud ® (e.g. Eureka, Consul). The UI is just a Vue.js application on top of the Spring Boot Actuator endpoints.
大概意思:
Spring Boot Admin是一个社区项目,用于管理和监视基于SpringBoot的应用程序。客户端应用可以通过Spring Boot Admin Client或者注册中心就可以注册到Spring Boot Admin服务端进行监控。Spring Boot Admin 是在 Spring Boot Actuator 的基础上提供简洁的可视化 WEB UI。2.X版本使用Vue.js重写了UI界面,简洁。
下面进入实战,搭建服务端与客户端:
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.6.RELEASE
com.stwen
springboot-admin-server
0.0.1-SNAPSHOT
springboot-admin-server
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
de.codecentric
spring-boot-admin-starter-server
2.1.6
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-maven-plugin
package com.stwen.admin.server;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableAdminServer
public class SpringbootAdminServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootAdminServerApplication.class, args);
}
}
server:
port: 8888
spring:
application:
name: SpringBootAdmin
boot:
admin:
ui:
title: SpringBootAdmin-Server
启动成功后,访问localhost:8888 ,就可以看到简洁的界面,现在还没有客户端注册上来,所以显示0:
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.6.RELEASE
com.stwen
springboot-admin-client
0.0.1-SNAPSHOT
springboot-admin-client
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
de.codecentric
spring-boot-admin-starter-client
2.1.6
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-maven-plugin
server:
port: 9999
spring:
boot:
admin:
client:
# server地址
url: http://localhost:8888
instance:
#client地址
service-base-url: http://localhost:${server.port}
application:
name: SpringBootAdmin-Client
#Actuator配置:暴露敏感路径,默认情况下,敏感路径并不暴露
management:
endpoints:
web:
exposure:
# 暴露xxx端点,如需暴露多个,用,分隔;如需暴露所有端点,用'*'
include: "*"
endpoint:
health:
# 是否展示健康检查详情
show-details: ALWAYS
# info信息会显示到SpringBootAdmin的server端,这里取的是pom文件中的数据
info:
version: @project.version@
groupId: @project.groupId@
artifactId: @project.artifactId@
这里可以看到具体实例的JVM内存情况:
如果你的应用程序使用了注册中心Spring Cloud Discovery,则不需要SBA Client客户端依赖。只需将SpringBootAdmin Server 服务端注册到注册中心即可,其余的自动配置完成。
org.springframework.cloud
spring-cloud-starter-zookeeper-discovery
2.1.1.RELEASE
org.apache.zookeeper
zookeeper
org.apache.zookeeper
zookeeper
3.4.14
package com.stwen.admin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
@EnableAdminServer
public class SpringbootAdminClient2Application {
public static void main(String[] args) {
SpringApplication.run(SpringbootAdminClient2Application.class, args);
}
}
server:
port: 8888
spring:
application:
name: SpringBootAdmin
boot:
admin:
ui:
title: SpringBootAdmin-Server
cloud:
zookeeper:
#zk 注册中心
connectString: localhost:2181
# eureka注册中心
#eureka:
# client:
# serviceUrl:
# defaultZone: http://localhost:1001/eureka/
#Actuator配置:暴露敏感路径,默认情况下,敏感路径并不暴露
management:
endpoints:
web:
exposure:
# 暴露xxx端点,如需暴露多个,用,分隔;如需暴露所有端点,用'*'
include: "*"
endpoint:
health:
# 是否展示健康检查详情
show-details: ALWAYS
4.4 启动该Server 应用:
可以看到,该Server应用已经把自己注册上zk注册中心,同时也监控了自己。同理,可以将上面的Client 改成类似现在的Server,可以注册监控上。
需要源码的,请下方评论,看到会发你。
本文来自:CSDN 作者:stwen_gan https://blog.csdn.net/a1036645146/article/details/97249153
喜欢的请点个赞再走吧,转载请注明出处,谢谢。