av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Springboot actuator應(yīng)用后臺監(jiān)控實現(xiàn)

瀏覽:104日期:2023-05-22 11:05:56

一 前言

springboot 額外的特色是提供了后臺應(yīng)用監(jiān)控,可以通過 HTTP 或者 JMX的方式管理監(jiān)控應(yīng)用,本文主講HTTP方式;其主要的功能是監(jiān)控應(yīng)用的健康狀態(tài),查看環(huán)境變量等;

二 pom.xml

springboot 2.1.1,主要引入 actuator 依賴,web依賴用于測試;

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>

三 默認(rèn)開啟端點

3.1 默認(rèn)端點 health

直接編寫主程序入口,啟動;瀏覽器輸入 http://localhost:8080/actuator/health;結(jié)果如下,狀態(tài)是UP;

Springboot actuator應(yīng)用后臺監(jiān)控實現(xiàn)

翻翻源碼heath狀態(tài)碼如下

public OrderedHealthAggregator() { this.setStatusOrder(Status.DOWN, Status.OUT_OF_SERVICE, Status.UP, Status.UNKNOWN); } DOWN 服務(wù)無法獲得,狀態(tài)碼503; .OUT_OF_SERVICE 服務(wù)無法獲得,狀態(tài)碼503; UP 獲得服務(wù),狀態(tài)碼200; UNKNOWN 獲得未知服務(wù),狀態(tài)碼200;

在 application.yml 中配置 healthy 信息 示例如下:

management: endpoint: health: show-details: always

打印詳細(xì)信息:

Springboot actuator應(yīng)用后臺監(jiān)控實現(xiàn)

基本配置如下:

never :默認(rèn),表示不顯示詳細(xì)信息;when-authorized:詳細(xì)信息顯示給 認(rèn)證過的用戶;使用

management.endpoint.health.roles 配置always: 顯示詳細(xì)信息給所有用戶3.2 默認(rèn)端點 info

瀏覽器輸入 http://localhost:8080/actuator/info; 展示空信息如下圖:

Springboot actuator應(yīng)用后臺監(jiān)控實現(xiàn)

在application.yml 中 配置工程 info 信息 示例如下;

#配置信息info: actuator: name: springboot-actutor version: 1.0.0 author: zszxz

展示結(jié)果如下:

Springboot actuator應(yīng)用后臺監(jiān)控實現(xiàn)

四 HTTP端點說明

端點 端點描述 默認(rèn)值 auditevents 當(dāng)前應(yīng)用的審計事件 Yesbeans 顯示spring IOC 容器加載的所有bean Yescaches 顯示可獲得的緩存 Yesconditions 顯示自動配置通過condition判斷匹配或者不匹配的配置信息 Yesconfigprops 顯示 通過 @ConfigurationProperties 配置的屬性信息 Yesenv spring環(huán)境變量屬性信息 Yesflyway 顯示flyway 配置數(shù)據(jù)庫已經(jīng)遷移的信息 Yeshealth 顯示應(yīng)用的健康信息 Yeshttptrace 顯示 HTTP 軌跡信息默認(rèn)最新的100 HTTP request或response Yesinfo 顯示自定義的應(yīng)用信息 Yesintegrationgraph 顯示spring 整合 graph 信息 Yesloggers 顯示配置文件中日志修改信息 Yesliquibase 顯示 任意的 Liquibase 數(shù)據(jù)庫已經(jīng)遷移的信息 Yesmetrics 顯示當(dāng)前應(yīng)用的指標(biāo) Yesmappings 顯示 @RequestMapping paths. 配置的路徑信息 Yesscheduledtasks 顯示任務(wù)調(diào)度信息 Yessessions 刪除或者恢復(fù)Spring Session會話,不支持web響應(yīng)式編程 Yesshutdown 關(guān)閉應(yīng)用 Nothreaddump 執(zhí)行一個線程轉(zhuǎn)儲 Yes

五 配置開啟端點

application.yml 中配置需要開啟的端點,其中 * 表示開啟所有端點,示例如下:

management: endpoints: web: exposure: # 使用通配符 * 表示匹配所有端點 # 排除的端點 exclude: caches # 包括的端點 include: info,health,beans,env,shutdown,threaddump

5.1 threaddump示例

http://localhost:8080/actuator/threaddump ;用于返回線程快照,分析線程阻塞,死鎖等,部分內(nèi)容如下

{'threads': [{'threadName': 'DestroyJavaVM','threadId': 41,'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}

5.2 beans示例

http://localhost:8080/actuator/beans ; 用于返回 spring 容器加載的所有bean,部分內(nèi)容如下;

{'contexts': {'application': {'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']},'defaultServletHandlerMapping': {'aliases': [],'scope': 'singleton','type': 'org.springframework.web.servlet.HandlerMapping','resource': 'class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]','dependencies': []}

5.3 關(guān)閉應(yīng)用示例

普通情況下是沒有開啟這個配置,是比較危險的動作,會導(dǎo)致應(yīng)用停止;修改application.yml配置如下

management: endpoints: web: exposure: # 使用通配符 * 表示匹配所有端點 # 排除的端點 exclude: caches # 包括的端點 include: info,health,beans,env,shutdown endpoint: health: show-details: always # 開啟關(guān)閉應(yīng)用 需要post請求 shutdown: enabled: true

訪問地址 http://localhost:8080/actuator/shutdown; 注意僅支持使用POST請求,否則 會 405錯誤;

六 CORS 支持

application.yml 修改配置如下, allowed-origins 中允許跨域的ip地址; allowed-methods 配置 允許通過的請求,還有支持時間等;

management: endpoints: web: exposure: # 使用通配符 * 表示匹配所有端點 # 排除的端點 exclude: caches # 包括的端點 include: info,health,beans,env,shutdown # 跨域處理 cors: allowed-origins: http://localhost:8080/ allowed-methods: post,delete,get,put endpoint: health: show-details: always # 開啟關(guān)閉應(yīng)用 需要post請求 shutdown: enabled: true

七 修改默認(rèn)路徑

在 配置文件中添加 base-path , 會修改掉默認(rèn)路徑 actuator/endpoint;

management: endpoints: web: exposure: # 使用通配符 * 表示匹配所有端點 # 排除的端點 exclude: caches # 包括的端點 include: info,health,beans,env,shutdown # 自定義配置監(jiān)控路徑 base-path: /zszxz # 跨域處理 cors: allowed-origins: http://localhost:8080/ allowed-methods: post,delete,get,put endpoint: health: show-details: always # 開啟關(guān)閉應(yīng)用 需要post請求 shutdown: enabled: true

示例url: http://localhost:8080/zszxz/info

結(jié)果如下

Springboot actuator應(yīng)用后臺監(jiān)控實現(xiàn)

八 其他配置說明

還可以引入 security 依賴 配置 賬號密碼,角色信息,達(dá)到訪問控制,詳細(xì)的可以參照官網(wǎng);

還可以使用注解進(jìn)行配置,自定義端點,詳細(xì)參照官網(wǎng);

jmx支持,可以使用open jdk 自帶的工具 jconsole 進(jìn)行監(jiān)控;

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 中文日本在线 | 三级免费网| 日韩一区二区三区精品 | 精品一区二区av | 国产伊人久久久 | 色天堂影院 | 精品一区二区三区四区在线 | caoporn国产精品免费公开 | 日本成人毛片 | 成人免费视频网站在线看 | 亚洲成人一级 | 成人免费久久 | 日韩在线不卡 | 全部免费毛片在线播放网站 | 亚洲精品中文字幕在线观看 | 亚洲日本视频 | 一区二区三区亚洲 | 亚洲国产偷 | 韩日精品在线观看 | 91精品国产综合久久精品图片 | 最新国产在线 | 美国一级毛片a | 一区二区伦理电影 | 精品国产乱码久久久久久闺蜜 | 国产成人精品一区二区三区在线 | 国产91网址 | 国产成人久久av免费高清密臂 | 色综合久久天天综合网 | 久久小视频| 大吊一区二区 | 91在线一区 | 久久精品国产久精国产 | 久久久久久国产 | 逼逼网 | 亚洲一区二区三区在线免费观看 | 久久亚洲国产 | 久久久入口 | 精品久久久久久久久久久久 | 99re国产| 久久久久国产 | 夜夜爽99久久国产综合精品女不卡 |