SpringBoot配置Actuator組件,實(shí)現(xiàn)系統(tǒng)監(jiān)控
一、Actuator簡(jiǎn)介
監(jiān)控分類
- Actuator 提供Rest接口,展示監(jiān)控信息。
- 接口分為三大類:
- 應(yīng)用配置類:獲取應(yīng)用程序中加載的應(yīng)用配置、環(huán)境變量、自動(dòng)化配置報(bào)告等與SpringBoot應(yīng)用相關(guān)的配置類信息。
- 度量指標(biāo)類:獲取應(yīng)用程序運(yùn)行過(guò)程中用于監(jiān)控的度量指標(biāo),比如:內(nèi)存信息、線程池信息、HTTP請(qǐng)求統(tǒng)計(jì)等。
- 操作控制類:提供了對(duì)應(yīng)用的關(guān)閉等操作類功能。
二、與SpringBoot2.0整合
1、核心依賴Jar包
<!-- 監(jiān)控依賴 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
2、Yml配置文件
# 端口 server: port: 8016 spring: application: # 應(yīng)用名稱 name: node16-boot-actuator management: endpoints: web: exposure: # 打開(kāi)所有的監(jiān)控點(diǎn) include: "*" # 自定義監(jiān)控路徑 monitor # 默認(rèn)值:http://localhost:8016/actuator/* # 配置后:http://localhost:8016/monitor/* base-path: /monitor endpoint: health: show-details: always shutdown: # 通過(guò)指定接口關(guān)閉 SpringBoot enabled: true # 可以自定義端口 # server: # port: 8089 # 描述項(xiàng)目基礎(chǔ)信息 info: app: name: node16-boot-actuator port: 8016 version: 1.0.0 author: cicada
三、監(jiān)控接口詳解
1、Info接口
Yml文件中配置的項(xiàng)目基礎(chǔ)信息
路徑:http://localhost:8016/monitor/info 輸出: { "app": { "name": "node16-boot-actuator", "port": 8016, "version": "1.0.0", "author": "cicada" } }
2、Health接口
health 主要用來(lái)檢查應(yīng)用的運(yùn)行狀態(tài)
路徑:http://localhost:8016/monitor/health 輸出: { "status": "UP", "details": { "diskSpace": { "status": "UP", "details": { "total": 185496236032, "free": 140944084992, "threshold": 10485760 } } } }
3、Beans接口
展示了 bean 的類型、單例多例、別名、類的全路徑、依賴Jar等內(nèi)容。
路徑:http://localhost:8016/monitor/beans 輸出: { "contexts": { "node16-boot-actuator": { "beans": { "endpointCachingOperationInvokerAdvisor": { "aliases": [], "scope": "singleton", "type": "org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor", "resource": "class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.class]", "dependencies": ["environment"] } } } }
4、Conditions接口
查看配置在什么條件下有效,或者自動(dòng)配置為什么無(wú)效。
路徑:http://localhost:8016/monitor/conditions 輸出: { "contexts": { "node16-boot-actuator": { "positiveMatches": { "AuditAutoConfiguration#auditListener": [{ "condition": "OnBeanCondition", "message": "@ConditionalOnMissingBean" }], } }
5、HeapDump接口
自動(dòng)生成Jvm的堆轉(zhuǎn)儲(chǔ)文件HeapDump,可以使用監(jiān)控工具 VisualVM 打開(kāi)此文件查看內(nèi)存快照。
路徑:http://localhost:8016/monitor/heapdump
6、Mappings接口
描述 URI 路徑和控制器的映射關(guān)系
路徑:http://localhost:8016/monitor/mappings 輸出: { "contexts": { "node16-boot-actuator": { "mappings": { "dispatcherServlets": { "dispatcherServlet": [ { "handler": "Actuator web endpoint 'auditevents'", "predicate": "{GET /monitor/auditevents || application/json]}", "details": { "handlerMethod": { "className": "org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping.Operat "name": "handle", "descriptor": "(Ljavax/servlet/http/HttpServletRequest;Ljava/util/Map;)Ljava/lang/Object;" }, "requestMappingConditions": { "consumes": [], "headers": [], "methods": ["GET"], "params": [], "patterns": ["/monitor/auditevents"], "produces": [{ "mediaType": "application/vnd.spring-boot.actuator.v2+json", "negated": false }, { "mediaType": "application/json", "negated": false }] } } } } } }
7、ThreadDump接口
展示線程名、線程ID、是否等待鎖、線程的狀態(tài)、線程鎖等相關(guān)信息。
路徑:http://localhost:8016/monitor/threaddump 輸出: { "threads": [{ "threadName": "DestroyJavaVM", "threadId": 34, "blockedTime": -1, "blockedCount": 0, "waitedTime": -1, "waitedCount": 0, "lockName": null, "lockOwnerId": -1, "lockOwnerName": null, "inNative": false, "suspended": false, "threadState": "RUNNABLE", "stackTrace": [], "lockedMonitors": [], "lockedSynchronizers": [], "lockInfo": null } ] }
8、ShutDown接口
優(yōu)雅關(guān)閉 Spring Boot 應(yīng)用,默認(rèn)只支持POST請(qǐng)求。
路徑:http://localhost:8016/monitor/shutdown
四、源代碼地址
GitHub地址:知了一笑
https://github.com/cicadasmile/spring-boot-base
碼云地址:知了一笑
https://gitee.com/cicadasmile/spring-boot-base
以上就是SpringBoot配置Actuator組件,實(shí)現(xiàn)系統(tǒng)監(jiān)控的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot配置Actuator的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
MyBatis映射文件resultMap元素中使用多個(gè)association的方法
這篇文章主要介紹了MyBatis映射文件resultMap元素中使用多個(gè)association的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03Java適配器模式_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了Java適配器模式,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07Java中BigDecimal除法使用不當(dāng)導(dǎo)致精度問(wèn)題
本文主要介紹了Java中BigDecimal除法使用不當(dāng)導(dǎo)致精度問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11Java初學(xué)者之五子棋游戲?qū)崿F(xiàn)教程
這篇文章主要為大家詳細(xì)介紹了Java初學(xué)者之五子棋游戲?qū)崿F(xiàn)教程,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10java版微信公眾平臺(tái)消息接口應(yīng)用示例
這篇文章主要介紹了java版微信公眾平臺(tái)消息接口應(yīng)用,結(jié)合實(shí)例形式對(duì)比分析了PHP與java應(yīng)用微信公眾平臺(tái)接口的相關(guān)調(diào)用與操作技巧,需要的朋友可以參考下2017-07-07快速解決idea打開(kāi)某個(gè)項(xiàng)目卡住的問(wèn)題
這篇文章主要介紹了解決idea打開(kāi)某個(gè)項(xiàng)目卡住的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08MybatisPlus 插入或更新數(shù)據(jù)時(shí)自動(dòng)填充更新數(shù)據(jù)解決方案
本文主要介紹了MybatisPlus 插入或更新數(shù)據(jù)時(shí)自動(dòng)填充更新數(shù)據(jù)解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09