一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

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

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

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

詳解spring-boot actuator(監控)配置和使用

2021-01-09 14:52Clement-Xu Java教程

本篇文章主要介紹了spring-boot actuator(監控)配置和使用,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

在生產環境中,需要實時或定期監控服務的可用性。spring-boot 的actuator(監控)功能提供了很多監控所需的接口。簡單的配置和使用如下:

1、引入依賴:

?
1
2
3
4
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

如果使用http調用的方式,還需要這個依賴:

?
1
2
3
4
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>

2、配置:

application.yml中指定監控的HTTP端口(如果不指定,則使用和server相同的端口);指定去掉某項的檢查(比如不監控health.mail):

?
1
2
3
4
5
6
7
server:
 port: 8082
management:
 port: 54001
 health:
  mail:
   enabled: false

3、使用:

查看health指標:http://localhost:54001/health

?
1
{"status":"UP","diskSpace":{"status":"UP","total":120031539200,"free":33554337792,"threshold":10485760},"db":{"status":"UP","dataSource1":{"status":"UP","database":"MySQL","hello":1},"dataSource2":{"status":"UP","database":"MySQL","hello":1}}}

4、自定義指標:

4.1 /health:在某個類中implements HealthIndicator接口,然后實現其中的health()方法即可:

代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@SpringBootApplication
@EnableScheduling
public class MySpringBootApplication implements HealthIndicator{
  private static Logger logger = LoggerFactory.getLogger(MySpringBootApplication.class);
   
  public static void main(String[] args) {
    SpringApplication.run(MySpringBootApplication.class, args);
    logger.info("My Spring Boot Application Started");
  }
 
  /**
   * 在/health接口調用的時候,返回多一個屬性:"mySpringBootApplication":{"status":"UP","hello":"world"}
   */
  @Override
  public Health health() {
    return Health.up().withDetail("hello", "world").build();
  }
}

/health 運行結果(注意第二個指標):

{"status":"UP","mySpringBootApplication":{"status":"UP","hello":"world"},"diskSpace":{"status":"UP","total":120031539200,"free":33554337792,"threshold":10485760},"db":{"status":"UP","dataSource1":{"status":"UP","database":"MySQL","hello":1},"dataSource2":{"status":"UP","database":"MySQL","hello":1}}}

4.2 /info:配置如下,可以直接給一個字符串,也可以從pom.xml配置中獲取

?
1
2
3
4
5
6
info:
 app:
  name: "@project.name@" #從pom.xml中獲取
  description: "@project.description@"
  version: "@project.version@"
  spring-boot-version: "@project.parent.version@"

/info的結果如下:

{"app":{"name":"my-spring-boot","description":"Test Project for Spring Boot","version":"1.0","spring-boot-version":"1.3.6.RELEASE"}}

官網:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready

源代碼參考:https://github.com/xujijun/my-spring-boot

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:http://blog.csdn.net/clementad/article/details/52045495

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩影院在线观看 | segou视频在线观看 | 亚州在线 | 午夜A级理论片左线播放 | 国产高清在线精品一区二区三区 | 免费一级毛片在线播放放视频 | 办公室大战秘书呻吟 | 青青青久在线视频免费观看 | 2019男人天堂 | 亚洲第99页 | 高清男的插曲女的 欢迎你老狼 | 亚洲欧美精品一区天堂久久 | 91混血大战上海双胞胎 | 日本xxxxx高清免费观看 | 香蕉国产成版人视频在线观看 | 亚欧综合 | 91精品国产综合久久香蕉 | 色漫在线观看 | xnxx老师 | 性趣用品 | 调教扩张宫颈女人惨叫 | 欧亚专线欧洲m码可遇不可求 | 男人把大ji巴放进男人免费视频 | 国产99久久久国产精品成人 | 久久久久久久国产精品视频 | acg火影忍者熟密姬纲手h | 男人狂躁女人下面狂叫图片 | 国模李丽莎大尺度啪啪 | 唯美清纯 自拍偷 | 亚洲卡一卡2卡三卡4卡无卡三 | 亚洲精品www久久久久久久软件 | 女八把屁股扒开让男生添 | 精品麻豆 | 亚洲高清在线视频 | 亚洲www视频 | 色一情一乱一伦 | 91欧美国产 | 极品美女写真菠萝蜜视频 | 亚洲精品中文字幕在线 | chinese一bdsmⅹxx| 黄色a |