激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - spring boot starter actuator(健康監控)配置和使用教程

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

2021-05-08 12:12yangliuhbhd Java教程

這篇文章主要介紹了spring-boot-starter-actuator(健康監控)配置和使用教程,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下

添加pom依賴:

?
1
2
3
4
5
6
7
8
9
<!-- spring-boot-監控-->
<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中指定監控的http端口(如果不指定,則使用和server相同的端口);指定去掉某項的檢查(比如不監控health.mail):

?
1
2
3
4
5
6
server:
 port: 8083
management:
  port: 8083
  security:
   enabled: false #

監控和管理端點

 

端點名 描述
autoconfig 所有自動配置信息( positivematches :運行的, negativematches 未運行組件)
auditevents 審計事件
beans 所有bean的信息
configprops 所有配置屬性
dump 線程狀態信息
env 當前環境信息
health 應用健康狀況
info 當前應用信息
metrics 應用的各項指標
mappings 應用@requestmapping映射路徑
shutdown 關閉當前應用(默認關閉)
trace 追蹤信息(最新的http請求)
heapdump 下載內存快照

 

讀取配置文件application.properties的 info.*屬性

  在infoproperties 讀取

  application.properties :

?
1
2
info.app.version=v1.2.0
info.app.name=abc

在gitproperties  獲取git.properties 的信息 

?
1
2
3
4
5
info.app.version=v1.2.0
info.app.name=abc
#遠程關閉開啟
endpoints.shutdown.enabled=true
#訪問:http://localhost:8083/shutdown  關閉服務

metrics

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
mem: 573549//內存大小
mem.free: 388198, //內存剩余大小
processors: 4, //處理器數量
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
}

自定義配置說明:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#關閉metrics功能
endpoints.metrics.enabled=false
#開啟shutdown遠程關閉功能
endpoints.shutdown.enabled=true
#設置beansid
endpoints.beans.id=mybean
#設置beans路徑
endpoints.beans.path=/bean
#關閉beans 功能
endpoints.beans.enabled=false
#關閉所有的
endpoints.enabled=false
#開啟單個beans功能
endpoints.beans.enabled=true
#所有訪問添加根目錄
management.context-path=/manage?
management.port=8181

org.springframework.boot.actuate.health 包下對于所有的健康狀態檢查例如:redishealthindicator ,當有redis的starter 時候就會檢查

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
  status: "down", //狀態
  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

•自定義健康狀態指示器

•1、編寫一個指示器 實現 healthindicator 接口

•2、指示器的名字 xxxxhealthindicator

•3、加入容器中

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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","服務異常").build();
  }
}

總結

以上所述是小編給大家介紹的spring boot starter actuator(健康監控)配置和使用教程,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!

原文鏈接:https://blog.csdn.net/yangliuhbhd/article/details/80655847

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲91精品| 亚洲字幕av | 综合激情网 | 成人激情在线 | 久久毛片免费观看 | 国产超碰人人做人人爱 | 九九热精品在线视频 | 黄色片视频观看 | 成人免费电影在线观看 | 国产乱乱视频 | 国产精品福利一区 | 久久人人爽人人爽人人片av高清 | 在线播放免费视频 | av电影网站在线观看 | 久久人人爽人人爽人人片av高请 | 国产羞羞网站 | 高清av在线| 国产视频软件在线 | 成人在线观看一区二区 | 国产成年人网站 | 免费网站看v片在线a | 久久狠狠高潮亚洲精品 | 午夜视频啊啊啊 | 国产亚洲精品综合一区 | 亚洲天堂字幕 | 欧美久久久一区二区三区 | 亚洲第一页中文字幕 | 男女一边摸一边做羞羞视频免费 | 日韩在线黄色片 | 精品久久久久久亚洲精品 | 特片网久久 | 亚洲精品欧美二区三区中文字幕 | 九九热精品在线视频 | 久久国产一级 | 中文字幕精品在线播放 | 欧美成人精品欧美一级乱黄 | 国产瑟瑟视频 | 一级黄色片武则天 | 成人在线激情视频 | av中文一区| 国产欧美日韩在线不卡第一页 |