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

Prometheus によるクラウドネイティブなモニタリングとは / What is cloud native monitoring with Prometheus?

atoato88
August 02, 2018

Prometheus によるクラウドネイティブなモニタリングとは / What is cloud native monitoring with Prometheus?

@OpenStack Days Tokyo 2018 / Cloud Native Days Tokyo 2018

atoato88

August 02, 2018
Tweet

Other Decks in Technology

Transcript

  1. Prometheusによる クラウドネイティブなモニタリングとは Cloud Native Days Tokyo 2018 / OpenStack Days

    Tokyo 2018 2018/08/02 NECソリューションイノベータ株式会社 稲生 章人 1
  2. Agenda • 自己紹介 • 発表内容 • トレンド • モニタリングについて •

    Prometheus • Operator • Prometheus Operator • デモ • Wrap-up • 参考 3
  3. 自己紹介 • 稲生 章人(いのう あきひと) / @atoato88 ◦ 業務 ▪

    OpenStack (Essexごろ) からクラウドテクノロジーに触れ、 2016年に IaaS基盤の構築・運用業務を経験。その後、コンテナ技術の調査・機 能検証に従事。SW開発よりインフラ構築の経験が多いです。 ◦ 言語 ▪ Bash (2007 - ) ▪ Python (2014 - ) ▪ Go (2017 - ) ◦ その他 ▪ 最近はコンテナ界隈の勉強会 (Kubernetes Meetup, Cloud Native Meetup, etc..)に割と出没しています ▪ 犬好き 4
  4. 発表内容 • Prometheus を使った Kubernetes のアプリケーションモニタリングの基本をお話し ます。 • これから Kuberentes

    を使ったアプリケーションのデプロイや運用をしようと思って いる方がメインターゲットです。 • Kubernetes の基本的な概念や使い方を把握されている方を想定しています。 • Kubernetes と Prometheus、Prometheus Operator を使った場合の特徴や利点 を知っていただき、選択肢の1つとして認識いただけると良いかと思います。 5
  5. トレンド • コンテナ技術の活用が本格化 • コンテナオーケストレーションエンジンとしては Kubernetes のシェアが最も高く※1、 大手クラウドベンダーが Kubernetes as

    a Service (KaaS) の提供を相次いで開始 ◦ GKE(Google Cloud Platform) ◦ AKS(Microsoft Azure) ◦ EKS(Amazon Web Services) ※1: https://sysdig.com/blog/2018-docker-usage-report/ 6
  6. トレンド • コンテナで動かすアプリケーションは “Cloud Native” というキーワードに象徴される考え 方に沿って作成するのが良いと言われています。 ◦ Cloud Native

    の定義は CNCF のページに記述されています。 ▪ https://www.cncf.io/about/faq/ ▪ “Cloud native technologies empower organizations to build and run scalable applications in modern, dynamic environments such as public, private, and hybrid clouds. Containers, service meshes, microservices, immutable infrastructure, and declarative APIs exemplify this approach. These techniques enable loosely coupled systems that are resilient, manageable, and observable. Combined with robust automation, they allow engineers to make high-impact changes frequently and predictably with minimal toil.” ▪ 本セッションのテーマに関わる特徴としては、以下が挙げられます • マイクロサービス • コンテナ • オブザバブル(可観測性を持つ) • 自動化されている • 頻繁なシステム変更が可能 7
  7. モニタリングについて • “モニタリング” という言葉には様々な解釈がありますが、本セッションでのモニタリ ングの定義は以下の4つの方式で構成されることとします。 ◦ Profiling : プロファイリング ◦

    Tracing : トレーシング ◦ Logging : ロギング ◦ Metrics : メトリクス • そして、Prometheus は Metrics をカバーするソフトウェアであり、本セッションでは Prometheus による Metrics を使ったモニタリングの説明となります。 9
  8. Prometheus • メトリクスを用いたPull型のモニタリングシステム • 2012年に SoundCloud 社のエンジニアによって開発がスタート。2016年に CNCF がホ ストする2番目のプロジェクトとなった。

    • データは時系列で保存される • ラベルを用いた強力なデータモデルとクエリ言語(PromQL)が利用可能 ◦ データモデルはシンプルなテキスト形式なため、 Prometheus が読み込むメトリクスを容易に実装可能 ◦ クエリ言語ではラベルを用いた集約が可能なため、自分の欲しい観点で値を取得可能 (例 : サービスごと、リージョンごと、など ) • サービスディスカバリにより動的にモニタリング対象を追加・変更可能 • Grafana 等を用いることでデータを可視化できる • Logging の機能は提供しない • 長期ストレージ機能は提供しない 14
  9. Prometheus • コンポーネント構成 ref: https://prometheus.io/docs/introduction/overview/ Prometheus server モニタリング対象からメトリクス値を取得して保 存する。また、取得したメトリクス値に従って障 害かどうかを判定するルール判定を行う。

    Alertmanager Prometheus が障害と判断した時に特定の通 知を実行するコンポーネントであり、メール通知 やSlackを始めとするチャットツールへの通知、 任意のWebhook実行が可能。 Pushgateway バッチジョブ等の結果をキャッシュし、 Prometheusが結果をPullする。 Grafana Prometheus に蓄積されたデータの参照、グラ フ化を行うダッシュボード。 15
  10. Prometheus • データモデル と PromQL による集計 http_requests_total{code="200",instance="10.8.0.10:8080", ...} 8586 http_requests_total{code="200",instance="10.8.0.25:8080",

    ...} 7946 http_requests_total{code="404",instance="10.8.0.10:8080", ...} 8004 http_requests_total{code="404",instance="10.8.0.25:8080", ...} 7905 16 15909 sum(http_requests_total{job="example-app", code="404"}) → 8004 + 7905 15851 PromQL PromQL sum(http_requests_total{job="example-app", instance="10.8.0.25:8080"}) → 7946 + 7905
  11. Prometheus • サービスディスカバリ ◦ kubernetes-sd : Kubernetes API を使って Kubernetes

    上のリソース情報を取得できる。 Service のIPアドレスや Endpoints 情報を取得し、 Prometheus がメトリクスを取得するのに利用する。 ◦ 他にも OpenStack、GCP GCE、AWS EC2、Azure 等のサービスディスカバリ機能もある。 17 Service A Service B discovery & monitor 変更 既存
  12. Operator • CoreOSのブログで発表された考え方で、アプリケーションの作成、設定、管理を 行ってくれる固有のコントローラのこと。Kubernetes の仕組みを使って実現されて おり、アプリケーション独自のタスクを自動化してくれる。 • 発表当時(2016/11)に紹介されていたのは、etcd-operator と prometheus-operator

    の2つ。 • Kubernetes 上のアプリケーションと同様のアプローチでマニフェストを使った宣言 によって対象を管理することができる。 • KubeCon Europe 2018 で Operator Framework が発表され、今後 Kubernetes のエコシステムで各種 Operator の実装が進むと考えられる。 21 ref: https://coreos.com/blog/introducing-operator-framework
  13. Prometheus Operator • Prometheus を管理する Operator で、デプロイ・モニタリング設定・アラート設定な どを Kubernetes のリソースとして扱うことが可能。

    • Prometheus Operator デプロイ後、以下のようなマニフェストを Kubernetes に適 用すれば Prometheus がデプロイされる。 apiVersion: monitoring.coreos.com/v1 kind: Prometheus metadata: name: prometheus spec: serviceMonitorSelector: matchLabels: team: frontend resources: requests: memory: 400Mi apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: example-app labels: team: frontend spec: selector: matchLabels: app: example-app endpoints: - port: web 22
  14. Prometheus Operator • Prometheus は Pod としてデプロイされるため、オートヒールなど Kubernetes の 標準機能が動作します。

    • 設定変更は kubectl などを使って kind:Prometheus や kind:ServiceMonitor リ ソースに対する変更で実行します。 ref: https://coreos.com/operators/prometheus/docs/latest/user-guides/getting-started.html 23
  15. 1. サンプルアプリデプロイ 2. Prometheus + Grafana デ プロイ 3. モニタリング設定投入

    4. Grafana で確認 5. アプリをスケールアウト 6. Grafana で再度確認 デモ 24 Example App Prometheus Grafana monitor データ読み込み ブラウザから確認 Prometheus Operator デプロイ デモ構成の概要 ref: https://github.com/atoato88/prometheus-monitoring-demo
  16. Wrap-up • モニタリングのソフトウェアもクラウドネイティブアプリケーションの特徴に対応でき る必要があります。(手動の運用では追いつかない可能性があります。) ◦ ホワイトボックスモニタリングも行いましょう ◦ 集団に対する集計値を使ってサービスに対する健全性をモニタリングしましょう ◦ サービスの動的な変更を考慮しましょう

    • Prometheus、Prometheus Operator を使って Kubernetes と連携したモニタリン グを実現しましょう。 • 既存の運用基盤からクラウドネイティブアプリケーションを扱う事もできると思いま すが、Operator など Kubernetes を使ったシステムを検討することで幸せになれま す。使える仕組みは積極的に使いましょう。 25
  17. その他の関連トピック • Thanos ◦ https://github.com/improbable-eng/thanos ◦ 長期データ保管に対応 ◦ 複数のPrometheusのメトリクスをマージして見れるグローバルビュー ◦

    メトリクスのダウンサンプリング機能 • Istio v1.0 リリース (2018/07/31) ← NEW!! ◦ https://istio.io/blog/2018/announcing-1.0/ ◦ サービスメッシュにより提供されるモニタリング機能 26
  18. 参考 • Prometheus ◦ https://prometheus.io/ • Prometheus Operator ◦ https://github.com/coreos/prometheus-operator

    • SRE サイトリライアビリティエンジニアリング ―Googleの信頼性を支えるエンジニアリングチーム ◦ https://www.oreilly.co.jp/books/9784873117911/ • Prometheus Up & Running ◦ http://shop.oreilly.com/product/0636920147343.do • Declarative Multi Cluster Monitoring With Prometheus ◦ http://sched.co/Dqw1 ◦ slide • Monitoring What Matters: The Prometheus Approach to Whitebox Monitoring ◦ https://www.slideshare.net/brianbrazil/monitoring-what-matters-the-prometheus-approach-to-whitebox-monitoring-berlin- ops-summit-2016 27