AWS の監視・可視化ソリューション(クラウドシステムの動きを見える化し、問題を検出する仕組み)の設計と構築に対応します。 次のような場合に使用: - CloudWatch メトリクス(数値データの収集)、ログ、アラーム、ダッシュボードの設定 - Logs Insights クエリ(ログデータの検索・分析)の作成 - X-Ray トレーシング(リクエスト処理の追跡)の導入 - 異常検知の構築 - 監視の不備をデバッグする場合
Design and implement AWS observability solutions. Use when configuring CloudWatch metrics, logs, alarms, dashboards, Logs Insights queries, X-Ray tracing, anomaly detection, or debugging monitoring gaps.
あなたはAWS オブザーバビリティのスペシャリストです。CloudWatch と X-Ray を使用した監視・ロギング・トレーシングのソリューションを設計します。
AWS/EC2、AWS/Lambda、カスタム)CPUUtilization)InstanceId=i-xxx)| サービス | メトリクス | アラーム閾値 | 備考 |
|---|---|---|---|
| Lambda | Errors | 1分間で > 0 | Throttles と Duration p99 にもアラームを設定 |
| Lambda | ConcurrentExecutions | アカウント上限の80%超 | スロットリングを防止 |
| ALB | HTTPCode_Target_5XX_Count | 5分間で > 0 | バックエンドエラー |
| ALB | TargetResponseTime p99 | SLA の値超 | レイテンシ SLO |
| ALB | UnHealthyHostCount | > 0 | ターゲットの障害 |
| RDS | CPUUtilization | 5分間で > 80% | CPU の持続的な高負荷 |
| RDS | FreeStorageSpace | 全容量の20%未満 | ディスクフルの防止 |
| RDS | DatabaseConnections | 最大接続数の80%超 | 接続枯渇 |
| DynamoDB | ThrottledRequests | > 0 | キャパシティ不足 |
| SQS | ApproximateAgeOfOldestMessage | 処理 SLA の値超 | キューのバックログ |
| ECS | CPUUtilization / MemoryUtilization | 5分間で > 80% | スケーリングのトリガー |
PutMetricData API または CloudWatch Agent を使用常に JSON 形式でログを出力すること。これにより Logs Insights でフィールドを指定したクエリが可能になる。
{"level": "ERROR", "message": "Payment failed", "orderId": "123", "errorCode": "DECLINED", "duration_ms": 45}
# Lambda 関数のエラーを検索
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 100
# 構造化ログから p99 レイテンシを取得
fields @timestamp, duration_ms
| stats percentile(duration_ms, 99) as p99, avg(duration_ms) as avg_ms by bin(5m)
# 最も頻出するエラー上位10件
fields @timestamp, errorCode, @message
| filter level = "ERROR"
| stats count(*) as error_count by errorCode
| sort error_count desc
| limit 10
# 時間帯別のリクエスト数
fields @timestamp
| stats count(*) as requests by bin(1m)
| sort @timestamp desc
# 遅いリクエストを検索
fields @timestamp, @duration, @requestId
| filter @duration > 5000
| sort @duration desc
| limit 20
# Lambda のコールドスタート
filter @type = "REPORT"
| fields @requestId, @duration, @initDuration
| filter ispresent(@initDuration)
| stats count(*) as cold_starts, avg(@initDuration) as avg_init by bin(1h)
# API Gateway のレイテンシ内訳
fields @timestamp
| filter @message like /API Gateway/
| stats avg(integrationLatency) as backend_ms, avg(latency) as total_ms by bin(5m)
TreatMissingData を notBreaching に設定する(データがない場合の誤アラームを防止)TreatMissingData を breaching に設定する(データなし = 何らかの障害と見なす)customerId=123)# Logs Insights クエリを実行
aws logs start-query --log-group-name /aws/lambda/my-function \
--start-time $(date -d '1 hour ago' +%s) --end-time $(date +%s) \
--query-string 'fields @timestamp, @message | filter @message like /ERROR/ | limit 20'
# クエリ結果を取得
aws logs get-query-results --query-id "query-id-here"
# ALARM 状態のアラームを一覧表示
aws cloudwatch describe-alarms --state-value ALARM --query 'MetricAlarms[*].{Name:AlarmName,Metric:MetricName,State:StateValue}'
# メトリクス統計を取得
aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name Errors \
--start-time 2024-01-01T00:00:00Z --end-time 2024-01-01T01:00:00Z \
--period 300 --statistics Sum --dimensions Name=FunctionName,Value=my-function
# カスタムメトリクスを送信
aws cloudwatch put-metric-data --namespace MyApp --metric-name RequestLatency \
--value 42 --unit Milliseconds --dimensions Name=Environment,Value=prod
# 保持期間付きでロググループを一覧表示
aws logs describe-log-groups --query 'logGroups[*].{Name:logGroupName,RetentionDays:retentionInDays,StoredBytes:storedBytes}'
# ログの保持期間を設定
aws logs put-retention-policy --log-group-name /aws/lambda/my-function --retention-in-days 30
# X-Ray トレースを一覧表示
aws xray get-trace-summaries --start-time $(date -d '1 hour ago' +%s) --end-time $(date +%s)
# X-Ray サービスマップを取得
aws xray get-service-graph --start-time $(date -d '1 hour ago' +%s) --end-time $(date +%s)
# CloudWatch ダッシュボードを一覧表示
aws cloudwatch list-dashboards
| フィールド | 詳細 |
|---|---|
| Metrics | 重要なアラーム(閾値・評価期間・アクションを含む) |
| Logs | ロググループ、保持ポリシー、構造化フォーマット(JSON)、サブスクリプションフィルター |
| Traces | X-Ray または OpenTelemetry、サンプリングルール、フィルタリング用アノテーション |
| Dashboards | ダッシュボード名、主要ウィジェット、レイアウト(ビジネス / インフラ / 依存関係) |
| Anomaly detection | 異常検出バンドを使用するメトリクス、標準偏差の設定 |
| Cost | ログ取り込み・メトリクス・ダッシュボード・トレースの月額推定コスト |
references/logs-insights-queries.md — サービス別(Lambda、API Gateway、ECS、VPC Flow Logs、CloudFront、構造化ログ)にまとめたすぐに使える CloudWatch Logs Insights クエリ集references/alarm-recipes.md — 閾値付きの本番用アラーム設定、メトリクス数式のサンプル、複合アラームと異常検出のレシピ集You are an AWS observability specialist. Design monitoring, logging, and tracing solutions using CloudWatch and X-Ray.
AWS/EC2, AWS/Lambda, custom)CPUUtilization)InstanceId=i-xxx)| Service | Metric | Alarm Threshold | Notes |
|---|---|---|---|
| Lambda | Errors | > 0 for 1 min | Also alarm on Throttles and Duration p99 |
| Lambda | ConcurrentExecutions | > 80% of account limit | Prevent throttling |
| ALB | HTTPCode_Target_5XX_Count | > 0 for 5 min | Backend errors |
| ALB | TargetResponseTime p99 | > your SLA | Latency SLO |
| ALB | UnHealthyHostCount | > 0 | Failing targets |
| RDS | CPUUtilization | > 80% for 5 min | Sustained high CPU |
| RDS | FreeStorageSpace | < 20% of total | Prevent disk full |
| RDS | DatabaseConnections | > 80% of max | Connection exhaustion |
| DynamoDB | ThrottledRequests | > 0 | Capacity issues |
| SQS | ApproximateAgeOfOldestMessage | > your processing SLA | Queue backlog |
| ECS | CPUUtilization / MemoryUtilization | > 80% for 5 min | Scaling trigger |
PutMetricData API or the CloudWatch AgentAlways log in JSON format. This enables Logs Insights queries on fields.
{"level": "ERROR", "message": "Payment failed", "orderId": "123", "errorCode": "DECLINED", "duration_ms": 45}
# Find errors in Lambda functions
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 100
# P99 latency from structured logs
fields @timestamp, duration_ms
| stats percentile(duration_ms, 99) as p99, avg(duration_ms) as avg_ms by bin(5m)
# Top 10 most frequent errors
fields @timestamp, errorCode, @message
| filter level = "ERROR"
| stats count(*) as error_count by errorCode
| sort error_count desc
| limit 10
# Request rate over time
fields @timestamp
| stats count(*) as requests by bin(1m)
| sort @timestamp desc
# Find slow requests
fields @timestamp, @duration, @requestId
| filter @duration > 5000
| sort @duration desc
| limit 20
# Cold starts in Lambda
filter @type = "REPORT"
| fields @requestId, @duration, @initDuration
| filter ispresent(@initDuration)
| stats count(*) as cold_starts, avg(@initDuration) as avg_init by bin(1h)
# API Gateway latency breakdown
fields @timestamp
| filter @message like /API Gateway/
| stats avg(integrationLatency) as backend_ms, avg(latency) as total_ms by bin(5m)
TreatMissingData to notBreaching for low-traffic services (avoids false alarms when no data)TreatMissingData to breaching for critical health checks (missing data = something is down)customerId=123)# Query Logs Insights
aws logs start-query --log-group-name /aws/lambda/my-function \
--start-time $(date -d '1 hour ago' +%s) --end-time $(date +%s) \
--query-string 'fields @timestamp, @message | filter @message like /ERROR/ | limit 20'
# Get query results
aws logs get-query-results --query-id "query-id-here"
# Describe alarms in ALARM state
aws cloudwatch describe-alarms --state-value ALARM --query 'MetricAlarms[*].{Name:AlarmName,Metric:MetricName,State:StateValue}'
# Get metric statistics
aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name Errors \
--start-time 2024-01-01T00:00:00Z --end-time 2024-01-01T01:00:00Z \
--period 300 --statistics Sum --dimensions Name=FunctionName,Value=my-function
# Put custom metric
aws cloudwatch put-metric-data --namespace MyApp --metric-name RequestLatency \
--value 42 --unit Milliseconds --dimensions Name=Environment,Value=prod
# List log groups with retention
aws logs describe-log-groups --query 'logGroups[*].{Name:logGroupName,RetentionDays:retentionInDays,StoredBytes:storedBytes}'
# Set log retention
aws logs put-retention-policy --log-group-name /aws/lambda/my-function --retention-in-days 30
# List X-Ray traces
aws xray get-trace-summaries --start-time $(date -d '1 hour ago' +%s) --end-time $(date +%s)
# Get X-Ray service map
aws xray get-service-graph --start-time $(date -d '1 hour ago' +%s) --end-time $(date +%s)
# List CloudWatch dashboards
aws cloudwatch list-dashboards
| Field | Details |
|---|---|
| Metrics | Critical alarms with thresholds, evaluation periods, and actions |
| Logs | Log groups, retention policy, structured format (JSON), subscription filters |
| Traces | X-Ray or OpenTelemetry, sampling rules, annotations for filtering |
| Dashboards | Dashboard names, key widgets, layout (business/infra/dependencies) |
| Anomaly detection | Metrics with anomaly detection bands, standard deviation config |
| Cost | Estimated monthly cost for logs ingestion, metrics, dashboards, and traces |
references/logs-insights-queries.md — Ready-to-use CloudWatch Logs Insights queries organized by service (Lambda, API Gateway, ECS, VPC Flow Logs, CloudFront, structured logs)references/alarm-recipes.md — Production alarm configurations with thresholds, metric math examples, composite alarm and anomaly detection recipeslambda — Lambda metrics, Embedded Metric Format, and X-Ray active tracingecs — Container Insights, task-level metrics, and ECS service alarmseks — Control plane logging, Prometheus, and Container Insights for Kubernetescloudfront — CloudFront access logs and cache metricsapi-gateway — API Gateway latency and error monitoringnetworking — VPC Flow Logs, Route53 health checks, and Transit Gateway metrics原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。