springboot 使用actuator監控

2022-06-21 19:24:06 字數 2968 閱讀 2000

spring-boot-starter-actuator是乙個用於暴露自身資訊的模組,主要用於監控與管理。

org.springframework.boot

spring-boot-starter-actuator

使用字首/actuator加上端點id來訪問。例如,在預設情況下,health端點對映到/actuator/health。

雖然大部分端點在預設情況下都是啟用狀態,但是在spring boot應用中,預設只開啟info端點和health端點。其餘端點都需要通過宣告屬性來開啟

management:

endpoints:

web:

exposure:

include: ["*"] #開啟全部端點相關**

這時我們可以像使用任何其他敏感url一樣注意保護http端點。若存在spring security,則預設使用spring security的內容協商策略來保護端點。

<

dependency

>

<

groupid

>org.springframework.boot

groupid

>

<

artifactid

>spring-boot-starter-security

artifactid

>

dependency

>

在配置檔案中為spring security設定乙個安全使用者

spring:

security:

user: # 配置安全使用者

name: admin

password: 123456

health端點是檢視spring boot應用程式健康狀況的端點,如果沒有特殊設定,顯示的資訊就比較少

可以通過在配置檔案中設定management.endpoint.health.show-details來決定health端點的細節資訊是否展示。以下為health端點的細節屬性。

• never:細節資訊詳情永遠都不展示。

• when-authorized:細節詳情只對授權使用者顯示。

• always:細節詳情顯示給所有使用者。

management:

endpoint:

health:

show-details: always #health端點的細節屬性是否展示

健康資訊的內容是從healthindicators中收集應用程式中定義的所有bean中的上下文資訊,其中包含一些自動配置的healthindicators,也可以編寫自己的健康資訊bean。spring boot缺省會自動配置以下healthindicators。

• cassandrahealthindicator:檢查cassandra資料庫是否已啟動。

• diskspacehealthindicator:檢查磁碟空間是否不足。

• datasourcehealthindicator:檢查是否可以獲得連線的datasource。

• elasticsearchhealthindicator:檢查elasticsearch集群是否已啟動。

• influxdbhealthindicator:檢查influxdb伺服器是否已啟動。

• jmshealthindicator:檢查jms**是否已啟動。

• mailhealthindicator:檢查郵件伺服器是否已啟動。

• mongohealthindicator:檢查mongo資料庫是否已啟動。

• neo4jhealthindicator:檢查neo4j資料庫是否已啟動。

• rabbithealthindicator:檢查rabbit伺服器是否已啟動。

• redishealthindicator:檢查redis伺服器是否已啟動。

• solrhealthindicator:檢查solr伺服器是否已啟動。

import

org.springframework.beans.factory.annotation.value;

import

org.springframework.boot.actuate.health.health;

import

org.springframework.boot.actuate.health.healthindicator;

import

org.springframework.stereotype.component;

/*** 自定義健康狀況資訊

info: # 公開自定義info資訊

參考:spring boot 2實戰之旅-8.1 使用actuator監控

ACT 動作遊戲

動作遊戲是一種廣義上的遊戲型別。以 動作 作為遊戲主要表現形式的遊戲即可算作動作遊戲,動作遊戲也包含 射擊遊戲 和 格鬥遊戲 2005年後,單純的動作遊戲已較為罕見,因為 動作 都由各種不同的形式來表現。具有關卡設計的橫版過關遊戲可以稱其為動作遊戲,目前動作遊戲均指傳統的過關式動作遊戲,或不強調 射...

ACT完善與修改測試

大多數情況下,一次測試執行無法提供足夠的資訊來回答有關 web 應用程式的所有問題。請檢查 acttrace.log 檔案和報告,並確保不存在以下錯誤 如有必要,請在重新執行測試之前改正其中的錯誤。無效的 url 將導致 web 伺服器返回錯誤響應 並關閉 http 連線,降低 web 應用程式的效...

ACT完善與修改測試

大多數情況下,一次測試執行無法提供足夠的資訊來回答有關 web 應用程式的所有問題。請檢查 acttrace.log 檔案和報告,並確保不存在以下錯誤 如有必要,請在重新執行測試之前改正其中的錯誤。無效的 url 將導致 web 伺服器返回錯誤響應 並關閉 http 連線,降低 web 應用程式的效...