Google Distributed Cloud(GDC)エアギャップ アプライアンスを使用すると、ワークロードから指標をスクレイピングして収集し、アプリケーションのパフォーマンスをモニタリングしてデータのオブザーバビリティを維持できます。指標の収集を開始するには、Management API サーバーのプロジェクト Namespace に MonitoringTarget カスタム リソースをデプロイします。
MonitoringTarget カスタム リソースは、Prometheus の公開形式(OpenMetrics など)で HTTP エンドポイントを公開する指定された Pod をスクレイピングするようにモニタリング パイプラインに指示します。ターゲット Pod のスクレイピング頻度、エンドポイント設定、ラベル、アノテーションをカスタマイズできます。プロジェクトの Grafana インスタンスには、収集された指標が表示され、アプリケーションの運用状態を分析できます。
始める前に
MonitoringTarget カスタム リソースを管理するには、必要な権限を管理者にリクエストしてください。
必要な IAM のロール
プロジェクトの IAM 管理者に連絡して、次のロールをリクエストしてください。
- MonitoringTarget 作成者(
monitoringtarget-creator): プロジェクトの名前空間にMonitoringTargetカスタム リソースを作成します。 - MonitoringTarget 編集者(
monitoringtarget-editor): プロジェクトの名前空間でMonitoringTargetカスタム リソースを編集または削除します。 - MonitoringTarget 閲覧者(
monitoringtarget-viewer): プロジェクトの名前空間にあるMonitoringTargetカスタム リソースを表示します。
MonitoringTarget カスタム リソースを構成する
MonitoringTarget カスタム リソースは、指標の収集元をモニタリング プラットフォームに指示します。指標を収集する Pod、それらの Pod の指標エンドポイント、スクレイピング頻度、その他の設定を指定できます。
このリソースでは、次の構成を定義します。
- ターゲット: 指標を公開するプロジェクト内の Pod とそのエンドポイント。
- スクレイピング間隔: 選択したエンドポイントから指標を pull する頻度。
- ラベルのカスタマイズ: 指標のラベル変更を含むオプションのルール。
MonitoringTarget カスタム リソースで指標エンドポイントを指定するには、次のいずれかの方法を選択します。
- 静的エンドポイント:
MonitoringTarget構成でエンドポイント(ポート、パス、スキーム)を明示的に宣言します。 アノテーション: Pod 指標エンドポイント情報は、コンテナの
Deploymentファイル内のアノテーションから取得されます。各 Pod に異なるエンドポイントがある場合、この方法の方が柔軟性が高くなります。
静的エンドポイント
静的に定義されたエンドポイントで、選択した Pod の指標を公開する手順は次のとおりです。
モニタリング用の指標を収集する GDC エアギャップ アプライアンス プロジェクトを決定します。
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 に異なるエンドポイントがある場合に、アノテーションを使用して指標を公開する手順は次のとおりです。
モニタリング用の指標を収集する GDC エアギャップ アプライアンス プロジェクトを決定します。
コンテナの
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定義ファイルの名前。