AI Hints
Home›Spring Boot Tutorial›Actuator, Health and Info and Packaging a Jar
Spring Boot · Lesson 109 of 120

Actuator

Health and metrics.

⏱ 2 min read▶ Video at 2:24:34🎓 Free
Watch this lesson in the Spring Boot courseWatch on YouTube ↗Full Spring Boot course

Once your API is running in production, you need to know, is it up? Is it healthy? How busy is it? Spring Boot Actuator answers these questions, with ready made endpoints.

  • Is it up?
  • Is it healthy?
  • Actuator answers

What Actuator adds

Actuator adds endpoints, under slash actuator. Health says whether the app is up. Info describes the app. And metrics count things, like requests, and memory. Monitoring tools call these endpoints, every few seconds.

keyvalue
Endpoints/actuator/...
healthis it up?
infowhat is this app?
metricsrequests, memory, threads

One dependency

Actuator is one starter, in pom dot xml. Add it, and the endpoints appear. No code needed.

pom.xmlxml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Health out of the box

Our app has one small controller, and Actuator on the class path. We call health first. Then we try info, and metrics. Run it. Health says UP. But info, and metrics, give four oh four. They're hidden, because only health is exposed by default.

BookController.javajava
@RestController
public class BookController {

    @GetMapping("/books")
    public String books() { return "Book list"; }
}
Output
$ curl localhost:8080/actuator/health
{"groups":["liveness","readiness"],"status":"UP"}
$ curl -i localhost:8080/actuator/info | head -1
HTTP/1.1 404
$ curl -i localhost:8080/actuator/metrics | head -1
HTTP/1.1 404
Also uses _curl.sh
curl localhost:8080/actuator/health
curl -i localhost:8080/actuator/info | head -1
curl -i localhost:8080/actuator/metrics | head -1

Safe by default

Some endpoints show sensitive things, like settings, and environment variables. So over the web, only health is exposed by default. You choose what else to expose, with one property. Never expose everything on a public server.

keyvalue
Defaultonly /actuator/health
Sensitiveenv, beans, heapdump
You chooseexposure.include
Neverexpose * in public

Exposing more endpoints

This property exposes health, info, and metrics. Nothing else. Run it. Metrics shows the number of live threads in the app. And env is still hidden, because we didn't include it.

application.propertiesini
management.endpoints.web.exposure.include=health,info,metrics
Output
$ curl localhost:8080/actuator/metrics/jvm.threads.live
{
  "availableTags":[],
  "baseUnit":"threads",
  "description":"The current number of live threads including both daemon and non-daemon
  threads",
  "measurements":[{"statistic":"VALUE","value":23.0}],
  "name":"jvm.threads.live"
}
$ curl -i localhost:8080/actuator/env | head -1
HTTP/1.1 404
Also uses BookController.java
@RestController
public class BookController {

    @GetMapping("/books")
    public String books() { return "Book list"; }
}
Also uses _curl.sh
curl localhost:8080/actuator/metrics/jvm.threads.live
curl -i localhost:8080/actuator/env | head -1

Summary

Actuator adds health, info, and metrics endpoints. Only health is exposed by default, and you choose the rest. Next, health, and info, in more detail.

Key takeaways
  • /actuator/health
  • exposure.include
  • Safe by default
Next up: Health and Info — what is inside