AWS Observability Concepts
The 3 Pillars of Observability
┌─────────────────────────────────────────────────────────────┐
│ THE 3 PILLARS │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ METRICS LOGS TRACES │ │
│ │ ─────── ──── ────── │ │
│ │ │ │
│ │ What? Why? How? │ │
│ │ │ │
│ │ CPU: 80% ERROR: Request A │ │
│ │ Requests: 1000 Connection → Service 1 │ │
│ │ Errors: 5% failed to DB → Service 2 │ │
│ │ → Database │ │
│ │ │ │
│ │ CloudWatch CloudWatch X-Ray │ │
│ │ Metrics Logs │ │
│ │ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ Together, they answer: │
│ • What is happening? (Metrics) │
│ • Why is it happening? (Logs) │
│ • Where is it happening? (Traces) │
│ │
└─────────────────────────────────────────────────────────────┘
CloudWatch Metrics
Native EC2 Metrics
┌─────────────────────────────────────────────────────────────┐
│ NATIVE EC2 METRICS │
├─────────────────────────────────────────────────────────────┤
│ │
│ METRIC DESCRIPTION UNIT │
│ ─────── ─────────── ───── │
│ │
│ CPUUtilization CPU Usage % │
│ NetworkIn Incoming Traffic Bytes │
│ NetworkOut Outgoing Traffic Bytes │
│ DiskReadBytes Disk Read Bytes │
│ DiskWriteBytes Disk Write Bytes │
│ DiskReadOps Read Operations Count │
│ DiskWriteOps Write Operations Count │
│ StatusCheckFailed Health Check Failed Count │
│ │
│ ⚠️ WARNING: │
│ Memory (RAM) is NOT included by default! │
│ → Requires CloudWatch Agent │
│ │
└─────────────────────────────────────────────────────────────┘
CloudWatch Agent (Advanced Metrics)
┌─────────────────────────────────────────────────────────────┐
│ CLOUDWATCH AGENT │
├─────────────────────────────────────────────────────────────┤
│ │
│ The CloudWatch agent collects additional metrics │
│ from inside the instance: │
│ │
│ ADDITIONAL METRICS: │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ • mem_used_percent : RAM Usage (%) │ │
│ │ • disk_used_percent : Disk Usage (%) │ │
│ │ • processes_total : Number of Processes │ │
│ │ • cpu_usage_user : User CPU │ │
│ │ • cpu_usage_system : System CPU │ │
│ │ • netstat_tcp_established : TCP Connections │ │
│ │ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ INSTALLATION: │
│ 1. Install the agent on the instance │
│ 2. Configure the metrics to collect │
│ 3. Attach an IAM role with permissions │
│ │
│ # Installation on Amazon Linux 2 │
│ sudo yum install amazon-cloudwatch-agent │
│ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon- │
│ cloudwatch-agent-config-wizard │
│ sudo systemctl start amazon-cloudwatch-agent │
│ │
└─────────────────────────────────────────────────────────────┘
CloudWatch Alarms
Alarm Types
┌─────────────────────────────────────────────────────────────┐
│ CLOUDWATCH ALARMS │
├─────────────────────────────────────────────────────────────┤
│ │
│ ALARM STATES: │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ OK → Metric is within limits │ │
│ │ ALARM → Metric has exceeded the threshold │ │
│ │ INSUFFICIENT_DATA → Not enough data │ │
│ │ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ALARM COMPONENTS: │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 1. Metric: CPUUtilization │ │
│ │ 2. Statistic: Average │ │
│ │ 3. Period: 300 seconds (5 min) │ │
│ │ 4. Evaluation: 2 periods │ │
│ │ 5. Threshold: > 80% │ │
│ │ 6. Action: Notify SNS │ │
│ │ │ │
│ │ Translation: │ │
│ │ "If average CPU > 80% for 2 periods of 5 min, │ │
│ │ then trigger the alarm and notify SNS" │ │
│ │ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
CLI Configuration
# Create a high CPU alarm
aws cloudwatch put-metric-alarm \
--alarm-name cpu-high-alarm \
--metric-name CPUUtilization \
--namespace AWS/EC2 \
--statistic Average \
--period 300 \
--threshold 80 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 2 \
--dimensions Name=InstanceId,Value=i-xxx \
--alarm-actions arn:aws:sns:us-east-1:123456789:alerts \
--alarm-description "CPU above 80% for 10 minutes"
# Create a memory alarm (requires CloudWatch Agent)
aws cloudwatch put-metric-alarm \
--alarm-name mem-high-alarm \
--metric-name mem_used_percent \
--namespace CWAgent \
--statistic Average \
--period 300 \
--threshold 90 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 2 \
--dimensions Name=InstanceId,Value=i-xxx \
--alarm-actions arn:aws:sns:us-east-1:123456789:alerts
CloudWatch Logs
Log Structure
┌─────────────────────────────────────────────────────────────┐
│ CLOUDWATCH LOGS STRUCTURE │
├─────────────────────────────────────────────────────────────┤
│ │
│ LOG GROUP (container) │
│ └── /aws/ec2/my-app │
│ │ │
│ ├── LOG STREAM (source stream) │
│ │ └── i-xxx/application.log │
│ │ │ │
│ │ ├── LOG EVENT (individual entry) │
│ │ │ └── 2024-01-15 10:30:00 INFO User login │
│ │ │ │
│ │ └── LOG EVENT │
│ │ └── 2024-01-15 10:30:01 ERROR DB timeout │
│ │ │
│ └── LOG STREAM │
│ └── i-yyy/application.log │
│ │
│ RETENTION: │
│ • Configurable: 1 day to 10 years (or never) │
│ • Default: never (beware of costs!) │
│ │
└─────────────────────────────────────────────────────────────┘
Log Insights (Queries)
┌─────────────────────────────────────────────────────────────┐
│ CLOUDWATCH LOG INSIGHTS │
├─────────────────────────────────────────────────────────────┤
│ │
│ Query language for log analysis: │
│ │
│ # Search for errors │
│ fields @timestamp, @message │
│ | filter @message like /ERROR/ │
│ | sort @timestamp desc │
│ | limit 100 │
│ │
│ # Count errors per hour │
│ fields @timestamp, @message │
│ | filter @message like /ERROR/ │
│ | stats count() by bin(1h) │
│ │
│ # Top 10 IPs with errors │
│ fields @timestamp, @message │
│ | filter @message like /ERROR/ │
│ | parse @message /IP: (?<ip>\d+\.\d+\.\d+\.\d+)/ │
│ | stats count() by ip │
│ | sort count desc │
│ | limit 10 │
│ │
│ # Latency P99 │
│ fields @timestamp, latency │
│ | stats percentile(latency, 99) as p99 │
│ │
└─────────────────────────────────────────────────────────────┘
CloudWatch Dashboards
┌─────────────────────────────────────────────────────────────┐
│ CLOUDWATCH DASHBOARD │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ PRODUCTION DASHBOARD 🔄 │ │
│ ├─────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ ┌─────────────────┐ ┌─────────────────┐ │ │
│ │ │ CPU Usage │ │ Memory Usage │ │ │
│ │ │ ████████░░ 80% │ │ ██████░░░░ 60% │ │ │
│ │ │ [graph] │ │ [graph] │ │ │
│ │ └─────────────────┘ └─────────────────┘ │ │
│ │ │ │
│ │ ┌─────────────────┐ ┌─────────────────┐ │ │
│ │ │ Request Count │ │ Error Rate │ │ │
│ │ │ 1,234 req/min │ │ 0.5% │ │ │
│ │ │ [graph] │ │ [graph] │ │ │
│ │ └─────────────────┘ └─────────────────┘ │ │
│ │ │ │
│ │ ┌───────────────────────────────────────┐ │ │
│ │ │ Latency P50/P95/P99 │ │ │
│ │ │ [line chart over time] │ │ │
│ │ └───────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ WIDGET TYPES: │
│ • Line: Trends over time │
│ • Stacked: Component comparison │
│ • Number: Single value (KPI) │
│ • Text: Documentation, links │
│ • Alarm Status: Alarm states │
│ • Logs: Latest events │
│ │
└─────────────────────────────────────────────────────────────┘
Incident Runbook
┌─────────────────────────────────────────────────────────────┐
│ RUNBOOK TYPE │
├─────────────────────────────────────────────────────────────┤
│ │
│ INCIDENT: High CPU (> 90%) │
│ ───────────────────────── │
│ │
│ 1. ASSESS SEVERITY │
│ □ One instance or multiple? │
│ □ Visible user impact? │
│ □ Errors in logs? │
│ │
│ 2. QUICK DIAGNOSTIC │
│ □ top -c on the instance │
│ □ Identify consuming process │
│ □ Check application logs │
│ │
│ 3. IMMEDIATE ACTIONS │
│ □ If legitimate load → Scale out (add instances) │
│ □ If rogue process → Restart the service │
│ □ If attack → Block source IP │
│ │
│ 4. RESOLUTION │
│ □ CPU back < 70%? │
│ □ Service operational? │
│ □ Impacted users informed? │
│ │
│ 5. POST-MORTEM │
│ □ Document the cause │
│ □ Preventive actions │
│ □ Improve alerts │
│ │
└─────────────────────────────────────────────────────────────┘
Summary
| Service | Usage | Data |
|---|---|---|
| Metrics | Real-time monitoring | CPU, RAM, Network |
| Alarms | Automatic alerts | Thresholds exceeded |
| Logs | Debugging, audit | Application text |
| Dashboards | Visualization | Graphs, KPIs |
| Log Insights | Analysis | Log queries |
Next section: Lab Monitoring