ตัวบ่งชี้สุขภาพ
รายงานสถานะสุขภาพของแอปและส่วนพึ่งพา
ตัวบ่งชี้สุขภาพ เป็นบทเรียน Spring Boot 4 Microservices & REST APIs ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Spring Boot 4 Microservices & REST APIs และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Spring Boot 4 Microservices & REST APIs มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
The Health Endpoint
The /actuator/health endpoint reports whether the application and its dependencies are functioning. Load balancers and orchestrators poll it to decide if an instance should receive traffic.
GET /actuator/health
{ "status": "UP" }Aggregated Status
Overall health is an aggregate of many health indicators. If any critical indicator reports DOWN, the overall status becomes DOWN. Statuses include UP, DOWN, and OUT_OF_SERVICE.
Built-in Indicators
Boot auto-configures indicators for common dependencies — datasource, disk space, Redis, RabbitMQ, and others — whenever the corresponding starter is present. They contribute to the aggregate automatically.
Showing Health Details
By default details are hidden. Reveal per-component breakdowns with management.endpoint.health.show-details, ideally only to authenticated callers.
management:
endpoint:
health:
show-details: when-authorized
# or: always / neverDetailed Output
With details enabled, the response lists each component’s status and contributed data, making it easy to see which dependency is failing.
{
"status": "UP",
"components": {
"db": { "status": "UP", "details": { "database": "PostgreSQL" } },
"diskSpace": { "status": "UP" }
}
}A Custom HealthIndicator
Implement HealthIndicator to report on a dependency Boot does not cover — say, a downstream API. Return Health.up() or Health.down() with optional details.
@Component
public class PaymentApiHealthIndicator implements HealthIndicator {
private final PaymentClient client;
public PaymentApiHealthIndicator(PaymentClient client) { this.client = client; }
@Override
public Health health() {
return client.ping()
? Health.up().withDetail("latencyMs", client.lastLatency()).build()
: Health.down().withDetail("reason", "ping failed").build();
}
}Indicator Naming
The component name is derived from the bean/class name with the HealthIndicator suffix stripped. PaymentApiHealthIndicator appears as paymentApi in the output.
Liveness and Readiness Probes
In Kubernetes you distinguish liveness (is the app alive?) from readiness (can it serve traffic?). Boot exposes both as health groups when probes are enabled.
management:
endpoint:
health:
probes:
enabled: true
# exposes /actuator/health/liveness and /readinessHealth Groups
Group indicators under a named subset so probes only consider the relevant checks. Readiness might include the database; liveness usually should not, to avoid pod restarts on transient outages.
management:
endpoint:
health:
group:
readiness:
include: db,paymentApiTuning Status to HTTP Codes
Actuator maps health statuses to HTTP codes — UP to 200, DOWN to 503 by default — so infrastructure can act on the response code without parsing the body.
Designing Good Health Checks
Keep checks fast and meaningful:
- Probe real dependencies, not just process liveness
- Avoid heavy work that itself causes failures
- Separate liveness from readiness to prevent restart storms
Quick Check
Test your understanding of custom indicators.
Recap
Health endpoints signal operational status.
/actuator/healthaggregates many indicators- Built-in indicators cover common dependencies
- Implement
HealthIndicatorfor custom checks - Use
show-detailswisely; names strip the suffix - Enable liveness/readiness probes and groups for Kubernetes
คำถามที่พบบ่อย
บทเรียน “ตัวบ่งชี้สุขภาพ” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ตัวบ่งชี้สุขภาพ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Spring Boot 4 Microservices & REST APIs ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Spring Boot 4 Microservices & REST APIs มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ตัวบ่งชี้สุขภาพ”
รายงานสถานะสุขภาพของแอปและส่วนพึ่งพา คุณปฏิบัติ Spring Boot 4 Microservices & REST APIs ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Spring Boot 4 Microservices & REST APIs หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Spring Boot 4 Microservices & REST APIs บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “ตัวบ่งชี้สุขภาพ” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Spring Boot 4 Microservices & REST APIs นี้ได้ไหม
ได้ บทเรียน Spring Boot 4 Microservices & REST APIs ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การเปิดใช้ปลายทาง Actuator
- ตัวบ่งชี้สุขภาพ
- เมตริกแบบกำหนดเองด้วย Micrometer
- การรักษาความปลอดภัยปลายทาง Actuator