0Pricing
Spring Boot 4 Microservices & REST APIs · Lekcja

Wskaźniki stanu

Raportuj stan aplikacji i jej zależności

Wskaźniki stanu to bezpłatna lekcja Spring Boot 4 Microservices & REST APIs na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Spring Boot 4 Microservices & REST APIs, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Spring Boot 4 Microservices & REST APIs zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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 / never

Detailed 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 /readiness

Health 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,paymentApi

Tuning 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/health aggregates many indicators
  • Built-in indicators cover common dependencies
  • Implement HealthIndicator for custom checks
  • Use show-details wisely; names strip the suffix
  • Enable liveness/readiness probes and groups for Kubernetes

Często zadawane pytania

Czy lekcja „Wskaźniki stanu” jest bezpłatna?

Tak — pełny tekst „Wskaźniki stanu” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Spring Boot 4 Microservices & REST APIs, przejdź na CoddyKit PRO. Kurs Spring Boot 4 Microservices & REST APIs zawiera 4 lekcji w sumie.

Co nauczysz się w „Wskaźniki stanu”?

Raportuj stan aplikacji i jej zależności Ćwiczysz Spring Boot 4 Microservices & REST APIs z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Spring Boot 4 Microservices & REST APIs?

Nie wymagamy żadnego doświadczenia. Spring Boot 4 Microservices & REST APIs w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Wskaźniki stanu”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Spring Boot 4 Microservices & REST APIs?

Tak. Każda lekcja Spring Boot 4 Microservices & REST APIs zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Włączanie endpointów Actuator
  2. Wskaźniki stanu
  3. Własne metryki z Micrometer
  4. Zabezpieczanie endpointów Actuator
← Powrót do Spring Boot 4 Microservices & REST APIs