国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Java > 正文

spring boot starter actuator(健康監(jiān)控)配置和使用教程

2024-07-14 08:41:13
字體:
供稿:網(wǎng)友

添加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: 8083management:  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.0info.app.name=abc

在GitProperties  獲取git.properties 的信息 

info.app.version=v1.2.0info.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è)置beansIdendpoints.beans.id=mybean#設(shè)置beans路徑endpoints.beans.path=/bean#關(guān)閉beans 功能endpoints.beans.enabled=false#關(guān)閉所有的endpoints.enabled=false #開啟單個(gè)beans功能endpoints.beans.enabled=true#所有訪問添加根目錄management.context-path=/manage?management.port=8181

org.springframework.boot.actuate.health 包下對于所有的健康狀態(tài)檢查例如:RedisHealthIndicator ,當(dāng)有redis的starter 時(shí)候就會檢查

{  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、編寫一個(gè)指示器 實(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;@Componentpublic 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)控)配置和使用教程,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對VeVb武林網(wǎng)網(wǎng)站的支持!


注:相關(guān)教程知識閱讀請移步到JAVA教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 泾源县| 平原县| 文化| 新河县| 富源县| 丰镇市| 海宁市| 和政县| 和硕县| 赤壁市| 江源县| 北京市| 永城市| 麦盖提县| 梁河县| 济宁市| 商南县| 吴桥县| 新化县| 华蓥市| 岳普湖县| 乐昌市| 博爱县| 赣州市| 肇源县| 乌拉特后旗| 平南县| 宣武区| 湘阴县| 贵港市| 通化县| 迭部县| 巨野县| 肃北| 龙岩市| 清远市| 昌邑市| 马山县| 武陟县| 延吉市| 宜兰县|