1 of 34

Stackdriver Introduction

GCPUG Admin

Google Developers Expert

Mercari / Merpay Solution Team

@sinmetal

https://gcpug.jp

2 of 34

2

  • モニタリング系のサービスをまとめたGCPのブランド
  • 元々はAWS用のモニタリングサービスであるStackdriverを買収したところから、スタートした
  • GCPに元々あったCloud Loggingなどのサービスは、Stackdriverのブランドの中に入った。
  • 最近だと、Application Performance Managementの機能や、k8sの機能などが追加されている

https://gcpug.jp

3 of 34

Stackdriver Services

3

  • Stackdriver Monitoring
    • Monitoring
  • Stackdriver Logging と Stackdriver Error Reporting
    • Logging
    • Error Reporting
  • Stackdriver APM
    • Trace
    • Debugger
    • Profiler

https://gcpug.jp

4 of 34

Stackdriver Monitoring

https://gcpug.jp

5 of 34

What’s Stackdriver Monitoring

5

  • GCPとAWSをターゲットにしているモニタリングサービス
    • 時系列グラフ
    • Alert
    • Uptime Check
  • GCPのフルマネージドサービスは大抵自動で出力される
    • GCE InstanceはMonitoring Agentをインストールすることで、より細かい値が出力される

https://gcpug.jp

6 of 34

Monitoring Demo

6

個人的に便利だなーと思うのは、Cloud StorageのBucketごとのStorage Sizeを見れること

https://gcpug.jp

7 of 34

Alert Demo

7

https://gcpug.jp

8 of 34

8

  • Email
  • Cloud Mobile App
  • PagerDuty
  • SMS notifications
  • Slack
  • Campfire
  • HipChat
  • Webhooks

https://gcpug.jp

9 of 34

Uptime Check

9

  • 各地のデータセンターから、指定したURLにHTTPリクエストを送り、200 OKが返ってくるかをチェックする機能
    • VIRGINIA
    • OREGON
    • IOWA
    • BELGIUM
    • SINGAPORE
    • SAO PAULO

それぞれ、レイテンシも教えてくれる

https://gcpug.jp

10 of 34

Monitoring : Price

10

  • Monitoring data
    • $0.2580/MiB: 150–100,000 MiB
    • $0.1510/MiB: 100,000–250,000 MiB
    • $0.0610/MiB: above 250,000 MiB
    • Free
      • All GCP metrics
      • First 150 MiB per billing account
  • Monitoring API calls
    • $0.01/1,000 API calls
    • Free
      • First 1 million API calls

GCEのCPUなどのGCPが自動で出力するmetricsは無料なので、Monitoring AgentやCustom Metricsを使わない限りは、さほどお金はかからない

https://gcpug.jp

11 of 34

Stackdriver Loggingと

Error Reporting

https://gcpug.jp

12 of 34

What’s Stackdriver Logging

12

  • GCPのすべてのログを集約するサービス
  • Application Logだけでなく、Audit Logなども全部ここに出力される
  • App Engineなどは自動で出力されるGCE Instanceでは、Logging Agentをインストールする
    • Logging Agentはfluentdベース

https://gcpug.jp

13 of 34

Logging : Price

13

  • $0.50/GiB
    • First 50 GiB per project
  • 比較
    • BigQuery Streaming Insert
      • $0.050 per GiB
    • PubSub
      • $0.06 per GiB

GCPの中で最も高いと言ってもいいんじゃないかと思うぐらい高い!!

なので、リアルタイムに見る必要がないログは、除外設定とExportを組み合わせてBigQueryなどに退避しよう

https://gcpug.jp

14 of 34

ExportとIngestion

14

  • Export
    • Loggingを出力する機能
      • BigQuery Streaming Insert
      • Google Cloud Storage
      • Google Cloud Pub/Sub
  • Ingestion
    • Loggingのログ表示を除外する機能
    • 除外したログは課金対象にならない
    • 除外したログはExportには出力される

https://gcpug.jp

15 of 34

ExportとIngestion Demo

15

Exclusionsの設定はいつでもEnable/Dissbleを切り替えれるので、リリース時はDisableにしておいて、落ち着いたらEnableにすることも可能

Blogにも書いてあるので、見てみてね

https://gcpug.jp

16 of 34

16

  • ApplicationにErrorが発生した時に、通知される機能
    • 500 Error
    • Exception
    • Panic
  • 同じ種類のエラーのグルーピング
  • 解決済みなどのステータス管理

https://gcpug.jp

17 of 34

Stackdriver Error Reporting

17

https://gcpug.jp

18 of 34

Stackdriver Error Reporting

18

  • 通知先が少ないのが、ちょっと...
    • Email
    • Console Mobile App

https://gcpug.jp

19 of 34

Error Reporting : Price

19

  • 無料

https://gcpug.jp

20 of 34

Application Performance Management

https://gcpug.jp

21 of 34

21

  • Production環境を実際に計測することにより、パフォーマンス, 信頼性を高くするためには、何をすればよいかを知るぞ!というもの
  • クラウドではコンポーネントが多く、LocalにProduction環境と等価な状態を作成するのが難しいので、Production環境を計測するためのTool群が登場

https://gcpug.jp

22 of 34

22

  • Applicationの中でどこでどのぐらい時間がかかっているのかをトレースする仕組み
  • 分かれている複数のコンポーネントを呼ぶ時や、重たい計算処理などを行う時に、計測できる
    • 複数のコンポーネントをトレースすることを分散トレーシングと呼ぶ

Requestの中で、Datastore, Vision API, Functionを使っている時に、2秒かかっている。

この時、どこにどれだけ時間がかかっている?というのをトレースし続けることができる

https://gcpug.jp

23 of 34

Stackdriver Trace

23

  • 利用する場合はロジックに入れる
  • 任意のタイミングで計測することもできるし、HTTP Requestや、gRPCに挟むこともできる

レイテンシ計測したいところで、StartSpanする

func (d *dqnImpl) Prediction(ctx context.Context, body *Payload) (*Answer, error) {

ctx, span := trace.StartSpan(ctx, "/dqn")

defer span.End()

https://gcpug.jp

24 of 34

Stackdriver Trace

24

https://gcpug.jp

25 of 34

多段でトレースすることもできる

25

  • Trace IDを持ち回れば、多段でトレースすることもできる
  • App Engine
    • Function
      • Datastore
      • Storage
    • Datastore

App EngineのRequestのTraceIDをFunctionに渡せば、FunctionからのDatastore, Storageのアクセスも一緒に出てくる

https://gcpug.jp

26 of 34

Traceのタイミング

26

  • すべてをトレースしているわけではなく、サンプリングしている
  • リクエスト数が少ない時などはサンプリングされなくて、全く出力されないので、サンプリングレートを変更してあげる
    • 変更方法は ノウハウ#72 でわちゃわちゃ言ってたりする

https://gcpug.jp

27 of 34

Trace : Price

27

  • Trace ingestion
    • $0.20/million spans
    • Free
      • First 2.5 million spans
  • Trace spans scanned (予定されているだけで、まだ無料)
    • $0.02/million spans
    • Free
      • First 25 million spans

サンプリングして送られるので、ほとんど料金はかからない

https://gcpug.jp

28 of 34

28

  • Production環境にブレイクポイントを付けて、デバッグする仕組み
  • 実際にブレイクポイントでアプリケーションが止まっているわけではなくて、その瞬間のメモリのスナップショットを見せてくれる機能
  • ソースコード変更無しで、ログ出力を差し込む機能もある

sinmetalはソースコードをうまいこと噛み合わせる設定を入れるのがめんどうだなと思って、使ったことがない...

https://gcpug.jp

29 of 34

Debugger : Price

29

  • 無料

https://gcpug.jp

30 of 34

30

  • 関数ごとにCPU利用率, メモリ利用量をプロファイルする仕組み
  • 対応言語はまだ少なめ
    • Java
      • CPU, Wall
    • Go
      • CPU, Heap, Threads, Contention
    • Node.js
      • Wall, Heap

https://gcpug.jp

31 of 34

Stackdriver Profiler

31

https://gcpug.jp

32 of 34

Stackdriver Profiler

32

Goの場合は、アプリケーションの最初に呼ぶだけなので、導入はとっても簡単

func main() {

profiler.Start(profiler.Config{

Service: "myservice",

ServiceVersion: "1.0.0",

}

https://gcpug.jp

33 of 34

Profiler : Price

33

  • 無料

https://gcpug.jp

34 of 34

Thank you

GCPUG Slack #stackdriver

34

https://gcpug.jp