Spring Boot基礎教程27-生產準備-基於HTTP的監控

 

  • 利用Spring Boot的特性進行監控你的應用
  1. 通過HTTP(最簡單方便)
  2. 通過JMX
  3. 通過遠程shell
  • 添加依賴

<!-- actuator -->

<dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

<!-- security -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-security</artifactId>

</dependency>

 

  • 端點(通過執行器端點可以監控應用及與應用進行交互)
  1. 端點暴露的方式取決於你採用的監控方式。如果使用HTTP監控,端點的ID映射到一個URL。例如,默認情況下,health端點將被映射到/health。
  2. 端點會默認有敏感度,根據不同的敏感度是否需要提供用戶密碼認證
  3. 如果沒啓用web安全,則敏感度高的會禁用
  4. 可以通過配置文件進行配置敏感度
  5. 默認情況下,除了shutdown外的所有端點都是啓用的。
  • 配置

#端點的配置

endpoints.sensitive=true

endpoints.shutdown.enabled=true

 

#保護端點

security.basic.enabled=true

security.user.name=roncoo

security.user.password=roncoo

management.security.roles=SUPERUSER

 

#自定義路徑

security.basic.path=/manage

management.context-path=/manage

  • 備註

度量http://localhost:8080/manage/metrics

追蹤http://localhost:8080/manage/trace

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章