使用Prometheus监控自定义kubernetes pod指标 [英] Monitor custom kubernetes pod metrics using Prometheus

查看:1027
本文介绍了使用Prometheus监控自定义kubernetes pod指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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.yamlkubernetes-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆