本篇内容主要讲解“SpringBoot服务监控SpringBootAdmin的使用方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“SpringBoot服务监控SpringBootAdmin的使用方法”吧!
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>
服务端依赖
<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
添加客户端依赖
<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")
请求日志与请求耗时监控
缓存管理器
到此,相信大家对“SpringBoot服务监控SpringBootAdmin的使用方法”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。