Skip to main content

Overview

The Monitoring Module provides comprehensive observability for your Artos deployment using AWS CloudWatch. It creates centralized log aggregation, performance metrics, automated alerting, and visualization dashboards to help you monitor application health, diagnose issues, and maintain system reliability.

Key Features

  • Centralized Logging: Aggregated logs from all application components
  • Performance Metrics: CPU and memory utilization tracking
  • Automated Alerts: Proactive notifications for anomalies and threshold breaches
  • Visual Dashboards: Real-time insights into cluster and application health
  • Query Templates: Pre-configured CloudWatch Insights queries for common investigations
  • Event Tracking: Capture and respond to EKS cluster state changes

Core Components

1. CloudWatch Log Groups

Log groups provide centralized storage and organization for application logs from different components.

Application Log Group

Log Group Name: /aws/eks/{cluster_name}/application Purpose: Stores logs from the main Artos backend API server. Typical Log Contents:
  • HTTP request/response logs
  • Business logic execution traces
  • Error stack traces and exceptions
  • Database query logs
  • Authentication events
  • API performance metrics
Example Log Entry:

Celery Log Group

Log Group Name: /aws/eks/{cluster_name}/celery Purpose: Stores logs from Celery background workers processing asynchronous tasks. Typical Log Contents:
  • Task execution start/completion
  • Task failures and retries
  • Worker health status
  • Queue processing metrics
  • Long-running job progress
Example Log Entry:

Nginx Log Group

Log Group Name: /aws/eks/{cluster_name}/nginx Purpose: Stores logs from Nginx ingress controller or reverse proxy. Typical Log Contents:
  • HTTP access logs
  • Request routing decisions
  • SSL/TLS handshake events
  • Upstream connection errors
  • Rate limiting events
Example Log Entry:
Log Retention: All log groups use configurable retention periods to balance observability needs with storage considerations. Logs older than the retention period are automatically deleted. Log retention is set to the maximum allowed in cloudwatch.

2. CloudWatch Alarms

Alarms monitor metrics and automatically trigger notifications when thresholds are breached.

High CPU Alarm

Alarm Name: {cluster_name}-high-cpu Trigger Condition:
  • Metric: Average CPU Utilization
  • Threshold: > 80%
  • Evaluation: 2 consecutive periods of 5 minutes
  • Total duration: 10 minutes above threshold
What It Means: When CPU utilization exceeds 80% for 10 consecutive minutes, this alarm triggers. High CPU can indicate:
  • Increased application load requiring more compute capacity
  • CPU-intensive operations (AI model inference, data processing)
  • Inefficient code or infinite loops
  • Need to scale node groups or add more pods
Response Actions:
  1. Check CloudWatch metrics to identify which pods are consuming CPU
  2. Review application logs for unusual activity
  3. Consider horizontal scaling (more pod replicas) or vertical scaling (larger instance types)
  4. Investigate for potential performance bottlenecks

High Memory Alarm

Alarm Name: {cluster_name}-high-memory Trigger Condition:
  • Metric: Average Memory Utilization
  • Threshold: > 80%
  • Evaluation: 2 consecutive periods of 5 minutes
  • Total duration: 10 minutes above threshold
What It Means: When memory utilization exceeds 80% for 10 consecutive minutes, this alarm triggers. High memory usage can indicate:
  • Memory leaks in application code
  • Large dataset processing
  • Caching layers consuming excessive memory
  • Insufficient memory allocation for workloads
Response Actions:
  1. Identify memory-intensive pods using kubectl top pods
  2. Review application logs for memory errors or OOM events
  3. Analyze heap dumps if available
  4. Consider increasing memory limits or adding more nodes
  5. Investigate memory leaks or optimize data structures
Critical Threshold: If CPU or memory reaches 90%+, pods may be throttled or evicted, causing application instability. Consider setting additional alarms at 90% for critical alerts.

3. CloudWatch Dashboard

The dashboard provides a unified view of cluster metrics and application logs. Dashboard Name: {cluster_name}-dashboard Widgets:

EKS Cluster Metrics Widget

  • Type: Time series graph
  • Metrics: CPU and Memory Utilization
  • Period: 5 minutes
  • View: Line graph with both metrics overlaid
Use Cases:
  • Quick health check of cluster resource utilization
  • Identify trends and patterns over time
  • Correlate CPU/memory spikes with application events
  • Capacity planning insights

Application Logs Widget

  • Type: Log query table
  • Source: Application log group
  • Query: Latest 20 log entries, sorted by timestamp
  • Refresh: Auto-refresh every 1 minute
Use Cases:
  • Real-time log streaming for debugging
  • Immediate visibility into recent errors
  • Monitor application activity during deployments
  • Quick access to latest log events
Accessing the Dashboard: The dashboard URL is available as a Terraform output:

4. CloudWatch Insights Queries

Pre-configured query definitions for common log analysis tasks.

Error Logs Query

Query Name: {cluster_name}-error-logs Log Groups: Application and Celery Query:
Use Cases:
  • Quickly find all error messages across application and workers
  • Troubleshoot failures and exceptions
  • Identify error patterns and frequencies
  • Generate error reports for analysis
Running the Query:
  1. Navigate to CloudWatch Console → Insights
  2. Select the error-logs query definition
  3. Choose time range
  4. Click “Run query”

Performance Logs Query

Query Name: {cluster_name}-performance-logs Log Groups: Application Query:
Use Cases:
  • Identify slow API endpoints or database queries
  • Monitor performance degradation over time
  • Find operations exceeding performance SLAs
  • Prioritize optimization efforts
Custom Queries: You can create additional queries for specific needs: Count Errors by Type:
Request Duration Statistics:

5. SNS Topic for Alerts

The SNS (Simple Notification Service) topic distributes alarm notifications to configured endpoints. Topic Name: {cluster_name}-alerts Encryption: KMS-encrypted for security Subscribers: Configure email, SMS, HTTP/HTTPS endpoints, or Lambda functions to receive alerts. How It Works:
  1. CloudWatch alarm enters ALARM state
  2. Alarm publishes message to SNS topic
  3. SNS delivers notification to all subscribers
  4. Team members receive alerts via configured channels
Example Alert Message:
Adding Subscribers:
Integration Options:
  • Email: Direct email notifications
  • SMS: Text message alerts for critical events
  • Slack/Teams: Webhook integration for team channels
  • PagerDuty: Incident management system integration
  • Lambda: Custom processing and routing logic

6. CloudWatch Events (EventBridge)

Captures EKS cluster state change events for automated responses. Event Rule Name: {cluster_name}-events Event Pattern:
Captured Events:
  • Cluster creation or deletion
  • Cluster version updates
  • Node group scaling events
  • Add-on installation or updates
  • Cluster configuration changes
Event Target: SNS topic (alerts are sent to subscribers) Use Cases:
  • Automated notification of cluster changes
  • Audit trail for infrastructure modifications
  • Trigger automated workflows on cluster events
  • Compliance logging for change management
Example Event:

Module Configuration

Basic Configuration

Production Configuration with SNS Alerts

Development Configuration

Configuring Application Logging

Application Code Configuration

Configure your applications to send logs to CloudWatch Log Groups: Python (using watchtower):
Node.js (using winston-cloudwatch):

Kubernetes Configuration

Alternatively, use a log forwarder like Fluent Bit or Fluentd: Fluent Bit ConfigMap:

Accessing Monitoring Resources

CloudWatch Console

View Dashboard:
  1. Navigate to AWS Console → CloudWatch
  2. Select “Dashboards” from left menu
  3. Click on {cluster_name}-dashboard
Query Logs:
  1. Navigate to CloudWatch → Logs → Insights
  2. Select log groups to query
  3. Choose saved query or write custom query
  4. Adjust time range and run query
View Alarms:
  1. Navigate to CloudWatch → Alarms
  2. Filter by cluster name
  3. View alarm state and history

AWS CLI

Query Recent Logs:
Check Alarm Status:
Run Insights Query:

Best Practices

1. Structured Logging

Use structured (JSON) logging instead of plain text for better query capabilities: Good - Structured:
Avoid - Unstructured:

2. Log Levels

Use appropriate log levels to control verbosity:

3. Alarm Threshold Tuning

Adjust alarm thresholds based on your application’s normal behavior:
  • Start with conservative thresholds (80%)
  • Monitor false positive rate
  • Adjust based on actual capacity needs
  • Set multiple severity levels (warning at 70%, critical at 90%)

4. Dashboard Customization

Extend the default dashboard with application-specific metrics:

5. Log Sampling

For high-volume logs, consider sampling to reduce storage costs while maintaining visibility:

Module Maintenance: This module is compatible with Terraform 1.0+ and AWS Provider 5.x. CloudWatch Logs are retained according to configured retention periods and automatically deleted after expiration. Review retention settings periodically to balance observability needs with storage requirements.