将 promethus `job` 标签从 `kubelet` 更改为 `kubernetes-cadvisor`
Posted
技术标签:
【中文标题】将 promethus `job` 标签从 `kubelet` 更改为 `kubernetes-cadvisor`【英文标题】:Changing promethus `job` label from `kubelet` to `kubernetes-cadvisor` 【发布时间】:2021-04-01 05:27:06 【问题描述】:我正在使用 Google Kubernetes Engine 集群,我希望我的 VerticalPodAutoscalers
到 use Prometheus as a history provider。
说明说:
配置您的 Prometheus 以从 cadvisor 获取指标。确保来自 cadvisor 的指标具有标签 job=kubernetes-cadvisor。
我正在使用 kube-prometheus-stack 图表通过 Helm 在我的集群上安装 Prometheus。
此图表中cadvisor
指标的默认job
标签似乎是job='kubelet
;
我正在查看source code for the chart,但我不明白如何操纵图表值将工作标签更改为kubernetes-cadvisor
。这样做的正确方法是什么?
在我的 Prometheus 配置下,我能找到的唯一提及 cadvisor
的是:
- job_name: monitoring/prometheus-operator-kubelet/1
honor_labels: true
honor_timestamps: true
scrape_interval: 30s
scrape_timeout: 10s
metrics_path: /metrics/cadvisor
scheme: https
kubernetes_sd_configs:
- role: endpoints
namespaces:
names:
- kube-system
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
insecure_skip_verify: true
relabel_configs:
- source_labels: [__meta_kubernetes_service_label_k8s_app]
separator: ;
regex: kubelet
replacement: $1
action: keep
- source_labels: [__meta_kubernetes_endpoint_port_name]
separator: ;
regex: https-metrics
replacement: $1
action: keep
- source_labels: [__meta_kubernetes_endpoint_address_target_kind, __meta_kubernetes_endpoint_address_target_name]
separator: ;
regex: Node;(.*)
target_label: node
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_endpoint_address_target_kind, __meta_kubernetes_endpoint_address_target_name]
separator: ;
regex: Pod;(.*)
target_label: pod
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_namespace]
separator: ;
regex: (.*)
target_label: namespace
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_service_name]
separator: ;
regex: (.*)
target_label: service
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_pod_name]
separator: ;
regex: (.*)
target_label: pod
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_service_name]
separator: ;
regex: (.*)
target_label: job
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_service_label_k8s_app]
separator: ;
regex: (.+)
target_label: job
replacement: $1
action: replace
- separator: ;
regex: (.*)
target_label: endpoint
replacement: https-metrics
action: replace
- source_labels: [__metrics_path__]
separator: ;
regex: (.*)
target_label: metrics_path
replacement: $1
action: replace
【问题讨论】:
【参考方案1】:将以下值传递给 Helm:
kubelet:
serviceMonitor:
cAdvisor: false
# Add a scrape job for cAdvisor in accordance with the Prometheus docs
prometheus:
prometheusSpec:
additionalScrapeConfigs:
- job_name: 'kubernetes-cadvisor'
scheme: https
metrics_path: /metrics/cadvisor
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
kubernetes_sd_configs:
- role: node
relabel_configs:
- action: labelmap
regex: __meta_kubernetes_node_label_(.+)
【讨论】:
这对我有帮助 - 谢谢! - 但我现在似乎有一个新问题:捆绑的 Grafana 仪表板中的一些图表现在已损坏。进行此更改后,您是否也遇到过这种情况? 不抱歉。您是否在 grafana 中运行了任何自定义配置,或者 kube-prometheus-stack 附带的默认配置会损坏? 这只是 kube-prometheus-stack 附带的默认值。大多数图表仍然有效,但与 CPU 指标相关的图表似乎停止接收数据 我提出了一个新问题:***.com/questions/69406120/…以上是关于将 promethus `job` 标签从 `kubelet` 更改为 `kubernetes-cadvisor`的主要内容,如果未能解决你的问题,请参考以下文章