Prometheus の公式ドキュメントには、metric_relabel_configs の完全な使用方法が記載されています。この Topic では、以下の一般的なシナリオの例を紹介します。
不要なメトリックの削除
特定のラベルの追加
不要なラベルの削除
不要なメトリックの削除
構成例は次のとおりです。
scrape_configs:
- job_name: "customJob_name1"
...
relabel_configs:
...
metric_relabel_configs:
- source_labels: [__name__]
action: drop
regex: 'pre1_.*' # customJob_name1 によってスクレイピングされた "pre1_" プレフィックスを持つすべてのメトリックを削除します。
- source_labels: [__name__]
action: drop
regex: 'metric_name1' # customJob_name1 によってスクレイピングされた "metric_name1" という名前のメトリックを削除します。 特定のラベルの追加
構成例は次のとおりです。
scrape_configs:
- job_name: "customJob_name1"
...
relabel_configs:
...
metric_relabel_configs:
# customJob_name1 によってスクレイピングされたすべてのメトリックに、値が "label_value1" のラベル "new_label1" を追加します。
- regex: (.*)
target_label: new_label1
replacement: label_value1
separator: ;
action: replace 不要なラベルの削除
構成例は次のとおりです。
scrape_configs:
- job_name: "customJob_name1"
...
relabel_configs:
...
metric_relabel_configs:
- regex: 'pre1_.*' # customJob_name1 によってスクレイピングされたすべてのメトリックから、"pre1_" プレフィックスを持つすべてのラベルを削除します。
action: labeldrop