CloudWatch Metrics and Alarms for Spring Boot
Fast recall
Quick revision
Core answer
Observability practices for production Java applications on AWS
Relying only on infrastructure-level metrics (CPU, memory) without publishing application-level metrics like request latency, error rates, and business events
Mention Micrometer's dimensional metrics model, structured logging with logback and JSON format for CloudWatch Logs Insights querying, and composite alarms
Interview-ready guide
Interview answer
Spring Boot's Micrometer integration publishes metrics to CloudWatch automatically — which means every service gets CPU, memory, HTTP latency, and JVM metrics in CloudWatch without writing any CloudWatch SDK code.
Publishing metrics from Spring Boot
- Add
micrometer-registry-cloudwatch2to the dependencies and configuremanagement.metrics.export.cloudwatch.namespace— Micrometer pushes all registered metrics to CloudWatch in the configured namespace every 60 seconds - Spring Boot auto-configures JVM metrics (GC pauses, heap usage, thread count), HTTP request metrics (latency, count, error rate), and HikariCP pool metrics — these appear in CloudWatch without any custom code
Custom metrics with Micrometer
Counter.builder("orders.placed").register(meterRegistry).increment()adds a custom counter;Timer.builder("payment.processing").register(meterRegistry).record(duration)records timing- Tag metrics with dimensions like
service,env, andregion— which means CloudWatch dashboards can filter and group by service or environment without creating separate metric namespaces
CloudWatch Alarms
- Define alarms on metrics with thresholds:
HTTPServerRequests{status=5xx}above 1% of total requests;jvm.memory.usedabove 80% of max; P99 latency above 500ms - Alarms can trigger SNS notifications (which notifies PagerDuty or Slack via webhook), Auto Scaling policies (scale out when CPU > 70%), or Lambda functions for automated remediation
CloudWatch Logs Insights
- Spring Boot JSON logs shipped to CloudWatch Logs can be queried with Logs Insights —
fields @timestamp, level, message | filter level = "ERROR" | stats count() by bin(5m)counts errors per 5-minute window, useful for correlating spikes in logs with metric alarms
CloudWatch Metrics and Alarms for Spring Boot
Direct Answer
Spring Boot publishes metrics via Micrometer; the Micrometer CloudWatch registry pushes those metrics to CloudWatch. You then create CloudWatch Alarms on those metrics (e.g., high error rate, slow response time) that trigger SNS notifications or Auto Scaling actions. Application logs go to CloudWatch Logs via the awslogs Docker logging driver or the CloudWatch agent.
Common Mistakes & Pitfalls
Relying only on infrastructure-level metrics (CPU, memory) without publishing application-level metrics like request latency, error rates, and business events
Check your understanding
Answer these without looking back at the article.
- How do you use CloudWatch Logs Insights to query application errors across multiple ECS tasks?
- What is the difference between CloudWatch metrics and CloudWatch embedded metrics format (EMF)?
- How would you set up a CloudWatch dashboard to visualise your Spring Boot application's health?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.