4.2. メトリクスのクラスター ID ラベルの作成
openshift-monitoring namespace の cluster-monitoring-config config map にリモート書き込みストレージ用の write_relabel 設定を追加することで、メトリクスのクラスター ID ラベルを作成できます。クラスター ID ラベルを追加すると、メトリクスを一意に識別し、クラスターとワークロード全体で一貫して追跡できます。
前提条件
-
cluster-adminクラスターロールを持つユーザーとしてクラスターにアクセスできる。 -
cluster-monitoring-configConfigMapオブジェクトを作成している。 -
OpenShift CLI (
oc) がインストールされている。 - リモート書き込みストレージを設定している。
手順
openshift-monitoringプロジェクトでcluster-monitoring-configconfig map を編集します。$ oc -n openshift-monitoring edit configmap cluster-monitoring-configdata/config.yaml/prometheusK8s/remoteWriteの下にあるwriteRelabelConfigs:セクションで、クラスター ID の再ラベル付け設定値を追加します。apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" <endpoint_authentication_credentials> writeRelabelConfigs:1 - <relabel_config>2 次のサンプルは、クラスター ID ラベル
cluster_idを使用してメトリクスを転送する方法を示しています。apiVersion: v1 kind: ConfigMap metadata: name: cluster-monitoring-config namespace: openshift-monitoring data: config.yaml: | prometheusK8s: remoteWrite: - url: "https://remote-write-endpoint.example.com" writeRelabelConfigs: - sourceLabels: - __tmp_openshift_cluster_id__1 targetLabel: cluster_id2 action: replace3 - 1
- システムは最初に
__tmp_openshift_cluster_id__という名前の一時的なクラスター ID ソースラベルを適用します。この一時的なラベルは、指定するクラスター ID ラベル名に置き換えられます。 - 2
- リモート書き込みストレージに送信されるメトリクスのクラスター ID ラベルの名前を指定します。メトリクスにすでに存在するラベル名を使用する場合、その値はこのクラスター ID ラベルの名前で上書きされます。ラベル名には
__tmp_openshift_cluster_id__は使用しないでください。最後の再ラベル手順では、この名前を使用するラベルを削除します。 - 3
replace置き換えラベルの再設定アクションは、一時ラベルを送信メトリクスのターゲットラベルに置き換えます。このアクションはデフォルトであり、アクションが指定されていない場合に適用されます。
- 変更を適用するためにファイルを保存します。新しい設定は自動的に適用されます。