このページでは、モニタリングとデータのオブザーバビリティを容易にするために、Google Distributed Cloud(GDC)エアギャップ環境のワークロードから指標をスクレイピングするプロセスの概要について説明します。
コンポーネントが生成する指標をスクレイピングして収集できます。モニタリング プラットフォームには、Distributed Cloud プロジェクトの名前空間内で実行中のワークロードから指標をスクレイピングするためのカスタム API が用意されています。指標をスクレイピングするには、Management API サーバーのプロジェクト Namespace に MonitoringTarget カスタム リソースをデプロイします。このリソースをデプロイすると、モニタリング プラットフォームがデータの収集を開始します。
MonitoringTarget カスタム リソースは、プロジェクト内の指定された Pod をスクレイピングするようにモニタリング パイプラインに指示します。これらの Pod は、OpenMetrics などの Prometheus 表示形式で指標を配信する HTTP エンドポイントを公開する必要があります。スクレイピングされた指標は、プロジェクトの Grafana インスタンスに表示され、アプリケーションの運用状態に関する分析情報を提供します。
MonitoringTarget カスタム リソースを構成するには、指標を収集するプロジェクトの名前空間内の Pod を指定する必要があります。スクレイピングの頻度、Pod の指標エンドポイント、ラベル、アノテーションなど、さまざまな設定をカスタマイズできます。
始める前に
MonitoringRule カスタム リソースを管理するには、必要な権限を管理者にリクエストしてください。
必要な IAM のロール
IAM プロジェクト管理者に連絡して、次のロールをリクエストしてください。
- MonitoringRule 作成者(
monitoringrule-creator): プロジェクトの名前空間にMonitoringRuleカスタム リソースを作成します。 - MonitoringRule 編集者(
monitoringrule-editor): プロジェクトの名前空間でMonitoringRuleカスタム リソースを編集または変更します。 - MonitoringRule 閲覧者(
monitoringrule-viewer): プロジェクトの名前空間にあるMonitoringRuleカスタム リソースを表示します。
MonitoringTarget カスタム リソースを構成する
MonitoringTarget カスタム リソースは、指標の収集元をモニタリング プラットフォームに指示します。指標を収集する Pod、それらの Pod の指標エンドポイント、スクレイピング頻度、その他の設定を指定できます。
このリソースでは、次の構成を定義します。
- ターゲット: 指標を公開するプロジェクト内の Pod とそのエンドポイント。
- スクレイピング間隔: 選択したエンドポイントから指標を pull する頻度。
- ラベルのカスタマイズ: 指標のラベル変更を含むオプションのルール。
MonitoringTarget カスタム リソースで指標エンドポイントを指定するには、次のいずれかの方法を選択します。
- 静的エンドポイント:
MonitoringTarget構成でエンドポイント(ポート、パス、スキーム)を明示的に宣言します。 アノテーション: Pod 指標エンドポイント情報は、コンテナの
Deploymentファイル内のアノテーションから取得されます。各 Pod に異なるエンドポイントがある場合、この方法の方が柔軟性が高くなります。
静的エンドポイント
静的に定義されたエンドポイントで、選択した Pod の指標を公開する手順は次のとおりです。
モニタリング用の指標を収集する Distributed Cloud プロジェクトを決定します。
Pod の仕様で、指標を提供するポートを
containerPortフィールドで宣言します。次の例は、Pod の仕様でポート2112を宣言する方法を示しています。# ... spec: template: spec: containers: - name: your-container-name ports: - containerPort: 2112 # ...MonitoringTarget構成のpodMetricsEndpointsセクションで、Pod の仕様で公開したポートと一致するようにエンドポイントの詳細(ポート、パス、スキーム)を指定します。次の 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: プロジェクトの名前空間。MONITORING_TARGET_NAME:MonitoringTarget定義ファイルの名前。