4.1.5 Review Health with Dashboards & Insights

Review Application Health

CloudWatch Dashboards

  • Custom dashboards với metrics, logs, alarms
  • Cross-account, cross-region dashboards
  • Auto-refresh intervals
  • Share via URL (public or authenticated)
  • Single shared dashboard để monitor nhiều applications

Key Widgets

WidgetUse Case
Line graphMetrics over time (latency, errors)
NumberCurrent value (active connections)
Alarm statusHealth overview
Log insightsRecent errors, patterns
ExplorerDynamic resource discovery

CloudWatch ServiceLens

Amazon CloudWatch ServiceLens là tính năng trong CloudWatch giúp giám sát, chẩn đoán và phân tích ứng dụng phân tán bằng cách tập hợp metrics, logs và traces trong một giao diện duy nhất.

3 Pillars of Observability

ServiceLens tích hợp:

1. Metrics → Chỉ số hoạt động (latency, error rate)
2. Logs → Nhật ký ứng dụng, hệ thống
3. Traces → X-Ray traces theo dõi luồng request

Mục tiêu chính

a) Hiểu toàn bộ hệ thống

  • Nhìn đầy đủ: User → Application → Backend → Database
  • Thay vì rải rác theo từng silo dữ liệu

b) Service Map

  • Hiển thị bản đồ dịch vụ với nodes (resources) và edges (dependencies)
  • Cho thấy cách request di chuyển qua các components
Example Service Map:
User → API Gateway → Lambda → DynamoDB
                            → SQS → Lambda Worker

c) Tăng tốc Root Cause Analysis

Khi có vấn đề (latency tăng, error spike, timeout):

  • ✅ Xem trace để biết segment nào chậm
  • ✅ Xem logs để biết lỗi gì xảy ra
  • ✅ Xem metrics để biết thay đổi bất thường
  • ✅ Tất cả trong cùng một view

3 Góc nhìn cốt lõi

Góc nhìnMô tả
Infrastructure MonitoringXem metrics & logs để hiểu resources (EC2, Lambda, database)
Transaction MonitoringXem traces để hiểu request flow qua các components
End-User MonitoringTích hợp Synthetics canaries để theo dõi user experience

Service Map Features

Service Map hiển thị:
- Nodes: Services/Resources (Lambda, API Gateway, DynamoDB)
- Edges: Dependencies và request flow
- Health indicators: Green (OK), Yellow (warnings), Red (errors)
- Latency per service
- Error rates per node
- Request volume

Trace Details với Correlated Metrics

Khi click vào trace:
1. Request timeline
2. Subsegments breakdown
3. Correlated CloudWatch metrics
4. Related logs
5. Annotations và metadata

Lợi ích chính

Lợi íchChi tiết
Holistic ObservabilityKhông phải lật giữa metrics, logs, traces ở các tab khác nhau
Tăng tốc phân tíchGiảm thời gian tìm root cause, xác định phần bị lỗi nhanh hơn
Xác định tác động userXem ai bị ảnh hưởng và phần nào gây ra issue
Miễn phíServiceLens miễn phí, chỉ trả phí X-Ray traces, logs, metrics

Quan hệ với các dịch vụ AWS

Dịch vụMối liên hệ
AWS X-RayCung cấp trace data để hiển thị trong ServiceLens
CloudWatch LogsChứa logs phục vụ điều tra lỗi
CloudWatch MetricsHiển thị metrics và alarms
CloudWatch SyntheticsTheo dõi endpoint từ phía user, hiển thị anomalies

Khi nào dùng ServiceLens?

Ứng dụng microservices phân tánMôi trường serverless (Lambda, Fargate) ✅ Hệ thống phức tạp với nhiều dịch vụ liên kết ✅ DevOps/SRE teams muốn observability sâu

Setup Requirements

1. Enable X-Ray tracing:
   - Lambda: Tracing: Active
   - API Gateway: Stage settings
   - ECS: X-Ray daemon sidecar

2. Instrument application:
   - Use X-Ray SDK
   - patch_all() for auto-instrumentation

3. CloudWatch Logs:
   - Ensure logs are sent to CloudWatch

4. Access ServiceLens:
   - CloudWatch Console → ServiceLens

Example: Troubleshooting với ServiceLens

Scenario: API latency tăng đột ngột

1. Service Map:
   - Thấy Lambda node màu vàng (warnings)
   - Latency tăng từ 100ms → 2000ms

2. Click vào Lambda node:
   - Xem traces: 95% requests chậm ở DynamoDB call
   
3. Correlated metrics:
   - DynamoDB ThrottledRequests tăng
   
4. Related logs:
   - "ProvisionedThroughputExceededException"
   
5. Root cause: Hot partition trong DynamoDB
6. Solution: Better partition key design hoặc on-demand billing

CloudWatch Synthetics

Amazon CloudWatch Synthetics là dịch vụ AWS cho phép giám sát liên tục endpoints và APIs bằng canaries – scripts nhẹ chạy định kỳ để kiểm tra availability, latency, và user experience từ “ngoài vào”.

Canaries là gì?

Canary = script monitoring chạy theo schedule để:

  • Kiểm tra tính sẵn sàng (availability) của endpoints
  • Đo độ trễ (latency)
  • Thu thập screenshots (visual monitoring)
  • Phát hiện issues trước khi users gặp
  • Chạy 24/7 theo lịch (ví dụ: mỗi phút)

Dữ liệu thu thập

Data TypeMô tả
Load timeThời gian tải trang/API
ScreenshotsVisual monitoring, so sánh UI changes
LogsChi tiết execution logs
MetricsSuccessPercent, Duration, Failed

Tích hợp với ServiceLens

Kết quả phân tích tích hợp với CloudWatch ServiceLens để:

  • Theo dõi end-to-end application
  • Phân tích root cause analysis
  • Correlate với X-Ray traces
  • Debug anomalies trong distributed systems

Canary Types

TypeUse Case
HeartbeatMonitor endpoint availability
API CanaryTest REST APIs
Broken Link CheckerFind broken links on website
Visual MonitoringDetect UI changes
Canary RecorderRecord user actions, replay

Example: Create Canary

import boto3

client = boto3.client('synthetics')

response = client.create_canary(
    Name='api-health-check',
    Code={
        'Handler': 'apiCanaryBlueprint.handler',
        'S3Bucket': 'my-canary-scripts',
        'S3Key': 'canary.zip'
    },
    ArtifactS3Location='s3://my-canary-results/',
    ExecutionRoleArn='arn:aws:iam::123456789012:role/CanaryRole',
    Schedule={
        'Expression': 'rate(5 minutes)',  # Chạy mỗi 5 phút
        'DurationInSeconds': 0  # Chạy indefinitely
    },
    RuntimeVersion='syn-python-selenium-1.3',
    SuccessRetentionPeriodInDays=31,
    FailureRetentionPeriodInDays=31
)

Common API Actions

APIPurpose
CreateCanaryTạo canary monitoring
DeleteCanaryXóa canary
DescribeCanariesXem danh sách canaries
GetCanaryRunsXem kết quả chạy
StartCanary / StopCanaryStart/stop canary
DescribeRuntimeVersionsXem runtime versions available
TagResourceQuản lý tags

Security Considerations

  • Canaries chạy trong VPC hoặc public internet
  • Cần IAM role với permissions:
    • CloudWatch Logs write
    • S3 write (artifacts)
    • X-Ray write (nếu tracing enabled)
  • Secrets nên store trong Secrets Manager, không hardcode
  • Screenshots có thể chứa sensitive data

Metrics & Alarms

Metrics:
- SuccessPercent (0-100%)
- Duration (milliseconds)
- Failed (count)
- 2xx, 4xx, 5xx (HTTP status counts)

Alarms:
- SuccessPercent < 90% → SNS alert
- Duration > 5000ms → Performance degradation

Use Cases

  1. Proactive Monitoring - Phát hiện downtime trước users
  2. API Testing - Continuous API health checks
  3. Visual Regression - Detect UI changes
  4. Multi-region Monitoring - Test from different regions
  5. Post-deployment Validation - Verify deployment success

Lambda Insights

  • Enhanced monitoring cho Lambda
  • Metrics: CPU, memory, network, cold starts
  • Requires Lambda Insights extension (Layer)
  • Dashboard: /aws/lambda-insights/

Container Insights

  • ECS/EKS monitoring
  • Metrics: CPU, memory, network, disk per task/pod
  • Performance log events
  • Automatic dashboards

Application Insights

  • Automatic problem detection
  • .NET, Java, SQL Server workloads
  • Correlate metrics, logs, alarms
  • Automated dashboards

VPC Flow Logs

  • Monitor network traffic trong VPC
  • Troubleshoot connectivity issues
  • Security analysis
  • Publish to CloudWatch Logs hoặc S3

Visualization Services

Amazon Managed Grafana

  • Visualize data từ multiple sources
  • CloudWatch, Prometheus, OpenSearch, Timestream
  • Custom dashboards và alerts

Amazon OpenSearch

  • Log analytics và visualization
  • Kibana dashboards
  • Full-text search
  • Real-time analysis

Exam Tip:

  • Lambda Insights = enhanced Lambda monitoring (add as Layer)
  • Container Insights = ECS/EKS monitoring
  • ServiceLens = end-to-end application view
  • Synthetics = proactive API endpoint monitoring
  • VPC Flow Logs = network troubleshooting
  • CloudWatch Dashboards cho custom views, có thể cross-account/cross-region