Actuator is like adding a health monitoring system to your Spring Boot app. It gives you real-time metrics, health checks, and other operational info — all via HTTP endpoints like:
http://localhost:8080/actuator/metrics
🎯 Why Is It Useful for Microservices?
Imagine you have 10 microservices running. You need to answer:
- Is my app healthy?
- Are the APIs responding fast?
- Is the memory usage too high?
- Are the DB connections overloaded?
👉 Actuator gives you these answers out-of-the-box.
🔍 What Metrics Does Actuator Provide?
Let’s explore the main types of metrics you’ll find useful for monitoring:
1. 🧠 JVM Metrics (Java Virtual Machine)
These tell you how your app is using memory, threads, and classes.
Metric | What It Tells You | Example |
---|---|---|
jvm.memory.used |
How much memory is used by your app | 128 MB |
jvm.memory.max |
The max memory your app can use | 512 MB |
jvm.threads.live |
How many threads are running | 100 |
jvm.classes.loaded |
Number of classes loaded into memory | 10,000 |
💡 Why care? If memory or thread usage spikes too much, your app could crash.
2. 🖥️ CPU & System Metrics
Metric | What It Tells You | Example |
---|---|---|
system.cpu.usage |
Total CPU usage (system-wide) | 0.60 (60%) |
process.cpu.usage |
CPU used by your app only | 0.20 (20%) |
system.cpu.count |
Number of processor cores | 8 |
process.uptime |
How long the app has been running | 4 hours |
💡 Why care? High CPU usage may slow down your APIs.
3. 🌐 HTTP Request Metrics
Metric | What It Tells You | Example |
---|---|---|
http.server.requests |
Number of API calls + response time | 500 calls, avg 120ms |
→ Tags: uri , method , status
|
Helps slice metrics per API route |
/login , POST , 200 OK
|
💡 Why care? You can find slow endpoints or too many errors (e.g. 500s).
4. 💽 Database (HikariCP) Metrics
If using a database connection pool (like HikariCP):
Metric | What It Tells You | Example |
---|---|---|
hikaricp.connections.active |
Number of DB connections in use | 5 |
hikaricp.connections.idle |
Available connections in pool | 10 |
hikaricp.connections.max |
Maximum allowed connections | 20 |
💡 Why care? If all DB connections are used, your app can freeze or slow down.
5. 📦 Cache Metrics
If you use caching (like Caffeine, Redis, etc.):
Metric | What It Tells You | Example |
---|---|---|
cache.gets |
How many times you read from the cache | 1000 hits |
cache.misses |
How many times data wasn't in cache | 200 misses |
cache.puts |
How many times you added to cache | 300 puts |
💡 Why care? Too many cache misses = your DB is doing extra work.
6. 💓 Health Endpoint
Shows status of your app and its dependencies (DB, disk, etc.).
📍 Endpoint:
http://localhost:8080/actuator/health
Example output:
{
"status": "UP",
"components": {
"db": { "status": "UP" },
"diskSpace": { "status": "UP" }
}
}
💡 Helps monitoring tools like Prometheus, Grafana, or Kubernetes to know if your service is healthy.
7. 📈 Custom Metrics (Optional but Powerful)
You can define your own metrics like:
meterRegistry.counter("orders.placed").increment();
meterRegistry.gauge("temperature", () -> getRoomTemp());
💡 Used to track business logic (e.g., number of signups, order volume).
⚙️ How to Enable Actuator Metrics
- Add the dependency:
org.springframework.boot
spring-boot-starter-actuator
- In
application.properties
:
management.endpoints.web.exposure.include=*
- For Prometheus/Grafana:
io.micrometer
micrometer-registry-prometheus
Then hit:
http://localhost:8080/actuator/prometheus
🧪 Use Case: Example for Microservice Monitoring
Let’s say you have a payment microservice:
-
/actuator/health
: Used by Kubernetes for health checks. -
/actuator/metrics
: View API performance, DB usage. -
http.server.requests
: See if/pay
API is slow. -
hikaricp.connections.active
: Monitor DB pool overload. -
orders.placed
: Track how many payments succeeded.
Would you like a dashboard setup in Grafana, or a custom Prometheus config example to visualize these metrics?