- github地址: https://github.com/codecentric/spring-boot-admin
- 文档地址:https://codecentric.github.io/spring-boot-admin/current/
在项目中使用SpringBootAdmin分为两部分: 服务端与客户端。客户端通过http的方式向服务端提供自生的运行状况
- 版本:
<spring.boot.admin.version>2.1.6</spring.boot.admin.version>
1. 构建服务端项目
- 服务端依赖
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>${spring.boot.admin.version}</version> </dependency>
- 启动类上标记注解
@EnableAdminServer
- 设置端口
server: port: 8080
- 启动即可
如果有报错:
2019-11-02 09:50:14.924 ERROR 55391 --- [nio-8080-exec-2] o.a.catalina.connector.CoyoteAdapter : Exception while processing an asynchronous request java.lang.IllegalStateException: Calling [asyncError()] is not valid for a request with Async state [MUST_DISPATCH] at org.apache.coyote.AsyncStateMachine.asyncError(AsyncStateMachine.java:440) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:512) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.Request.action(Request.java:430) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.core.AsyncContextImpl.setErrorState(AsyncContextImpl.java:396) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:239) ~[tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:241) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) [tomcat-embed-core-9.0.16.jar:9.0.16] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.16.jar:9.0.16] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_191] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_191] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.16.jar:9.0.16] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]
- 则将Tomcat换成jetty
<dependencies> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> </dependencies>
完整项目源代码在 https://github.com/FutaoSmile/LazyStarter/tree/master/lazy-admin
2. 客户端-需要被监控的服务
- 添加客户端依赖
<dependency> <groupId>org.jolokia</groupId> <artifactId>jolokia-core</artifactId> </dependency> <!-- https://codecentric.github.io/spring-boot-admin/2.1.6/#getting-started--> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>2.1.6</version> </dependency>
- 配置SpringBootAdmin服务端的地址
spring: boot: admin: client: url: http://localhost:8080 management: endpoints: web: exposure: include: "*" endpoint: health: show-details: always
- 启动SpringBoot客户端项目
- 访问服务端配置的地址:
http://localhost:8080
如果没有数据,像下面这样
- 这是因为你的SpringBoot项目封装了监控端点返回的数据,从Info返回的数据结构可以看出。
- 解决方案是,不要让SpringBoot封装监控端点返回的数据
- 如果使用的是
@RestControllerAdvice
则约束一下包路径@RestControllerAdvice("com.west.lake.blog.controller")
请求日志与请求耗时监控
缓存管理器