使用Prometheus监控自定义kubernetes pod指标 [英] Monitor custom kubernetes pod metrics using Prometheus
问题描述
我正在使用Prometheus监视我的Kubernetes集群.我在单独的命名空间中设置了Prometheus.我有多个名称空间,并且有多个Pod正在运行.每个容器容器在此终点:80/data/metrics
处公开自定义指标.我正在获取Pods CPU,内存指标等,但是如何配置Prometheus从每个可用Pod中的:80/data/metrics
中提取数据?我已使用本教程来设置Prometheus,链接
I am using Prometheus to monitor my Kubernetes cluster. I have set up Prometheus in a separate namespace. I have multiple namespaces and multiple pods are running. Each pod container exposes a custom metrics at this end point, :80/data/metrics
. I am getting the Pods CPU, memory metrics etc, but how to configure Prometheus to pull data from :80/data/metrics
in each available pod ? I have used this tutorial to set up Prometheus, Link
推荐答案
您必须将这三个注释添加到您的广告连播中:
You have to add this three annotation to your pods:
prometheus.io/scrape: 'true'
prometheus.io/path: '/data/metrics'
prometheus.io/port: '80'
它将如何工作?
查看您用于配置Prometheus的config-map.yaml
的kubernetes-pods
作业,
Look at the kubernetes-pods
job of config-map.yaml
you are using to configure prometheus,
- job_name: 'kubernetes-pods'
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
target_label: __address__
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: kubernetes_namespace
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: kubernetes_pod_name
检查这三个重新标记的配置
Check this three relabel configuration
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
target_label: __address__
此处,__metrics_path__
和port
,以及是否从该窗格中删除指标,正在从窗格注释中读取.
Here, __metrics_path__
and port
and whether to scrap metrics from this pod are being read from pod annotations.
有关如何配置Prometheus的更多详细信息,请参见此处.
For, more details on how to configure Prometheus see here.
这篇关于使用Prometheus监控自定义kubernetes pod指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!