This post highlights key elements and structure of an AWS CloudWatch Dashboard tailored for your Java Spring Boot, PostgreSQL-based microservices running on EKS.
Introduction
Creating an AWS CloudWatch dashboard to monitor your Java Spring Boot microservices deployed in an AWS EKS cluster involves several steps. You need to collect relevant metrics from your microservices and EKS cluster, set up CloudWatch to gather these metrics, and then create a dashboard to visualize them.
Step 1: Enable Container Insights for EKS
- Container Insights for Amazon EKS helps you collect, aggregate, and visualize metrics and logs from your containerized applications and microservices.
- Follow AWS documentation to enable Container Insights for your EKS cluster.
Step 2: Collect Metrics from Spring Boot Microservices
Prometheus Exporter: Use the Micrometer library in your Spring Boot applications to expose metrics in a format that Prometheus can scrape.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
Configure your application.properties file to expose metrics
management.endpoints.web.exposure.include=prometheus
management.endpoint.prometheus.enabled=true
Deploy a Prometheus server in your EKS cluster to scrape these metrics and forward them to CloudWatch using the CloudWatch Prometheus integration.
Step 3: Set Up CloudWatch Agent for Custom Metrics:
- Install and configure the CloudWatch Agent on your EKS nodes to collect custom metrics from Prometheus.
- Configuration file for the CloudWatch Agent (
config.json): - Ensure the Prometheus configuration (
prometheus.yml) is set to scrape the metrics from your Spring Boot applications.
{
"agent": {
"metrics_collection_interval": 60,
"logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
},
"metrics": {
"namespace": "EKS/ContainerInsights",
"metrics_collected": {
"prometheus": {
"prometheus_config_path": "/etc/prometheus/prometheus.yml",
"log_group_name": "/aws/containerinsights/YOUR_CLUSTER_NAME/prometheus"
}
}
}
}
Step 4: Create a CloudWatch Dashboard:
- In the AWS Management Console, navigate to CloudWatch.
- Select Dashboards from the left-hand menu and click Create dashboard.
- Add widgets to your dashboard for each of the key metrics.
Dashboard Name: EKS Microservices Health and Performance Overview
- Overall Cluster Health:
- Metric: EKS Cluster Status (OK, Warning, Critical)
- Microservice Health (Per Service):
- Metric:
- Container Insights: RunningTaskCount (Number of running tasks/replicas)
- Custom Metrics (if available): HTTP Status Codes (200, 500, etc.)
- Application Load Balancer (if used): RequestCount, TargetResponseTime
- Pod Health and Resource Utilization:
- Metric:
- Container Insights: CPUUtilization, MemoryUtilization
- Kubernetes Metrics: PodStatus (Running, Pending, Failed)
- PostgreSQL Database Performance:
- Metric:
- RDS (if using RDS): DatabaseConnections, CPUUtilization, ReadIOPS, WriteIOPS, FreeableMemory
- Custom Metrics (if self-managed): Connections, ActiveQueries, Replication Lag
- API Gateway (if used):
- Metric:
- API Gateway: Count (Requests), Latency, 4XXError, 5XXError
- Logging and Errors:
- Metric:
- CloudWatch Logs Insights: Error Counts, Specific Error Messages
- Network Traffic:
- Metric:
- VPC Flow Logs: BytesTransferredIn, BytesTransferredOut
- Elastic Load Balancer: RequestCount
- Custom Business Metrics (Optional):
- Metric: User signups, orders placed, cart abandonment rate, etc.
Dashboard Layout:
- Top Row: Overall cluster health and key summaries (e.g., total active pods, running tasks).
- Middle Rows: Microservice-specific health, grouped logically (e.g., by business domain).
- Bottom Rows: Database performance, API Gateway metrics, error logs, and network traffic.
- Side Panel: (Optional) List of microservices with links to their individual logs or detailed dashboards.
Alarm Configuration:
Set up CloudWatch alarms for critical metrics, such as:
- Microservice Health: Low task count, high error rates
- Database Performance: High CPU or memory utilization, long query times, replication lag
- API Gateway: High latency, high error rates
- Network Traffic: Unusual spikes or drops in traffic