Spring Boot services · Chapter 36 of 41

Actuator

By the end of this chapter you can open just the operations endpoints you choose, add your own health check and metric, and say which checks belong in a liveness probe. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Production
  • 6 tasks
  • Spring Boot
  • In the all labs plan

The first 2 chapters of Spring Boot services are free. This one comes with the all labs plan.

Why you need this

Tapri Cloud now runs in containers on the railway's cluster, and the platform team has questions. Is it alive? Is it ready for traffic? Which version runs at New Delhi? Ravi has one of his own: when the kitchen printer at Bengaluru jams, orders still arrive but nobody makes them, and nothing tells anyone.

With what you know so far, you would write a controller for each question, in a format of your own that no load balancer, cluster or dashboard understands, and you would have to remember to keep it private.

What you build: 6 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    application.properties: expose health, info and metrics, and nothing more

    Expose exactly the health, info and metrics endpoints over HTTP: GET /actuator/health answers 200 with status UP, GET /actuator/info answers 200, GET /actuator/metrics answers 200 with a names list, and GET /actuator/env and GET /actuator/beans still answer 404.

  2. Task 2

    application.properties: show the details of every health check

    Make GET /actuator/health list every component with its status and details: diskSpace is UP with a number at details.free, and ping is UP.

  3. Task 3

    KitchenPrinterHealthIndicator.java: report the kitchen printer's health

    Write KitchenPrinterHealthIndicator.health() so the kitchenPrinter component is UP with a paperLeft detail (the printer's paper left, 35 say) while the printer is online, and DOWN with an error detail of "Printer offline" when it is not. With the printer offline, GET /actuator/health answers 503 with overall status DOWN. Needs task 2, to see the component.

  4. Task 4

    application.properties: describe the app at /actuator/info

    Make GET /actuator/info answer 200 with {"app":{"name":"Tapri Cloud","version":"4.2.0"}}, from two properties: info.app.name is Tapri Cloud and info.app.version is 4.2.0. Needs task 1.

  5. Task 5

    OrderService.java: count orders per station with a Micrometer counter

    Make OrderService.place(station, total) count each order in a Micrometer counter named tapri.orders with a station tag (SBC, NDLS, ...), and still return the order number. After three orders at KYN and one at PUNE, GET /actuator/metrics/tapri.orders?tag=station:KYN shows a COUNT of 3.0, and with tag station:PUNE, 1.0. Needs task 1.

  6. Task 6 · interview question

    Interview: keep a broken printer from failing the liveness probe

    With the printer offline, GET /actuator/health answers 503 (task 3), while GET /actuator/health/liveness and GET /actuator/health/readiness both answer 200 with status UP. Switch the probe groups on explicitly with management.endpoint.health.probes.enabled=true (Spring Boot 4 already does by default), and add the printer to neither group. Needs task 3.

    Be ready to explain why a jammed printer must not fail the liveness probe.

What you will learn

  • Endpoints and exposure: what Actuator offers, and what you open over HTTP.
  • Health: components, their details, and your own HealthIndicator.
  • Liveness and readiness: two different questions (the interview question).
  • Info and metrics: describing the app, and counting with Micrometer.

More in Production

Build "Actuator" yourself

Tapri Cloud: the counters’ Java grows into a Spring Boot service with a database. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Spring Boot services are free. This one comes with the all labs plan.