您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“SpringBoot服務(wù)監(jiān)控SpringBootAdmin的使用方法”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“SpringBoot服務(wù)監(jiān)控SpringBootAdmin的使用方法”吧!
github地址: https://github.com/codecentric/spring-boot-admin
文檔地址:https://codecentric.github.io/spring-boot-admin/current/
在項(xiàng)目中使用SpringBootAdmin分為兩部分: 服務(wù)端與客戶端??蛻舳送ㄟ^(guò)http的方式向服務(wù)端提供自生的運(yùn)行狀況
版本: <spring.boot.admin.version>2.1.6</spring.boot.admin.version>
服務(wù)端依賴
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>${spring.boot.admin.version}</version> </dependency>
啟動(dòng)類上標(biāo)記注解@EnableAdminServer
設(shè)置端口
server: port: 8080
啟動(dòng)即可
如果有報(bào)錯(cuò):
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>
完整項(xiàng)目源代碼在 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服務(wù)端的地址
spring: boot: admin: client: url: http://localhost:8080 management: endpoints: web: exposure: include: "*" endpoint: health: show-details: always
啟動(dòng)SpringBoot客戶端項(xiàng)目
訪問(wèn)服務(wù)端配置的地址:http://localhost:8080
如果沒(méi)有數(shù)據(jù),像下面這樣 這是因?yàn)槟愕腟pringBoot項(xiàng)目封裝了監(jiān)控端點(diǎn)返回的數(shù)據(jù),從Info返回的數(shù)據(jù)結(jié)構(gòu)可以看出。
解決方案是,不要讓SpringBoot封裝監(jiān)控端點(diǎn)返回的數(shù)據(jù)
如果使用的是@RestControllerAdvice
則約束一下包路徑@RestControllerAdvice("com.west.lake.blog.controller")
請(qǐng)求日志與請(qǐng)求耗時(shí)監(jiān)控
緩存管理器
到此,相信大家對(duì)“SpringBoot服務(wù)監(jiān)控SpringBootAdmin的使用方法”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。