❤️ What is a Health Check & Metrics In Spring Boot?

A Health Check is a simple way to verify if your Spring Boot application and its components (like database, disk, etc.) are running properly.

Think of it like a regular doctor check-up — just for your app.

✅ How to Enable Health Checks?

  1. Add the Actuator dependency in pom.xml:

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

  1. Add this to application.properties:

management.endpoints.web.exposure.include=health,info
  1. Access the health check at:

http://localhost:8080/actuator/health

You’ll get a response like:

{
  "status": "UP"
}

📊 What are Metrics?

Metrics give detailed performance data of your app — memory usage, CPU, active threads, request counts, etc.

Think of it like a dashboard that shows how healthy and efficient your app is.

 

✅ Enable Metrics Endpoint

Update application.properties:

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

Then visit:

http://localhost:8080/actuator/metrics

Example metric:

http://localhost:8080/actuator/metrics/jvm.memory.used

You’ll get data like:

{
  "name": "jvm.memory.used",
  "measurements": [
    { "value": 17260000.0 }
  ],
  "availableTags": [...]
}

🧰 Common Metrics You Can Track

  • jvm.memory.used – RAM usage
  • system.cpu.usage – CPU load
  • http.server.requests – Request count
  • process.uptime – Uptime in seconds

🚀 Why Use Health & Metrics?

  • Useful for monitoring tools like Prometheus, Grafana, AWS CloudWatch
  • Helps DevOps know if app is healthy
  • Prevents unexpected downtimes
  • Alerts when performance drops

Back to blog

Leave a comment