spring boot starter actuator(健康監(jiān)控)配置和使用教程
添加POM依賴:
<!-- spring-boot-監(jiān)控--> <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>
application.yml中指定監(jiān)控的HTTP端口(如果不指定,則使用和Server相同的端口);指定去掉某項(xiàng)的檢查(比如不監(jiān)控health.mail):
server: port: 8083 management: port: 8083 security: enabled: false #
監(jiān)控和管理端點(diǎn)
端點(diǎn)名 | 描述 |
---|---|
autoconfig | 所有自動配置信息( positiveMatches :運(yùn)行的, negativeMatches 未運(yùn)行組件) |
auditevents | 審計(jì)事件 |
beans | 所有Bean的信息 |
configprops | 所有配置屬性 |
dump | 線程狀態(tài)信息 |
env | 當(dāng)前環(huán)境信息 |
health | 應(yīng)用健康狀況 |
info | 當(dāng)前應(yīng)用信息 |
metrics | 應(yīng)用的各項(xiàng)指標(biāo) |
mappings | 應(yīng)用@RequestMapping映射路徑 |
shutdown | 關(guān)閉當(dāng)前應(yīng)用(默認(rèn)關(guān)閉) |
trace | 追蹤信息(最新的http請求) |
heapdump | 下載內(nèi)存快照 |
http://localhost:8083/info 讀取配置文件application.properties的 info.*屬性
在InfoProperties 讀取
application.properties :
info.app.version=v1.2.0 info.app.name=abc
在GitProperties 獲取git.properties 的信息
info.app.version=v1.2.0 info.app.name=abc #遠(yuǎn)程關(guān)閉開啟 endpoints.shutdown.enabled=true #訪問:http://localhost:8083/shutdown 關(guān)閉服務(wù)
metrics
{ mem: 573549, //內(nèi)存大小 mem.free: 388198, //內(nèi)存剩余大小 processors: 4, //處理器數(shù)量 instance.uptime: 338426, uptime: 345091, systemload.average: -1, heap.committed: 489984, heap.init: 131072, heap.used: 101785, heap: 1842688, nonheap.committed: 85056, nonheap.init: 2496, nonheap.used: 83566, nonheap: 0, threads.peak: 46, threads.daemon: 36, threads.totalStarted: 72, threads: 39, //線程 classes: 12109, classes.loaded: 12109, //加載的類 classes.unloaded: 0, //沒加載的類 gc.ps_scavenge.count: 10, gc.ps_scavenge.time: 103, gc.ps_marksweep.count: 3, gc.ps_marksweep.time: 219, httpsessions.max: -1, httpsessions.active: 0, gauge.response.mappings: 3, gauge.response.autoconfig: 4, gauge.response.trace: 167, counter.status.200.mappings: 1, counter.status.200.autoconfig: 2, counter.status.200.trace: 1 }
自定義配置說明:
#關(guān)閉metrics功能 endpoints.metrics.enabled=false #開啟shutdown遠(yuǎn)程關(guān)閉功能 endpoints.shutdown.enabled=true #設(shè)置beansId endpoints.beans.id=mybean #設(shè)置beans路徑 endpoints.beans.path=/bean #關(guān)閉beans 功能 endpoints.beans.enabled=false #關(guān)閉所有的 endpoints.enabled=false #開啟單個beans功能 endpoints.beans.enabled=true #所有訪問添加根目錄 management.context-path=/manage management.port=8181
org.springframework.boot.actuate.health 包下對于所有的健康狀態(tài)檢查例如:RedisHealthIndicator ,當(dāng)有redis的starter 時候就會檢查
{ status: "DOWN", //狀態(tài) diskSpace: { status: "UP", total: 395243941888, free: 367246643200, threshold: 10485760 }, rabbit: { status: "DOWN", error: "org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect" }, redis: { status: "UP", version: "4.0.9" }, db: { status: "UP", database: "MySQL", hello: 1 } }
自定義health
•自定義健康狀態(tài)指示器
•1、編寫一個指示器 實(shí)現(xiàn) HealthIndicator 接口
•2、指示器的名字 xxxxHealthIndicator
•3、加入容器中
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.stereotype.Component; @Component public class MyAppHealthIndicator implements HealthIndicator { @Override public Health health() { //自定義的檢查方法 //Health.up().build()代表健康 return Health.down().withDetail("msg","服務(wù)異常").build(); } }
總結(jié)
以上所述是小編給大家介紹的spring boot starter actuator(健康監(jiān)控)配置和使用教程,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
spring cloud 集成 ribbon負(fù)載均衡的實(shí)例代碼
spring Cloud Ribbon 是一個客戶端的負(fù)載均衡器,它提供對大量的HTTP和TCP客戶端的訪問控制。本文給大家介紹spring cloud 集成 ribbon負(fù)載均衡,感興趣的朋友跟隨小編一起看看吧2021-11-11詳談鎖和監(jiān)視器之間的區(qū)別_Java并發(fā)
下面小編就為大家?guī)硪黄斦勬i和監(jiān)視器之間的區(qū)別_Java并發(fā)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06Java基礎(chǔ)教程之類數(shù)據(jù)與類方法
這篇文章主要介紹了Java基礎(chǔ)教程之類數(shù)據(jù)與類方法,本文是對類的深入探討,類數(shù)據(jù)指類的一些屬性、參數(shù)等,類方法就是類包含的功能方法,需要的朋友可以參考下2014-08-08Java?IO篇之Reactor?網(wǎng)絡(luò)模型的概念
Reactor?模式也叫做反應(yīng)器設(shè)計(jì)模式,是一種為處理服務(wù)請求并發(fā)提交到一個或者多個服務(wù)處理器的事件設(shè)計(jì)模式,Reactor?模式主要由?Reactor?和處理器?Handler?這兩個核心部分組成,本文給大家介紹Java?IO篇之Reactor?網(wǎng)絡(luò)模型的概念,感興趣的朋友一起看看吧2022-01-01web.xml?SpringBoot打包可執(zhí)行Jar運(yùn)行SpringMVC加載流程
這篇文章主要為大家介紹了web.xml?SpringBoot打包可執(zhí)行Jar運(yùn)行SpringMVC加載流程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04java實(shí)現(xiàn)航空用戶管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)航空用戶管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-07-07