[英]Issue with overriding labels in prometheus
我從掌舵安裝了穩定/普羅米修斯。 默認情況下,job_name kubernetes-service-endpoints
包含node-exporter
和kube-state-metrics
作為組件標簽。 我在 prometheus.yml 中添加了以下配置以包含命名空間、pod 和節點標簽。
- source_labels: [__meta_kubernetes_namespace]
separator: ;
regex: (.*)
target_label: namespace
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_pod_name]
separator: ;
regex: (.*)
target_label: pod
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_pod_node_name]
separator: ;
regex: (.*)
target_label: node
replacement: $1
action: replace
kube_pod_info{component="kube-state-metrics"}
已經有了命名空間、pod 和節點標簽,因此生成了導出的標簽。 並且度量node_cpu_seconds_total{component="node-exporter"}
現在正確地具有標簽命名空間、pod 和節點。
要正確使用這些標簽,我需要在上述兩個指標名稱中都包含這 3 個標簽。 為了實現這一點,我可以覆蓋exported_labels 的值。 我嘗試添加以下配置但無濟於事。
- source_labels: [__name__, exported_pod]
regex: "kube_pod_info;(.+)"
target_label: pod
- source_labels: [__name__, exported_namespace]
regex: "kube_pod_info;(.+)"
target_label: namespace
- source_labels: [__name__, exported_node]
regex: "kube_pod_info;(.+)"
target_label: node
這里提到了類似的方法。 我看不到我的一段代碼的問題。 任何解決方向都會非常有幫助。
更新 - (添加完整的工作)
- job_name: kubernetes-service-endpoints
kubernetes_sd_configs:
- role: endpoints
metric_relabel_configs:
- source_labels: [__name__, exported_pod]
regex: "kube_pod_info;(.+)"
target_label: pod
- source_labels: [__name__, exported_namespace]
regex: "kube_pod_info;(.+)"
target_label: namespace
- source_labels: [__name__, exported_node]
regex: "kube_pod_info;(.+)"
target_label: node
relabel_configs:
- action: keep
regex: true
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_scrape
- action: replace
regex: (https?)
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_scheme
target_label: __scheme__
- action: replace
regex: (.+)
source_labels:
- __meta_kubernetes_service_annotation_prometheus_io_path
target_label: __metrics_path__
- action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
source_labels:
- __address__
- __meta_kubernetes_service_annotation_prometheus_io_port
target_label: __address__
- action: labelmap
regex: __meta_kubernetes_service_label_(.+)
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: namespace
- action: replace
regex: (.*)
replacement: $1
separator: ;
source_labels:
- __meta_kubernetes_pod_name
target_label: pod
- action: replace
source_labels:
- __meta_kubernetes_pod_node_name
target_label: node
promql 的結果
所以,你的目標是重新命名的度量標准標簽exported_pod
至pod
等,為kube_pod_info
指標?
在這種情況下,您需要在從目標中獲取指標時進行指標重新標記:
- job_name: 'kubernetes-service-endpoints'
kubernetes_sd_configs:
- role: endpoints
metric_relabel_configs:
- source_labels: [__name__, exported_pod]
regex: "kube_pod_info;(.+)"
target_label: pod
- source_labels: [__name__, exported_namespace]
regex: "kube_pod_info;(.+)"
target_label: namespace
- source_labels: [__name__, exported_node]
regex: "kube_pod_info;(.+)"
target_label: node
relabel_configs:
# Insert the same what you have so far
背景:
正常重新標記( relabel_configs
) 在服務發現時應用於服務發現過程自動發現的目標標簽。 它定義了明確的目標標簽。 在抓取時,目標標簽會添加到來自目標的所有指標的指標標簽中。 正常的重新標記只能用於在服務發現后處理目標的標簽,這些標簽通常是以__
開頭的元標簽。
指標重新標記( metric_relabel_configs
) 在抓取時應用於指標標簽。 因此,這可用於重命名由公開指標本身的應用程序定義的標簽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.