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

どうしてログがいるのかな_どんなログがいいのかな__SAGA-JAWS.pdf

Avatar for Ryuji Hori Ryuji Hori
August 03, 2024
180

 どうしてログがいるのかな_どんなログがいいのかな__SAGA-JAWS.pdf

Avatar for Ryuji Hori

Ryuji Hori

August 03, 2024
Tweet

Transcript

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

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Confidential and Trademark. どうしてログがいるのかな? どんなログがいいのかな? 堀 竜慈 ( Hori Ryuji ) アマゾン ウェブ サービス ジャパン合同会社 ソリューションアーキテクト J A W S - U G S A G A
  2. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 自己紹介 名前:堀 竜慈 (Hori Ryuji) 所属:アマゾンウェブサービスジャパン合同会社 ソリューションアーキテクト (福岡拠点在住) 経歴:国内重電企業でシステムインテグレータ (約4年)、 ベンチャー企業で主にアプリケーション開発 (約4年)、 AWS Japan 合同会社 の SA として活動 (現在4年目) 最近は鉄道業界 focus 好きな AWS サービス : DevOps 系全般、AI/ML 系全般
  3. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ファミリー枠 連れてきたいよ 我が息子 祝︕SAGA JAWS ファミリー枠 SDGsで良いなぁ
  4. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. どうしてログがいるのかな? どんなログがいいのかな? どうしておなかがへるのかな〜♪ べんきょうするとへるのかな〜♪ 神の啓示 !? >
  5. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 対象者、本セッションで学べること • 対象者 § ログがなぜ大事なのか知りたい方 § どんなログの取り方をすれば良いのか知りたい方 § AWS 初心者で監視や Observability に興味のある方 • 本セッションで話すこと § どうしてログが大事なのか § どのようなログが良いのか § AWS ではどのようなログに関するサービスがあるか AWSというよりはログの全般的な話に フォーカスをします AWS わからない⼈も、安⼼してください・・ はいてますよ
  6. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. アジェンダ • オブザーバビリティについておさらい • ログとは • どうしてログがいるのかな? • どんなログがいいのかな? • 補足 外形監視とリアルタイムユーザモニタリングについて • まとめと参考情報 6
  7. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. オブザーバビリティについておさらい 7
  8. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. オブザーバビリティ(可観測性) どこで・何が・なぜ起こってるのか - このサービスでは、メソッドの 90% が 200 ミリ秒以下で完了している - この API は 1 秒間に 203 の HTTP リクエストを処理している - このサービスの CPU 使⽤率は 85% に達している 例)
  9. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. オブザーバビリティはなぜ必要か モノリシック アプリケーション サービス マイクロサービス 少 多 静的 動的 モニタリング オブザーバビリティ 予測可能な範囲はモニタリングで対応できるが 未知の事象や早い変化への対応にはオブザーバビリティが求められる 監視対象
  10. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. オブザーバビリティで得られるメリット 運⽤からビジネス⾯に⾄るメリットを得ることができる 視認性 迅速なトラブルシューティング 顧客体験 システム運⽤において、判断に必要な情報がきちんと取得できている状態
  11. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. メトリクス、ログ、トレース メトリクス ログ トレース 時間間隔で計測されたデータ の数値表現 タイムスタンプが記録された、 時間の経過とともに起こった イベントの記録 エンドツーエンドの リクエストフローの記録 ・オブザーバビリティでよく利⽤されるテレメトリデータ オブザーバビリティ全体を考えることが⼤切ですが、 このセッションではログにフォーカスしてお話していきます
  12. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. ログとは 12
  13. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログ タイムスタンプが記録された、 時間の経過とともに起こったイベントの記録 2024-08-02 12:34:56,789 INFO [main] com.example.MyApp - Application started successfully 2024-08-02 12:34:59,789 INFO [main] com.example.MyApp - User ‘Ryuji.hori' logged in successfully 2024-08-02 12:35:01,123 ERROR [main] com.example.MyApp - Failed to connect to database -アプリケーションログ、DBログ、セキュリティログ など様々 とあるアプリケーションログの例
  14. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログ アプリケーションログの例 2024-08-02 12:34:56,789 INFO [main] com.example.MyApp - Application started successfully 2024-08-02 12:34:59,789 INFO [main] com.example.MyApp - User ‘Ryuji.hori' logged in successfully 2024-08-02 12:35:01,123 ERROR [main] com.example.MyApp - Failed to connect to database 「Ryuji.Hori」というユーザがログイン成功 した⽇時がわかる アプリがDB接続失敗した⽇時がわかる
  15. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. どうしてログがいるのかな? 15
  16. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. オブザーバビリティで得られるメリット 運⽤からビジネス⾯に⾄るメリットを得ることができる 視認性 迅速なトラブルシューティング 顧客体験 再掲 オブザーバビリティで得られるメリットを 実現するためにログは⼤事
  17. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログによるメリット例(1/3) 17 • サービスが異常な時間を減らし、ユーザ体験の損失を減らせる § ログから自社サービスの異常をすぐに検知 § ログ情報を用いて問題箇所を迅速に特定し修正 • ユーザ体験をより向上させることができる § 画面のロードやデータのクエリに時間がかかっている場所を特定して性能改善 § 離脱率の高い画面を特定してUX改善
  18. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • 開発効率の向上 § デバッグログを活用してデバッグを高速化 – (本番環境、検証検証ではとくに唯一のソースとなり得る) § パフォーマンス分析の効率化 ログによるメリット例(2/3) 18 • セキュリティ強化 § 不正アクセスや情報漏洩を素早く検知して迅速に対応する § インシデント発生時のログを分析して、再発防止策を検討できる
  19. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログによるメリット例(3/3) 19 • 運用保守作業の効率化 • コンプライアンス遵守の証明 • ビジネスにおける意志決定の判断に活用 • 生成AI活用の際のデータソースに • etc… ログ設計をする上では、 どのケースで役⽴てたいかを考えるのは⼤事 ログにはいろんなお役⽴ちケースがある
  20. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. どんなログがいいのかな? 20
  21. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. どんなログの扱い方がいいのかな? 21
  22. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 今回はシステム運用のケースを中心に、 いくつかのポイントをご紹介!
  23. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログの目的を考えよう!
  24. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログの活用目的が明確になると、どのように扱えばよいかが見えてくる ログの目的を考える (1/2) • システムの障害検知が目的であれば・・ § 短期間のログライフサイクルにあった保管が大事 § すぐに参照しやすい環境や、障害通知のための設計が大事 • ユーザの行動分析が目的であれば・・ § 中長期的なログライフサイクルにあった保管が大事 § KPIの設定や、ユーザプライバシー保護の意識が大事
  25. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログの目的を考える (2/2) 25 • アンチパターン § なんとなくログを取得してコストだけが発生 § デバッグレベルのログを本番環境で大量に出力 活用ケースが思いつかないログは邪魔になるので蓄積 or 転送しない (もしくは低コストなストレージに移行する)
  26. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログは集約しよう!
  27. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログは集約しよう(1/2) 27 サーバが増加した際に、各サーバにログインしてログを確認する必要があり、運用が辛い 障害やディスク容量不足で、対象サーバにログインできずログが確認出来なくなる 集約しないと・・ ログの集約をすることで、運用の手間をなくし、問題分析をしやすく ログ集約環境
  28. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログは集約しよう(2/2) 28 Amazon CloudWatch Logs AWSのサービスだと、例えばログの集約に Amazon CloudWatch Logs が使える
  29. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. CloudWatch Logs (1/2) AWS サービスおよびアプリケーションログの監視、保存、アクセスを提供 • エージェント経由でログメッセージで ログメッセージを Cloud Watch Logs へ転送 • 保存ログデータの保持期間も⾃由に設定可能 (1⽇〜永久) • Amazon S3 へのログのエクスポートが可能 CloudWatch Logs オンプレミス/EC2 CloudWatch Agent
  30. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. CloudWatch Logs (2/2) AWS サービスおよびアプリケーションログの監視、保存、アクセスを提供 メトリクスフィルタ • ログデータから特定⽂字列のフィルタリング • ⼀致したパターン数をメトリクスとして記録 例)ERROR ログ出現数によってメトリクスとアラームを作成、通知を⾏う CloudWatch Metrics CloudWatch Logs CloudWatch Alarms 出現数が閾値 を超えたので 障害アラート ログの情報から重要な情報を検知し、通知を行う仕組みも作りやすい !! Amazon SNS 「ERROR」⽂⾔ の出現数を時系列 で可視化 「ERROR」⽂⾔ の出現を通知
  31. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログは構造化しよう
  32. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログは構造化しよう 32 構造化することでログ分析ツール、SaaSによる分析がしやすくなる (もちろんAWSの分析用サービスも) [Error] Feb 21 12:32:23 193.121.123 https-8080 Failed client denied by server jsonPayload: { "level": "[Error]", "timestamp": "Feb 21 12:32:23", "host": "193.121.123", "port-number": "https-8080", "result": "Failed", "message": "client denied by server", } 構造化されていないデータ 構造化データ (JSON) Amazon CW Amazon CW まぁOK CWの場合、構造化されていなくても分析は可能
  33. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. CloudWatch Logs Insight で可視化・分析 CloudWatch Alarms CloudWatch Metrics CloudWatch Logs CloudWatch Logs Insights AWSサービス お客様システム CloudWatch Dashboards メトリクスを送信 ログを送信 メトリクスに応じた アクションの実⾏ ログの可視化 メトリクスを送信 クエリによってログデータの検索及び分析を⾏える機能 本⽇のハンズオンはこのあたり全般網羅
  34. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. CloudWatch Logs Insights クエリを実行することで、ログデータをインタラクティブに検索および分析 34 専用のクリ言語を利用 様々なクエリ補助機能を搭載 § サンプルクエリ § コマンドの説明 § クエリの自動補完 § ログフィールド検出 クエリ例︓fields @timestamp, @message | filter user = ”ryuji.hori" and action = "login" and status = "success" | stats count() as login_success_count CloudWatch Logs Insights
  35. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ログの構造化によるクエリの差 35 fields @timestamp, @message | filter user = ”ryuji.hori" and action = "login" and status = "success" | stats count() as login_success_count { "timestamp": "2024-08-03T12:00:00Z", "user": "ryuji.hori", "action": "login", "status": "success” } 非構造化ログ 構造化されたログ 2024-08-03T12:00:00Z ryuji.hori performed login action with status success クエリ クエリ fields @timestamp, @message | parse @message " * * performed * action with status *" as user, action, status | filter user = ”ryuji.hori" and action = "login" and status = "success” | stats count() as login_success_count ⽣成AIでクエリを⾃動⽣成も・・ハンズオンでどうぞ CloudWatch Logs Insights
  36. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. その他、ログ活用のポイント
  37. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. その他のログ活用のポイント(1/2) • ログ設計を行い、定期的に見直す • ログフォーマット、ログレベル、ライフサイクル、 アーキテクチャ、運用方式 、etc… 37 • 機密情報は除外する • 記述を削除、もしくはマスクをかける • パスワード、クレジットカード番号、個人名など
  38. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. その他のログ活用のポイント(2/2) 38 • ログのローテーションや保存期間を意識する • 古いログは削除、もしくは低コストストレージへ移行など • CloudWatch Logs であれば保存期間は指定すること • コストやパフォーマンス効率を上げる • コストを考慮する • ストレージ料金以外にも、データ転送量金等も意識 • CloudWatch Logs であれば、低頻度アクセスクラスを 用いて、転送量を抑えることができる Amazon S3
  39. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. AWS における代表的なログの蓄積先 Amazon CloudWatch Logs Amazon S3 用途 リアルタイムに分析したいとき/短期保存 アドホックに分析したいとき/長期保存 保存料金 (東京リージョン) [USD] 保存 (アーカイブ) 0.033/GB S3 標準 0.025 /GB S3 標準 - 低頻度アクセス 0.0138USD / GB S3 Glacier Deep Archive 0.002USD/GB 保管期間 デフォルトは”無制限” 1日~10年単位で設定可能 デフォルトでは設定されていない. 1日単位できめ細かに設定可能 (期間に上限なし) 39 https://aws.amazon.com/jp/cloudwatch/pricing/ https://aws.amazon.com/jp/s3/pricing/ * Amazon CloudWatch Logs と Amazon S3 のログ取り込み料金を直接比較するのは困難であるので記載しない * Amazon S3 のストレージクラスは他の選択肢もある
  40. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. 補足 〜外形監視と リアルタイムユーザモニタリングについて〜 40
  41. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 合成監視 (Synthetic Monitoring) あるいは 外形監視 とは 41 システムに「ひとりのユーザ」としてアクセスして ログやメトリクスの収集を行う監視手法 合成監視、外形監視でわかること ・サービスに問題が発生しているかどうか ・それがユーザに影響を与えているかどうか ・システム内部から見えないことがわかる レスポンスコード、応答速度などを 外から監視 https://aws.amazon.com/jp/blogs/news/new- use-cloudwatch-synthetics-to-monitor-sites-api- endpoints-web-workflows-and-more/ ソトカラ カンシシマス CloudWatch Synthetics
  42. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. CloudWatch Synthetics Canary をセットアップし、スケジュールに従ってテストを実行 42 Canary(アプリケーションに潜入する スクリプト)を作成・セットアップし、 スケジュールに従ってテスト § エンドポイントと API を外形監視 アプリケーションに顧客トラフィック がない場合でも、顧客体験を継続的に 検証可能 CloudWatch Synthetics
  43. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. リアルタイムユーザモニタリングについて エン ドユ ー ザー の体 験その も の を モニ タ す る こ とで ユーザ 体験 の改善を 実 現 リアルユーザーのパフォーマンスをモニタし、 ブラウザやデバイスの種類、物理的ロケー ション、ネットワークの接続性の問題などを 把握できる • ダッシュボードでページの読み込み 順序やJavaScript/HTTPレスポンス のエラーなど、パフォーマンス問題 に関する情報を可視化 CloudWatch シリーズだと CloudWatch RUM
  44. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. [アラーム] CW Alarms [イベント] [メトリクス] CW Metrics [ログ] CW Logs [ログ分析] CW Logs Insights [統合] CW Dashboards time-base event-base メトリクスを送信 ログを送信 メトリクスに応じた アクションの実⾏ ログの可視化 イベントに応じた ターゲットによる処理 [構造化ログによるメトリクス] CW Container Insights / Contributor Insights [Lambda拡張機能によるメトリックス] Lambda Insights [アプリケーションコンポーネントのメトリックス] Application Insights [トレース] CW ServiceLens CW Synthetics Amazon CloudWatchの全体像 [タグベースの視覚化] CW Metrics Explorer Amazon Kinesis Data Firehose [メトリクスストリーム] CW Metrics Stream Amazon EventBridge [外形監視] ※CW = CloudWatch AWSサービス オンプレミス/EC2 CW Agent CW RUM CW Evidently [リアルユーザー モニタリング] [フィーチャーフラグ A/Bテスト] CW Metrics Insights [リアルタイムの メトリックス分析]
  45. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. まとめ 45
  46. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. まとめ § ログが大事な理由についてお伝えしました – ログがあると様々なメリットを享受できます § ログをどのように扱えばよいのかお伝えしました – 特にログの目的を考えて設計していくことが大事です § AWS ではどのようなログに関するサービスがあるかお伝えしました – 今回は Amazon CloudWatch を中心にお伝えしました
  47. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 参考文献 • AWS ではじめるオブザーバビリティ - システムのどこで・ 何が・なぜ起こってるのかを理解する • https://aws.amazon.com/jp/events/builders-online- series/ • AWS Observability Best Practices • https://aws-observability.github.io/observability-best- practices/ja/ • One Observability Workshop (ちょっとレベル高いけど) • https://catalog.workshops.aws/observability/ja-JP 47
  48. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon Confidential and Trademark. Thank you! 48 !?