繁体   English   中英

普罗米修斯只刮一个豆荚

[英]Prometheus only scrapes one pod

我正在使用Prometheus从我的广告连播中抓取指标。 我感兴趣的应用程序通过提供访问权限的一项服务被复制了两次。 Prometheus使用此服务来抓取指标。 在我的应用中,指标设置如下:

import * as Prometheus from 'prom-client';

const httpRequestDurationMicroseconds = new Prometheus.Histogram({
    name: 'transaction_amounts',
    help: 'Amount',
    labelNames: ['amount'],
    buckets: [0, 5, 15, 50, 100, 200, 300, 400, 500, 10000],
});

const totalPayments = new Prometheus.Counter('transaction_totals', 'Total payments');

我正在使用Helm安装Prometheus,并且scrape配置看起来像这样:

prometheus.yml:
  rule_files:
    - /etc/config/rules
    - /etc/config/alerts

  scrape_configs:
    - job_name: prometheus
      static_configs:
        - targets:
          - localhost:9090
    - job_name: transactions
      scrape_interval: 1s
      static_configs:
        - targets:
          - transaction-metrics-service:3001

我可以看到普罗米修斯内部的指标,但它似乎仅来自一个Pod。 例如,在Prometheus中,当我查询transaction_totals它给出:

在此处输入图片说明

我认为instance标签不能唯一标识我的豆荚。 我应该怎么做才能查询所有吊舱?

可以使用Prometheus提供的kubernetes_sd_configs Kubernetes Service Discovery,而不是使用仅刮刮一台主机的static_config 您的配置文件如下所示:

- job_name: 'kubernetes-pods'

  kubernetes_sd_configs:
  - role: pod

  relabel_configs:
  # only scrape when annotation prometheus.io/scrape: 'true' is set
  - 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

然后将注释添加到您的Kubernetes部署yaml配置中,如下所示:

kind: Deployment

...

spec:
  template:
    metadata:
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "<< PORT OF YOUR CONTAINER >>"

您可以在此处看到完整的工作示例

将prometheus批注添加到您的服务中,因为舞会只会刮擦以下服务:

  • 暴露出口港
  • 有一个prometheus.io/scrape: "true"注释
  • 具有prometheus.io/port: "<exporter_port_here>"批注

这是一个官方的例子

刮掉的豆荚本身可能就是普罗米修斯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM