このページでは、Google Distributed Cloud(GDC)エアギャップ環境のワークロードから指標をスクレイピングして、モニタリングとデータの可観測性を向上させるプロセスについて説明します。
コンポーネントが生成する指標をスクレイピングして、経時的に収集できます。モニタリング プラットフォームには、Distributed Cloud プロジェクト Namespace 内で実行中のワークロードから指標をスクレイピングするためのカスタム API が用意されています。指標をスクレイピングするには、Management API サーバーのプロジェクト Namespace に MonitoringTarget カスタム リソースをデプロイします。このリソースをデプロイすると、モニタリング プラットフォームがデータの収集を開始します。
MonitoringTarget カスタム リソースは、プロジェクト内の指定された Pod をスクレイピングするようにモニタリング パイプラインに指示します。これらの Pod は、OpenMetrics などの Prometheus 表示形式で指標を提供する HTTP エンドポイントを公開する必要があります。
スクレイピングされた指標は、プロジェクトの Grafana インスタンスに表示され、アプリケーションの運用状態に関する分析情報を提供します。
MonitoringTarget カスタム リソースを構成するには、指標収集のプロジェクト Namespace 内の Pod を指定する必要があります。スクレイピング頻度、Pod の指標エンドポイント、ラベル、アノテーションなど、さまざまな設定をカスタマイズできます。
始める前に
MonitoringRule カスタム リソースを管理するには、管理者から必要な権限をリクエストしてください。
必要な IAM のロール
次のロールをリクエストするには、プロジェクト IAM 管理者にお問い合わせください。
- MonitoringRule 作成者 (
monitoringrule-creator): プロジェクト Namespace にMonitoringRuleカスタム リソースを作成します。 - MonitoringRule 編集者 (
monitoringrule-editor): プロジェクト Namespace のMonitoringRuleカスタム リソースを編集または変更します。 - MonitoringRule 閲覧者 (
monitoringrule-viewer): プロジェクト Namespace のMonitoringRuleカスタム リソースを表示します。
MonitoringTarget カスタム リソースを構成する
MonitoringTarget カスタム リソースは、モニタリング プラットフォームに指標の収集元を通知します。指標を収集する Pod、それらの Pod の指標エンドポイント、スクレイピング頻度、その他の設定を指定できます。
このリソースは、次の構成を定義します。
- ターゲット: 指標を公開するプロジェクト内の Pod とそのエンドポイント。
- スクレイピング間隔: 選択した エンドポイントから指標をプルする頻度。
- ラベルのカスタマイズ: 指標のラベル変更を含む省略可能なルール。
MonitoringTarget カスタム リソースで指標エンドポイントを指定するには、次のいずれかの方法を選択します。
- 静的エンドポイント:
MonitoringTarget構成でエンドポイント(ポート、 パス、スキーム)を明示的に宣言します。 アノテーション: Pod 指標エンドポイント情報は、コンテナの
Deploymentファイル内の アノテーションから取得されます。この方法は、Pod ごとに異なるエンドポイントがある場合に柔軟に対応できます。
静的エンドポイント
静的に定義されたエンドポイントで、選択した Pod から指標を公開する手順は次のとおりです。
モニタリング用の指標を収集する Distributed Cloud プロジェクトを決定します。
Pod の仕様で、指標を提供するポートを
containerPortフィールドで宣言します。次の例は、Pod の仕様でポート2112を宣言する方法を示しています。# ... spec: template: spec: containers: - name: your-container-name ports: - containerPort: 2112 # ...MonitoringTarget構成で、Pod の仕様で公開したポートと一致するように、podMetricsEndpointsセクションでエンドポイントの詳細(ポート、パス、スキーム)を指定します。次の YAML ファイルは、選択したすべての Pod が同じエンドポイント
http://your-container-name:2112/metricsで指標を公開する必要があるMonitoringTarget構成の例を示しています。apiVersion: monitoring.gdc.goog/v1 kind: MonitoringTarget metadata: # Choose the same namespace as the workload pods. namespace: your-project-namespace name: your-container-name spec: selector: # Choose pod labels to consider for this job. # Optional: Map of key-value pairs. # Default: No filtering by label. # To consider every pod in the project namespace, remove selector fields. matchLabels: app: your-app-label podMetricsEndpoints: port: value: 2112 path: # Choose any value for your endpoint. # The /metrics value is an example. value: /metrics scheme: value: httpターゲット Pod と同じ Namespace 内の Management API サーバーに
MonitoringTarget構成を適用します。kubectl --kubeconfig KUBECONFIG_PATH apply -f MONITORING_TARGET_NAME.yaml次のように置き換えます。
KUBECONFIG_PATH: Management API サーバーの kubeconfig ファイルのパス。MONITORING_TARGET_NAME:MonitoringTarget定義ファイルの名前。
モニタリング プラットフォームが指標の収集を開始します。
アノテーション
Pod ごとに異なるエンドポイントがある場合は、次の手順でアノテーションを使用して指標を公開します。
モニタリング用の指標を収集する Distributed Cloud プロジェクトを決定します。
コンテナの
Deploymentファイルのannotationsセクションに次のアノテーションを追加します。prometheus.io/pathprometheus.io/portprometheus.io/scheme
次の例は、ポート
2112の指標のアノテーションを示しています。apiVersion: apps/v1 kind: Deployment metadata: name: your-container-name namespace: your-project-namespace labels: app: your-app-label annotations: # These annotations are not required. They demonstrate selecting # pod metric endpoints through annotations. prometheus.io/path: /metrics prometheus.io/port: \"2112\" prometheus.io/scheme: httpMonitoringTarget構成で、コンテナのDeploymentファイルに追加したアノテーションをpodMetricsEndpointsセクションで指定します。この指定により、カスタム リソースは、選択した Pod のアノテーションから指標エンドポイント情報を収集します。次の YAML ファイルは、アノテーションを使用する
MonitoringTarget構成の例を示しています。apiVersion: monitoring.gdc.goog/v1 kind: MonitoringTarget metadata: metadata: # Choose the same namespace as the workload pods. namespace: your-project-namespace name: your-container-name spec: selector: matchLabels: app: your-app-label podMetricsEndpoints: port: annotation: prometheus.io/port path: annotation: prometheus.io/path scheme: annotation: prometheus.io/schemeターゲット Pod と同じ Namespace 内の Management API サーバーに
MonitoringTarget構成を適用します。kubectl --kubeconfig KUBECONFIG_PATH apply -f MONITORING_TARGET_NAME.yaml次のように置き換えます。
KUBECONFIG_PATH: Management API サーバーの kubeconfig ファイルのパス。MONITORING_TARGET_NAME:MonitoringTarget定義ファイルの名前。
モニタリング プラットフォームが指標の収集を開始します。
追加のフィールドとオプションについては、完全な MonitoringTarget 仕様
と API リファレンス ドキュメント
をご覧ください。
MonitoringTarget の完全な仕様
次の YAML ファイルは、MonitoringTarget カスタム リソースの完全な仕様の例を示しています。詳細とフィールドの完全な
説明については、
API リファレンス ドキュメントをご覧ください。
apiVersion: monitoring.gdc.goog/v1
kind: MonitoringTarget
metadata:
# Choose the same namespace as the workload pods.
namespace: PROJECT_NAMESPACE
name: MONITORING_TARGET_NAME
spec:
# Choose matching pattern that identifies pods for this job.
# Optional
# Relationship between different selectors: AND
selector:
# Choose clusters to consider for this job.
# Optional: List
# Default: All clusters applicable to this project.
# Relationship between different list elements: OR
matchClusters:
- string
# Choose pod labels to consider for this job.
# Optional: Map of key-value pairs.
# Default: No filtering by label.
# Relationship between different pairs: AND
matchLabels:
key1: value1
# Choose annotations to consider for this job.
# Optional: Map of key-value pairs
# Default: No filtering by annotation
# Relationship between different pairs: AND
matchAnnotations:
key1: value1
# Configure the endpoint exposed for this job.
podMetricsEndpoints:
# Choose a port either through static value or annotation.
# Optional
# Annotation takes priority.
# Default: static port 80
port:
value: integer
annotation: string
# Choose a path either through static value or annotation.
# Optional
# Annotation takes priority
# Default: static path /metrics
path:
value: string
annotation: string
# Choose a scheme either through a static value (http or https) or annotation.
# Optional
# Annotation takes priority
# Default: static scheme http
scheme:
value: string
annotation: string
# Choose the frequency to scrape the metrics endpoint defined in podMetricsEndpoints
# Optional
# Default: 60s
scrapeInterval: string
# Dynamically rewrite the label set of a target before it gets scraped.
# https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
# Optional
# Default: No filtering by label
metricsRelabelings:
- sourceLabels:
- string
separator: string
regex: string
action: string
targetLabel: string
replacement: string
次のように置き換えます。
PROJECT_NAMESPACE: プロジェクト Namespace。MONITORING_TARGET_NAME:MonitoringTarget定義ファイルの名前。