| Widget | Use Case |
|---|---|
| Line graph | Metrics over time (latency, errors) |
| Number | Current value (active connections) |
| Alarm status | Health overview |
| Log insights | Recent errors, patterns |
| Explorer | Dynamic resource discovery |
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.
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
a) Hiểu toàn bộ hệ thống
b) Service Map
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):
| Góc nhìn | Mô tả |
|---|---|
| Infrastructure Monitoring | Xem metrics & logs để hiểu resources (EC2, Lambda, database) |
| Transaction Monitoring | Xem traces để hiểu request flow qua các components |
| End-User Monitoring | Tích hợp Synthetics canaries để theo dõi user experience |
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
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 | Chi tiết |
|---|---|
| Holistic Observability | Không phải lật giữa metrics, logs, traces ở các tab khác nhau |
| Tăng tốc phân tích | Giả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 user | Xem 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 |
| Dịch vụ | Mối liên hệ |
|---|---|
| AWS X-Ray | Cung cấp trace data để hiển thị trong ServiceLens |
| CloudWatch Logs | Chứa logs phục vụ điều tra lỗi |
| CloudWatch Metrics | Hiển thị metrics và alarms |
| CloudWatch Synthetics | Theo dõi endpoint từ phía user, hiển thị anomalies |
✅ Ứng dụng microservices phân tán ✅ Mô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
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
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
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”.
Canary = script monitoring chạy theo schedule để:
| Data Type | Mô tả |
|---|---|
| Load time | Thời gian tải trang/API |
| Screenshots | Visual monitoring, so sánh UI changes |
| Logs | Chi tiết execution logs |
| Metrics | SuccessPercent, Duration, Failed |
Kết quả phân tích tích hợp với CloudWatch ServiceLens để:
| Type | Use Case |
|---|---|
| Heartbeat | Monitor endpoint availability |
| API Canary | Test REST APIs |
| Broken Link Checker | Find broken links on website |
| Visual Monitoring | Detect UI changes |
| Canary Recorder | Record user actions, replay |
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
)
| API | Purpose |
|---|---|
CreateCanary | Tạo canary monitoring |
DeleteCanary | Xóa canary |
DescribeCanaries | Xem danh sách canaries |
GetCanaryRuns | Xem kết quả chạy |
StartCanary / StopCanary | Start/stop canary |
DescribeRuntimeVersions | Xem runtime versions available |
TagResource | Quản lý tags |
Metrics:
- SuccessPercent (0-100%)
- Duration (milliseconds)
- Failed (count)
- 2xx, 4xx, 5xx (HTTP status counts)
Alarms:
- SuccessPercent < 90% → SNS alert
- Duration > 5000ms → Performance degradation
/aws/lambda-insights/Exam Tip: