【问题标题】:How to scrape pod level info using prometheus kubernetes?如何使用 prometheus kubernetes 抓取 pod 级别信息?
【发布时间】:2017-06-03 04:57:00
【问题描述】:

我正在尝试使用 prometheus kubernetes 抓取 pod 级别信息。这是我正在使用的配置:

 - job_name: 'kubernetes-pods'

  kubernetes_sd_configs:
  - api_servers:
    - 'https://kubernetes.default'
    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_pod_namespace]
    action: replace
    target_label: kubernetes_namespace
  - source_labels: [__meta_kubernetes_pod_name]
    action: replace
    target_label: kubernetes_pod_name

但我没有看到有关 grafana 的任何信息。我需要对我的应用程序进行任何更改吗? snapshot

【问题讨论】:

标签: kubernetes prometheus kubernetes-health-check


【解决方案1】:

使用该配置,第一个操作要求使用 prometheus.io/scrape=true 注释 pod。您是否在相关 pod 上设置了该注释?

【讨论】:

  • 是的,我已经设置了注释。我还有什么需要做的吗?
  • 从pod(app)的角度来看,除了设置annotation,我还需要发布任何数据或metrics吗?
  • 您的应用程序需要通过 HTTP(通常通过客户端库)以 Prometheus 格式公开数据。 Prometheus 无法从零中提取数据。
【解决方案2】:

注意,

这里有一个配置错误: __meta_kubernetes_pod_namespace 不存在,应该是 __meta_kubernetes_namespace

最好的问候,

巴特

【讨论】:

    【解决方案3】:

    您应该确保您的 Grafana 图表使用的数据实际存在于 Prometheus 中。

    我假设您使用的是默认的Grafana dashboard

    您的 Grafana 查询可能如下所示:

    sum (container_memory_working_set_bytes{pod_name=~"^$Pod$"}) / sum (machine_memory_bytes{kubernetes_io_hostname=~"^$Node$"}) * 100
    

    因此,您必须确保记录了 container_memory_working_set_bytes 指标并且它有一个字段 pod_name

    如果没有记录该指标,您必须在 prometheus 的日志中进行一些挖掘,以检查它是否能够抓取 API。

    如果指标存在但标签错误,您可以在 Grafana 中调整查询或在 Prometheus 中添加另一个 relabel_config。见official documentation

    【讨论】:

    • 我看到x.x.x.x:9090/targets,kuberneted-pods下,有个错误Get x.x.x.x:9100/metrics: dial tcp x.x.x.x:9100: getsockopt: connection denied。所以它甚至无法抓取数据
    • 然后检查您的 prometheus pod 的日志并尝试解决可能的错误。对我来说,这是错误的凭据,如下所述:github.com/kubernetes/dashboard/issues/374
    • 您找到解决方案了吗?
    • 到目前为止,我正在使用 cadvisor 获取 pod 级别的信息,例如内存使用情况和 cpu 使用情况。还实现了该应用程序以公开普罗米修斯抓取的一些指标。
    • @nocturnal 你用注释代替标签了吗?
    猜你喜欢
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-27
    相关资源
    最近更新 更多