How does spring boot health check work with containers

  • 的头像-Tumi
  • 16 day agopublish

Zhe Qi Nei Rong Dang Zhong Xiao Bian Jiang Hui Gei Da Jia Dai Lai You Guan SpringBoot Jian Kang Jian Cha Zen Yang Yu Rong Qi Pei He , Wen Zhang Nei Rong Feng Fu Qie Yi Zhuan Ye De Jiao Du Wei Da Jia Fen Xi He Xu Shu , Yue Du Wan Zhe Pian Wen Zhang Xi Wang Da Jia Ke Yi You Suo Shou Huo 。

Jian Kong De Zhong Yao Xing Jiu Bu Bi Duo Shuo Liao Ba , Bu Yao Zai Hua Gong Fu Kai Hui Tao Lun Ta De Bi Yao Xing Liao , Dang Ni Xian Shang Yu Dao Wen Ti , Jiu Bu Hui Zai Huai Yi Jian Kong Shi Lang Fei Kai Fa Cheng Ben De Jian She 。 Jian Kong Rang Ren Gao Bie Liao Kao “ Cai ” Lai Wei Chi De Jiu Huo Xian Zhuang , Ta Neng Gou Liu Xia Zheng Ju , Lai Zhi Cheng Wo Men Hou Xu De Fen Xi 。

Zuo Wei Jian Kong De Shou Yao Mu Biao , Fu Wu De Cun Huo Xing , Ye Jiu Shi Ta De Jian Kang Zhuang Kuang , Cheng Wei Liao Zhong Zhong Zhi Zhong 。SpringBoot Ke Yi Tong Guo Jian Dan De Can Shu , Lai Kai Qi Jian Kang Jian Cha , Bing Neng Gou He Zhu Liu De Jian Kong Xi Tong Ji Cheng Qi Lai 。

1. Jian Kong Kai Qi

Zai Spring Zhong , Shi Shi Yong actuator Zu Jian , Lai Zuo Jian Kong Deng Xiang Guan Cao Zuo 。 Ke Yi Zai pom Zhong Jia Ru Xia Mian De starter:

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

Dui Yu gradle Lai Shuo , Jia Ru Xia Mian Zhe Ge 。

dependencies {   compile("org.springframework.boot:spring-boot-starter-actuator") }

Fang Wen /actuator/health, Ji Ke Huo Qu Xiang Mu De Jian Kang Zhuang Kuang 。

{"status":"UP"}

Zai application.yml Wen Jian Li , Jia Ru Ru Xia De Nei Rong :

management:   endpoint:     health:       show-details: always

Zai Ci Fang Wen Zhe Ge Jie Kou , Jiang Shu Chu Xiang Xi De Nei Rong 。 Bao Kuo DB De Zhuang Tai 、 Ci Pan Zhuang Tai Deng 。 Ke Yi Kan Dao , Zui Wai Ceng De status, Qi Shi Shi Nei Bu Ge Ge Zu Jian Zhuang Tai De Ji He 。

{     "status":"UP",     "components":{         "db":{             "status":"UP",             "details":{                 "database":"H2",                 "validationQuery":"isValid()"             }         },         "diskSpace":{             "status":"UP",             "details":{                 "total":250685575168,                 "free":31373905920,                 "threshold":10485760,                 "exists":true             }         },         "ping":{             "status":"UP"         }     } }

2. Zi Ding Yi Indicator

Zhe Xie Gong Neng , Shi You Indicators Lai Shi Xian De (HealthIndicator)。 Bi Ru Xia Mian Zhe Xie :

  • DataSourceHealthIndicator

  • DiskSpaceHealthIndicator

  • CouchbaseHealthIndicator

  • MongoHealthIndicator

  • RedisHealthIndicator

  • CassandraHealthIndicator

Ru Guo Ni Shi Yong De Shi Zu Jian Ti Gong De starter, Zhe Xie Indicator Jiu Hui Zai /health Jie Kou Jin Xing Ju He , Ru Guo Ni Bu Xiang Yao Jian Kong Mou Ge Zu Jian , Ke Yi Zai Pei Zhi Zhong Ba Ta Guan Bi 。

management:   health:     mongo:       enabled: false

Ming Bai Liao Zhe Ge Dao Li , Zai Zuo Yi Xie Zu Jian De Shi Hou Shi Hou , Jiu Ke Yi Tong Guo Zhe Zhong Fang Shi , Lai Ti Gong Zu Jian Zi Dai De Jian Kang Jian Cha : Zhi Xu Yao Shi Xian HealthIndicator Jie Kou Jiu Ke Yi Liao 。 Dai Ma Yang Li Ru Xia :

@Component @Slf4j public class X implements HealthIndicator {     @Override     public Health health() {         try {             // Jian  Cha  Zu  Jian  Zhuang  Tai  Yi  Chang  Xin  Xi          } catch (Exception e) {             log.warn("Failed to connect to: {}", URL);             return Health.down()                     .withDetail("error", e.getMessage())                     .build();         }         return Health.up().build();     } }

3. Jie Ru Jian Kong Xi Tong

Geng Duo Qing Kuang , Wo Men Shi Xi Wang Ba Ye Wu Jian Kong De Shu Ju , Shi Yong Zhuan Ye De Jian Kong Zu Jian Shou Ji Qi Lai 。 Zhe Ge Zai SpringBoot Zhong , Ke Yi Shi Yong micrometer Lai Shi Xian 。

Yi Zui Liu Xing De prometheus Wei Li , Zai pom Li Zeng Jia Xia Mian De Nei Rong 。

<dependency>     <groupId>io.micrometer</groupId>     <artifactId>micrometer-registry-prometheus</artifactId> </dependency>

Dang Ran , Wo Men Ye Yao Zai yaml Li Pei Zhi Yi Xie Nei Rong 。 Ta Xian Zai Kan Qi Lai Chang Zhe Ge Yang Zi :

management:   endpoints:     web:       exposure:         include: health,info,prometheus   endpoint:     health:       show-details: always

Zhe Shi Hou , Fang Wen /actuator/prometheus, Ji Ke Huo Qu prometheus Ge Shi De Jian Kong Shu Ju 。

Lei Si Yu Xia Mian Zhe Zhong :

jvm_memory_used_bytes{area="heap",id="PS Survivor Space",} 0.0 jvm_memory_used_bytes{area="heap",id="PS Old Gen",} 2.9444904E7 jvm_memory_used_bytes{area="heap",id="PS Eden Space",} 6.829E7 jvm_memory_used_bytes{area="nonheap",id="Metaspace",} 5.917196E7 jvm_memory_used_bytes{area="nonheap",id="Code Cache",} 1.0929088E7 jvm_memory_used_bytes{area="nonheap",id="Compressed Class Space",} 8420512.0

Zai prometheus De target Ye Mian , Ke Yi Kan Dao Xia Mian De Xin Xi :

SpringBoot Jian  Kang  Jian  Cha  Zen  Yang  Yu  Rong  Qi  Pei  He

Zui Zhong Zai Grafana Li , Chang De Geng Jia Yao Yan Yi Xie 。

SpringBoot Jian  Kang  Jian  Cha  Zen  Yang  Yu  Rong  Qi  Pei  He

Na Ta Du Neng Jian Kong Yi Xie Shi Me Dong Xi Ne ? Wo Men Lai Kan Yi Xia :

  • Fu Wu Jie Dian Ji Ben Xin Xi , Bao Kuo Nei Cun CPU Wang Luo IO Deng

  • JVM Dui Zhan Xin Xi

  • JVM GC Xin Xi ,STW Xin Xi

  • Mo Ren HikariCP De Lian Jie Chi Xin Xi

  • HTTP Qing Qiu Jie Kou Xin Xi ( Zui Da Hao Shi ,QPS Zui Gao )

  • Tomcat Rong Qi Jian Kong

  • Logback Ri Zhi Da Yin Jian Kong ( Ge Ji Bie Tiao Shu )

  • … Qi Ta

Ke Yi Kan Dao , Zhi Xu Yao Bao Lu Zhe Me Yi Ge Jie Kou , Jiu Ke Yi Dui Xiang Mu Zhong De Zu Jian , Jin Xing Bi Jiao Quan Mian De Zhang Kong 。

4. Yu Rong Qi Pei He

Zui Hou Yi Dian , You Yu SpringBoot Fu Wu , Jing Chang Hui Fa Bu Dao Yi Xie Rong Qi Zhong , Bi Ru docker。 Zhe Ge Shi Hou , Jiu Yao Yong Dao probes Pei Zhi (kube You Xiang Tong De Gai Nian )。probes Shi Tan Ce De Yi Si , Yong Lai Qu Fen Liveness He Readiness Liang Zhong Zhuang Tai 。

Zui Zhong De Pei Zhi Ru Xia :

management:   health:     probes:       enabled: true   endpoints:     web:       exposure:         include: health,info,prometheus   endpoint:     health:       show-details: always

Zhe Shi Hou , Wo Men Jiang Zai Zuo Lan Qi De Jie Kou Zhong Huo Qu Liang Ge Fen Zu , Zhan Shi Ru Xia :

SpringBoot Jian  Kang  Jian  Cha  Zen  Yang  Yu  Rong  Qi  Pei  He

  • http://localhost:8080/actuator/health/liveness

  • http://localhost:8080/actuator/health/readiness

Zhe Liang Ge Lian Jie , Qian Zhe Yong Yu Pan Duan Rong Qi Shi Fou Ying Gai Zhong Qi ; Hou Zhe Pan Duan Fu Wu Shi Fou Ke Yong , Ru Guo Ke Yong , Jiang Kai Shi Jie Shou Wai Bu De Qing Qiu 。

End

Dui Yu Gui Mo Bi Jiao Xiao De SpringBoot Ying Yong Lai Shuo , Shi Yong SpringBootAdmin Yi Lei De Jian Kong , Jiu Yi Jing Zu Gou Liao 。 Dan Ru Guo Ni De Qi Ye Shi Ji Zhong Shi Bu Shu , Jie Dian Duo Qie Bian Hua Pin Fan , Yi Ge Tong Yi De Jian Kong Jian She Ping Tai Shi Fei Chang Bi Yao De 。

Chu Liao Prometheus,SpringBoot De Metrics Huan Zhi Chi Yi Xia Zu Jian :

  • AppOptics

  • Atlas

  • Datadog

  • Dynatrace

  • Elastic

  • Ganglia

  • Graphite

  • Humio

  • Influx

  • JMX

  • KairosDB

  • New Relic

  • Prometheus

  • SignalFx

  • Simple (in-memory)

  • Stackdriver

  • StatsD

  • Wavefront

Shang Shu Jiu Shi Xiao Bian Wei Da Jia Fen Xiang De SpringBoot Jian Kang Jian Cha Zen Yang Yu Rong Qi Pei He Liao , Ru Guo Gang Hao You Lei Si De Yi Huo , Bu Fang Can Zhao Shang Shu Fen Xi Jin Xing Li Jie 。 Ru Guo Xiang Zhi Dao Geng Duo Xiang Guan Zhi Shi , Huan Ying Guan Zhu Tumi Yun Xing Ye Zi Xun Pin Dao 。

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment