モニタリング指標の報告

このページでは、Service Infrastructure を使用してマネージド サービスがモニタリング データを生成できるようにする方法について説明します。このモニタリング データは、サービス プロデューサー プロジェクトとサービス ユーザー プロジェクトに送信されます。モニタリングにより、個々のマネージド サービスのパフォーマンスやアップタイム、全体的な動作状況を可視化できます。

Service Control API は指標を受け入れ、それをバッチ処理して Cloud Monitoring に転送します。Monitoring では、これらの指標を取り込み、ダッシュボード、チャート、アラートで分析情報を提供します。

Monitoring のみを使用する場合、マネージド サービスはマネージド サービスのデベロッパーを対象としたモニタリング データを生成します。一方、Service Control API ではユーザーを対象としたモニタリング データも生成できます。これにより、ユーザーがマネージド サービスの使用状況を理解し、診断できるようになります。

このガイドは、マネージド サービスで定義されているモニタリング指標を対象としていることに注意してください。モニタリング カスタム指標は、Service Control API を介して報告できません。カスタム指標を報告するには、モニタリング ガイドに従う必要があります。

モニタリングの構成

モニタリング データを Service Control API に送信する前に、サービス構成で 3 種類の情報を指定する必要があります。

  • モニタリング対象リソース: モニタリング対象リソースは、モニタリング データを作成するクラウド エンティティを表します。サービス構成でモニタリング対象リソースを定義するには、技術仕様用の monitored_resource.proto をご覧ください。モニタリングとロギングの両方に同じモニタリング対象リソースを使用することを強くおすすめします。

  • 指標: 1 つ以上の指標を報告できます。各指標は単一の状態を表し、その値が経時的にトラッキングされます。指標を定義するには、技術仕様用の metric.proto をご覧ください。

  • モニタリング構成: 個々のモニタリング対象リソースに関連付けられている指標と、各指標を送信するサービス プロデューサー プロジェクトまたはサービス ユーザー プロジェクトを指定できます。詳細については、monitoring.proto をご覧ください。

次のサービス構成の例では、モニタリング対象リソースと指標を定義しています。

# The definition of the monitored resource to be used.
monitored_resources:
- type: library.appspot.com/Branch
  description: A library branch.
  display_name: Library Branch
  launch_stage: ALPHA
  labels:
  - key: resource_container
    description: The Google Cloud resource container (ie. project id) for
    the branch.
  - key: location
    description: The Google Cloud region the branch is located.
  - key: branch_id
    description: The ID of the branch.

# The definition of the metrics to be used.
metrics:
- name: library.appspot.com/book/num_overdue
  display_name: Books Overdue
  description: The current number of overdue books.
  launch_stage: ALPHA
  metric_kind: GAUGE
  value_type: INT64
  unit: 1
- name: library.googleapis.com/book/returned_count
  display_name: Books Returned
  description: The count of books that have been returned.
  launch_stage: ALPHA
  metric_kind: DELTA
  value_type: INT64
  unit: 1

# The monitoring configuration.
monitoring:
  producer_destinations:
  - monitored_resource: library.appspot.com/Branch
    metrics:
    - library.googleapis.com/book/returned_count
  consumer_destinations:
  - monitored_resource: library.appspot.com/Branch
    metrics:
    - library.appspot.com/book/num_overdue

このような構成を作成したら、サービス構成の管理サービス ロールアウトの管理に従って、サービス構成を、Cloud Monitoring でモニタリング対象リソースと指標の定義を構成する Service Management API に push します。

指標の報告

サービス構成の push が完了したら、Service Control API を呼び出して指標を報告できます。次の例は、gcurl コマンドを使用した呼び出しを示しています。この設定方法については、Service Control API スタートガイドをご覧ください。

gcurl -d "{
  'operations': [ {
    'operationId': '8356d3c5-f9b5-4274-b4f9-079a3731e6e5',
    'operationName': 'Return books',
    'consumerId': 'projects/library-consumer',
    'startTime': '`date +%FT%T%:z`',
    'endTime': '`date +%FT%T%:z --date="5 seconds"`',
    'labels': {
      'location': 'us-east1',
      'branch_id': 'my-test-library-branch'
    },
    'metricValueSets': [ {
      'metricName': 'library.googleapis.com/book/returned_count',
      'metricValues': [ { 'int64Value': '23' } ]
    } ]
  } ]
}" https://servicecontrol.googleapis.com/v1/services/endpointsapis.appspot.com:report