DevNotes
Support
Spring Boot · Chapter 24

Spring Boot Actuator and Production Readiness

Health, info, metrics and operational endpoints, custom HealthIndicators, Micrometer with Prometheus and Grafana, loggers, dumps, graceful shutdown, liveness/readiness probes and securing endpoints.

◷ 7 min read§ 20 sections? 10 interview questions{ } 3 code examples

#Introduction

Writing a Spring Boot application is only half the job. In production you must answer questions like: Is my application healthy? Is the database reachable? How much memory is being used? Why is the application slow? Which API is failing? How many requests per second are coming in? Can Kubernetes restart my application? How do I monitor CPU, JVM and threads? How do I expose metrics to Prometheus?

These are solved by Spring Boot Actuator.

#What is Spring Boot Actuator?

Actuator provides production-ready features for monitoring and managing your application. It exposes information about application health, metrics, the JVM, threads, memory, the environment, beans, mappings, logging, HTTP requests and custom health checks. Think of it as the dashboard for your application.

#Why Do We Need Actuator?

Without Actuator
Application
Running? Don't know
With Actuator
Application
Health, metrics, logs
Monitoring
Alerts

Operations teams can immediately determine whether the application is functioning correctly.

#Dependency

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

Once added, Spring Boot automatically registers the actuator endpoints.

HTTP request
DispatcherServlet
Actuator endpoint
Health / metrics / info

#Actuator Endpoints

Interview favourite.

EndpointPurpose
/actuatorList available endpoints
/actuator/healthHealth status
/actuator/infoApplication information
/actuator/metricsMetrics
/actuator/prometheusPrometheus metrics
/actuator/envEnvironment properties
/actuator/beansSpring beans
/actuator/mappingsRequest mappings
/actuator/loggersLogger configuration
/actuator/threaddumpJVM thread dump
/actuator/heapdumpJVM heap dump
/actuator/cachesCache information
/actuator/configpropsConfiguration properties

Exposing Endpoints

Not every endpoint is exposed by default — over HTTP, only health is exposed out of the box.

Text
management.endpoints.web.exposure.include=health,info,metrics

Expose everything (not recommended for production):

Text
management.endpoints.web.exposure.include=*

#Health Endpoint

One of the most used endpoints:

Text
GET /actuator/health
JSON
{
  "status": "UP"
}

Health Contributors

Health is determined by multiple contributors — the application, database, disk space, Redis, RabbitMQ, Kafka, … If one critical dependency fails, the overall status changes accordingly (e.g. to DOWN).

  • Overall health
    • db
    • diskSpace
    • redis
    • rabbit
    • kafka

Common status values: UP, DOWN, OUT_OF_SERVICE and UNKNOWN.

Detailed Health

Text
management.endpoint.health.show-details=always
JSON
{
  "status": "UP",
  "components": {
    "db": { "status": "UP" },
    "diskSpace": { "status": "UP" }
  }
}

(The default is never; when-authorized is a safer choice than always.)

#Custom HealthIndicator

Interview favourite.

Java
@Component
public class PaymentHealthIndicator implements HealthIndicator {

    @Override
    public Health health() {
        boolean ok = checkGateway();

        if (ok) {
            return Health.up().build();
        }
        return Health.down()
                .withDetail("Gateway", "Unavailable")
                .build();
    }
}

Spring automatically adds it to /actuator/health (as the payment component).

#Info Endpoint

Text
GET /actuator/info
Text
management.info.env.enabled=true
info.app.name=Booking System
info.app.version=1.0.0
info.company=ABC Ltd
JSON
{
  "app": {
    "name": "Booking System",
    "version": "1.0.0"
  },
  "company": "ABC Ltd"
}

#Metrics Endpoint

One of the most powerful features:

Text
GET /actuator/metrics

It returns JVM memory, CPU, GC, HTTP requests, threads, Tomcat, database pool and cache statistics.

JVM Metrics

Text
/actuator/metrics/jvm.memory.used
JVM memory used
Micrometer
Actuator

HTTP Metrics

Text
/actuator/metrics/http.server.requests

Shows request count, response time, status codes and per-URI statistics. Very common in production.

#Micrometer

Interview favourite. Micrometer is Spring Boot's metrics library (a vendor-neutral facade, like SLF4J for metrics).

Application
Micrometer
Prometheus
Grafana
Micrometer collects, Prometheus stores, Grafana visualizes

Prometheus Integration

XML
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

Endpoint: /actuator/prometheus. Prometheus periodically scrapes this endpoint.

Grafana

Application
Actuator
Prometheus
Grafana dashboard

Operations teams monitor CPU, memory, JVM, database, requests and errors using Grafana dashboards.

#Other Operational Endpoints

/actuator/env

Shows active profiles, environment variables, system properties and configuration values. Useful for debugging — don't expose it publicly in production.

/actuator/beans

Shows every Spring bean. Useful during development and troubleshooting.

/actuator/mappings

Shows controllers, URLs and HTTP methods. Useful for debugging routing issues.

/actuator/loggers

Change log levels dynamically:

Text
POST /actuator/loggers/com.app
JSON
{
  "configuredLevel": "DEBUG"
}

No application restart required.

/actuator/threaddump

Useful for diagnosing deadlocks, high CPU, thread leaks and blocking threads.

/actuator/heapdump

Useful for memory leaks, OutOfMemoryError and object analysis. Typically analyzed with tools such as Eclipse MAT or VisualVM.

#Graceful Shutdown

Instead of terminating immediately, Spring Boot can finish active requests:

Text
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=30s
Shutdown signal
Stop accepting requests
Finish existing requests
Close resources
Shutdown

Very important in Kubernetes. (Graceful shutdown is the default since Spring Boot 3.4.)

#Liveness and Readiness Probes

Interview favourite.

Liveness answers "Is the application alive?" — /actuator/health/liveness. If liveness fails, Kubernetes restarts the container.

Readiness answers "Can the application receive traffic?" — /actuator/health/readiness. If readiness fails, traffic is temporarily stopped, but the application may keep running.

Kubernetes
Liveness OK?
Restart the container
Readiness OK?
Send traffic
Stop routing traffic

#Custom Metrics

Counter

Java
Counter counter = meterRegistry.counter("orders.created");

counter.increment();

Visible in /actuator/metrics.

Timer

Measure execution time:

Java
Timer timer = meterRegistry.timer("payment.time");

timer.record(() -> {
    processPayment();
});

Tags

Micrometer supports labels (tags) — e.g. payment.time with status=SUCCESS, country=IN. This enables filtering and aggregation in monitoring tools.

#Security

Never expose all endpoints publicly:

Text
management.endpoints.web.exposure.include=health,info

Protect sensitive endpoints using Spring Security (or a separate management.server.port reachable only internally).

#Production Monitoring Architecture

Spring Boot
Actuator
Micrometer
Prometheus
Grafana
Alerts

Internal Components

Important classes: HealthEndpoint, MetricsEndpoint, InfoEndpoint, HealthIndicator, MeterRegistry, Counter, Timer and Gauge.

HTTP request
Controller → business logic
Micrometer
Actuator
Prometheus
Grafana
Alertmanager
DevOps team
Complete production flow

#Common Mistakes

  • Exposing every endpoint (include=*) in production — expose only what's required.
  • Leaving health details public (show-details=always) — limit details to authenticated users or trusted environments.
  • Ignoring metrics — applications without monitoring are difficult to troubleshoot.
  • Not enabling graceful shutdown — an immediate shutdown can interrupt active requests.
  • Ignoring JVM metrics — memory leaks often show up first in heap usage, GC frequency and thread count.

#Enterprise Architecture

Client
Load balancer
Spring Boot — security, controllers, services, repositories
Database
Micrometer → Actuator
Prometheus
Grafana
Alerts

#Interview Questions

Q1What is Spring Boot Actuator?

A Spring Boot module that provides production-ready monitoring and management endpoints.

Q2Which endpoint checks application health?

/actuator/health.

Q3What is Micrometer?

Spring Boot's metrics instrumentation library. It records application metrics and exports them to monitoring systems such as Prometheus.

Q4Difference between Prometheus and Grafana?
PrometheusGrafana
Collects and stores metricsVisualizes metrics
Time-series databaseDashboards and alert visualization
Q5What is a HealthIndicator?

A component that contributes custom health information to the health endpoint.

Q6Difference between liveness and readiness?
LivenessReadiness
Is the application alive?Can it accept traffic?
Failure usually triggers a restartFailure removes it from traffic
Q7Which endpoint exposes Prometheus metrics?

/actuator/prometheus.

Q8Which Micrometer classes are commonly used?

MeterRegistry, Counter, Timer, Gauge and DistributionSummary.

Q9Why should Actuator endpoints be secured?

Because some endpoints expose sensitive operational information such as environment properties, bean definitions, mappings and heap dumps.

Q10What is graceful shutdown?

A shutdown where the application stops accepting new requests, completes in-flight requests, releases resources and then terminates.

#Key Takeaways

  • Actuator provides production-ready monitoring and management.
  • HealthIndicator adds custom health checks for external systems.
  • Micrometer is the metrics facade; it integrates with Prometheus and Grafana.
  • Liveness and readiness probes are critical for Kubernetes.
  • Protect sensitive endpoints and expose only what's necessary.
  • Graceful shutdown prevents interrupted requests during deployments.
  • Monitor JVM, request and custom business metrics continuously.