Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CloudWatch 大好きなSAが語る CloudWatch キホンのキ

o11yfes
April 15, 2025

CloudWatch 大好きなSAが語る CloudWatch キホンのキ

o11yfes

April 15, 2025
Tweet

More Decks by o11yfes

Other Decks in Technology

Transcript

  1. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 1 © 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Confidential and Trademark. CloudWatch大好きなSAが語る CloudWatch キホンノキ Miki Tsuwazaki 春 の O b s e r v a b i l i t y 祭 り 2 0 2 5 〜 進 化 す る A m a z o n C l o u d W a t c h 基 礎 か ら 最 新 機 能 ま で 完 全 解 説 〜 Solutions Architect Amazon Web Service Japan G.K.
  2. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 2 自己紹介 津和崎 美希 Miki Tsuwazaki アマゾンウェブサービスジャパン ソリューションアーキテクト 通信業のお客様を中⼼にご⽀援しています。 2 n⼤好きなサービス n Amazon CloudWatch
  3. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 3 Amazon CloudWatchの好きなところ ①ある意味サーバーレスなところ ②スケーラビリティが求められる企業の事例があるところ ③初心者に優しいところ ④ログ保管用のストレージなど管理に頭をいためなくていいところ ⑤監視するシステムの進化にあわせて進化するところ
  4. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 4 CloudWatchの始め方 ⭐まずはダッシュボードを見てみよう CloudWatchをマネージメントコンソールで今使っているAWSサービスの状況を確認してみる。 利⽤中のサービスの ⾃動ダッシュボードが あらかじめ⽤意されている。 ①ダッシュボードをClick ②⾃動ダッシュボードをClick ※この操作にかかる料⾦は無料(2025/04/11時点) • 基本のモニタリングメトリクス (デフォルトで AWS サービ スから送信されるメトリクス)は無料 • すべての⾃動ダッシュボードは無料 料⾦については、AWS公式Webサイトにてご確認ください https://aws.amazon.com/jp/cloudwatch/pricing/
  5. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 5 再掲:CloudWatch / X-Ray は最初の選択肢 メトリクス ログ トレース Amazon CloudWatch AWS X-Ray Amazon CloudWatch Application Signals
  6. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 6 メトリクス • CloudWatchに発⾏された時系列のデータポイントのセット • データポイントはタイプスタンプと(オプションで)測定 単位を保持 • メトリクスは作成されたリージョンにのみ存在 • メトリクスは名前空間、メトリクス名、ディメンションで ⼀意に定義される。 • メトリクスは削除不可で保持スケジュールに従い 期限切れになる 名前空間 • CloudWatchメトリクスのコンテナ • 異なる名前空間のメトリクスは相互に切り離される • AWSサービスでは AWS/<service>が使⽤される(例: AWS/EC2) ディメンション • メトリクスを⼀意に識別する名前/値のペア (例:InstanceId=i-12345678) CloudWatch メトリクスとは?
  7. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 7 ⇨データテーブルなどの他の形式にもできる。 ⭐メトリクスを可視化してみよう - DEMO
  8. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 8 CloudWatch カスタムメトリクス 標準メトリクス以外の独⾃メトリクスも監視可能 • AWS CLIの”put-metric-data”もしくは”PutMetricData” APIでデータを登録 • CloudWatch Logsに“Embedded Metrics Format”で書くことで、カスタムメトリクスをLogに埋め込んで送ることも可能 • 詳細度が 1秒のデータを含む⾼解像度なメトリクスを発⾏可能 →1分未満のアクティビティを迅速に把握 ⾼解像度にメトリクスを発⾏する場合、APIコール時のスロットリング対策も忘れずに (上限緩和申請も検討) • 単⼀のput-metric-dataに複数のデータポイントを⼊れる • 統計セットを利⽤する • リトライ処理をする $ aws cloudwatch put-metric-data –metric-name RequestLatency¥ --namespace "GetStarted“¥ --timestamp 2014-10-28T12:30:00Z¥ --value 87 ¥ --unit Milliseconds¥ --dimensions InstanceId=1-23456789,InstanceType=t3.small $ aws cloudwatch put-metric-data --metric-name RequestLatency¥ --namespace "GetStarted“¥ --timestamp 2014-10-28T12:30:00Z¥ --statistic-value Sum=60,Minimum=15,Maximum=105,SampleCount=5 ←単⼀値の登録 ←統計セットの登録
  9. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 9 再掲:CloudWatch / X-Ray は最初の選択肢 メトリクス ログ トレース Amazon CloudWatch AWS X-Ray Amazon CloudWatch Application Signals
  10. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 10 CloudWatch Logsの例 ロググループが Lambda関数ごとに を作成される Lambda関数を実⾏す るとログストリーム が⾃動で追加される ログイベントで⽣のイベ ントが確認できる
  11. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 11 CloudWatch Logsの仕組み Web Server web001.ap-northeast-1 ロググループ ログストリーム ログイベント web002.ap-northeast-1 web003.ap-northeast-1 ログイベント • 1つのログエントリ • モニタリングしているリソースに よって記録されたアクティビティの レコード • イベント発⽣時のタイムスタンプお よび⽣のイベントメッセージで構成 ログストリーム • 同じソースを共有する⼀連のログイ ベント • モニタリングしているリソースのタ イムスタンプ順でイベントを表す ロググループ • 複数のログストリームで構成 • 保持、監視、アクセス制御について 同じ設定を共有するログストリーム のグループを定義
  12. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 12 ⭐ログを可視化してみよう - DEMO
  13. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 13 CloudWatch Logs Insightsを活用して ロググループからエラーログを抽出して可視化 ⇨①⾃然⾔語でクエリを⽣成 ⇨②⽣成されたクエリを実⾏ ※Log Insightsは スキャンされた データのGB単位の 料⾦体系
  14. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 14 再掲:CloudWatch / X-Ray は最初の選択肢 メトリクス ログ トレース Amazon CloudWatch AWS X-Ray Amazon CloudWatch Application Signals
  15. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 15 ポストモーテム Amazon での対応例 アラーム ダッシュボード メトリクス分析 ログ分析 生ログ トレース 抽 象 度 ⾼ 低 参考)AmazonでのObservability best practice なぜビジネスに影響がでたのか?ア ラームはなったのか?の質問に答える ために計装を追加していく *計装とは: ログ、メトリクス、トレースなどの データを取得し、外部に送信できるよ うシステムに組み込むこと h"ps://aws.amazon.com/jp/builders-library/building-dashboards-for-opera;onal-visibility/ ӡ༻ΛՄࢹԽ͢ΔͨΊͷ μογϡϘʔυͷߏங
  16. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 16 ⭐トレースでできること
  17. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 17 CloudWatchにテレメトリーデータを集めるには? • 統合CloudWatchエージェントを使えば、 CloudWatch Logs・Metrics・Traceに対応している • クラウドでもオンプレミスでもコンテナでも利用可能。 • Linux, Windowsの両方で稼働。 17 ★コンテナ向けには、 CloudWatch エージェントコンテナイメージを提供 → h2ps://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/monitoring/ContainerInsights.html ★サーバーへのインストール⽅法は⼤きく以下3パターン 1. コマンドラインで実⾏(複数サーバーに⾏うには⼯夫が必要)→コマンドラインを使⽤した CloudWatch エージェントのインストール 2. SSMを活⽤(SSMなら多数のサーバーにも簡単導⼊)→AWS Systems Manager を使⽤した CloudWatch エージェントのインストール 3. IaCで(CFnで併せてAgentも導⼊)→AWS CloudFormationを使⽤してCloudWatch エージェントのインストール
  18. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 18 参考:CloudWatch Agentでx-Rayにトレースを送る "8493BZͱ 0QFO5FMFNFUSZ4%,ͷ྆ํ͔ΒͷτϨʔεΛऩूͯ͠ "8493BZʹૹ ৴͢ΔΑ͏ $MPVE8BUDIΤʔδΣϯτΛઃఆͰ͖ΔΑ͏ʹͳ͍ͬͯΔɻ
  19. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 19 CloudWatch Alarmsでメトリクスをアクションにつなげる メトリクス アクション Amazon CloudWatch Amazon EC2 Amazon SNS Amazon EC2 Auto Scaling Alarm AWS Systems Manager OpsCenter AWS Systems Manager Incident Manager ①静的閾値に基づくアラーム ▪例︓5分間平均のCPU使⽤率が90%を6つの評価期間に2回以上発⽣ =30分の評価間隔で閾値超え2回ならばアラーム ※Event Bridgeにも アラーム状態変化は 配信される ②Metrics Insights クエリに基づく CloudWatch アラーム ▪例︓フリートのすべてのインスタンスの CPU 使⽤率を監視する →アラーム作成後の追加インスタンスにも監視が⾃動で適⽤される ④複合アラーム (例︓①と③両⽅ALARM状態のときにSNSトピックに通知する ※EC2アクション未対応) ③CloudWatch 異常検出に基づいたアラーム ▪例︓最⼤2週間分のErrorCountメトリクスに機械学習アルゴリズムを 適⽤して、メトリクスの想定値のモデルから“正常の範囲”を超えてError がある場合、突然の変化として検出する
  20. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 20 アラームを作成する例 1.ナビゲーション ペインで、[アラー ム]、[すべてのア ラーム] の順に選 択 2.[アラームの作 成] を選択 3.メトリクス を選択 A [期間] は、アラームの各データポイントを作 成するためにメトリクスや式を評価する期間 B [評価期間] は、アラームの状態を決定するま でに要する直近の期間 (データポイント) の数 C [Datapoints to Alarm (アラームを実⾏す るデータポイント)] は、アラームが ALARM 状 態に移るためにしきい値を超過する必要がある評 価期間内のデータポイントの数 5分間平均のCPU使⽤率が90%を6つの評価期間に2回以上発⽣(⽋落データはない場合) ≒30分の評価間隔で閾値超え2回ならばアラーム A C B 4.条件・アクションを 設定
  21. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 21 アラームを数多く作成するのが大変な時 アラームに関する推奨事項と その設定のための IaC や CLI サンプ ルをAWSマネージメントコンソール からダウンロードして活⽤できます。
  22. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 22 CloudWatchの全体像 Logs RUM Amazon CloudWatch Digital experience monitoring Visualizations Insights and analysis Foundations Partners and integrations Instrumentation and collection Synthetics Metrics Internet Monitor Traces Container Insights Lambda Insights Contributor Insights Application Insights Metrics streams CloudWatch embedded metric format Metrics explorer Dashboards Live Tail Logs Insights Cross account observability OpenTelemetry CloudWatch agent Application Signals ApplicaBon Signalsの進化に伴いアプリケーションモニタリングのカバレッジ向上に加え、 監視するシステムの進化にあわせて、Network Monitoring、Database Insights等も加わり進化を続けてい る。
  23. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 23 CloudWatch基本は簡単!まずは使ってみよう。
  24. © 2025, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. 24 Thank you