Spring Boot Actuatorヘルスチェック形式
コンポーネントインジケーター、グループ化されたヘルスチェック、show-details設定を含むSpring Boot Actuator規約に従ったヘルスチェックレスポンスを設計します。
Patterns
詳細な説明
Spring Boot Actuatorヘルス形式
Spring Boot Actuatorは、Java/Springアプリケーションにおけるヘルスエンドポイントのデファクトスタンダードです。その形式を理解することは、あらゆるフレームワークでヘルスチェックを設計する際に役立ちます。
標準Actuatorレスポンス
{
"status": "UP",
"components": {
"db": {
"status": "UP",
"details": {
"database": "PostgreSQL",
"validationQuery": "isValid()"
}
},
"diskSpace": {
"status": "UP",
"details": {
"total": 107374182400,
"free": 68719476736,
"threshold": 10485760
}
}
},
"groups": ["liveness", "readiness"]
}
ヘルスグループ(Spring Boot 2.3+)
// GET /actuator/health/liveness
{ "status": "UP" }
// GET /actuator/health/readiness
{
"status": "UP",
"components": {
"db": { "status": "UP" },
"redis": { "status": "UP" }
}
}
Show Detailsレベル
| レベル | 効果 |
|---|---|
never |
statusフィールドのみ |
when_authorized |
認証ユーザーに詳細を表示 |
always |
全員に完全な詳細を表示 |
カスタムヘルスインジケーター
Actuatorでは、カスタムチェック用にHealthIndicatorインターフェースを実装します。各インジケーターは同じUP/DOWN/OUT_OF_SERVICE/UNKNOWNセマンティクスを使用して全体ステータスに寄与します。このパターンはSpring以外のフレームワークでも再現する価値があります。
ユースケース
Actuatorを使用するJava/Spring Bootアプリケーション、またはSpringベースの監視ツールとの相互運用性のために確立されたActuatorヘルスチェック規約に従いたいフレームワーク。