Actuator Endpoints

Adding Actuator

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

Actuator adds ready-made endpoints under /actuator that tell you whether the app is healthy and what it is doing. Only health is exposed over HTTP by default.

EndpointShows
/actuator/healthUP/DOWN, plus database, disk, Redis checks
/actuator/infoapp version, git commit, build time
/actuator/metricsJVM memory, CPU, HTTP request timings, pool usage
/actuator/prometheusall metrics in Prometheus format
/actuator/loggersview and change log levels at runtime
/actuator/env, /configpropsconfiguration (values are masked)
/actuator/threaddump, /heapdumpdebugging stuck or leaking apps

Configuring Exposure

Example

application.yml

management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics,prometheus,loggers
  endpoint:
    health:
      show-details: when-authorized
      probes:
        enabled: true          # /actuator/health/liveness and /readiness
  info:
    git:
      mode: simple
  server:
    port: 8081               # keep actuator off the public port

Example

curl -s localhost:8081/actuator/health

Example output

{"status":"UP","components":{"db":{"status":"UP","details":{"database":"MySQL","validationQuery":"isValid()"}},"diskSpace":{"status":"UP"},"livenessState":{"status":"UP"},"ping":{"status":"UP"},"readinessState":{"status":"UP"},"redis":{"status":"UP","details":{"version":"7.2.4"}}}}

Note: Never expose env, heapdump or shutdown publicly. Run actuator on a separate management port, or protect it with Spring Security (role ACTUATOR).

Changing Log Level Without Restart

Example

curl -X POST localhost:8081/actuator/loggers/com.shopease.payment \
  -H "Content-Type: application/json" -d '{"configuredLevel":"DEBUG"}'
curl -s localhost:8081/actuator/loggers/com.shopease.payment

Example output

HTTP/1.1 204 No Content
{"configuredLevel":"DEBUG","effectiveLevel":"DEBUG"}