简体   繁体   English

Prometheus:在 Prometheus 中找不到 pod 的指标

[英]Prometheus: Metric from pod not found in Prometheus

I am currently running metrics server inside my pod.我目前正在 Pod 中运行指标服务器。 The data is being sent inside pod at localhost:9090.数据在 localhost:9090 的 pod 内发送。 I am able to get the data inside pod via curl. The deployment.yaml is annotated to scrape the data, but I don't see any new metrics in pod.我可以通过 curl 获取 pod 内的数据。deployment.yaml 被注释为抓取数据,但我没有在 pod 中看到任何新指标。 What am I doing wrong?我究竟做错了什么?

metrics I see inside pod:我在 pod 中看到的指标:

cpu_usage{process="COMMAND", pid="PID"} %CPU
cpu_usage{process="/bin/sh", pid="1"} 0.0
cpu_usage{process="sh", pid="8"} 0.0
cpu_usage{process="/usr/share/filebeat/bin/filebeat-god", pid="49"} 0.0
cpu_usage{process="/usr/share/filebeat/bin/filebeat", pid="52"} 0.0
cpu_usage{process="php-fpm:", pid="66"} 0.0
cpu_usage{process="php-fpm:", pid="67"} 0.0
cpu_usage{process="php-fpm:", pid="68"} 0.0
cpu_usage{process="nginx:", pid="69"} 0.0
cpu_usage{process="nginx:", pid="70"} 0.0
cpu_usage{process="nginx:", pid="71"} 0.0
cpu_usage{process="/bin/sh", pid="541"} 0.0
cpu_usage{process="bash", pid="556"} 0.0
cpu_usage{process="/bin/sh", pid="1992"} 0.0
cpu_usage{process="ps", pid="1993"} 0.0
cpu_usage{process="/bin/sh", pid="1994"} 0.0

deployment.yaml部署.yaml

  template: 
    metadata:
      labels: 
        app: supplier-service
      annotations:
        prometheus.io/path: /
        prometheus.io/scrape: 'true'
        prometheus.io/port: '9090'



          ports: 
            - containerPort: 80
            - containerPort: 443
            - containerPort: 9090

prometheus.yml普罗米修斯.yml

global:
  scrape_interval: 15s # By default, scrape targets every 15seconds. # Attach these labels to any time series or alerts when #communicating with external systems (federation, re$
  external_labels:
    monitor: 'codelab-monitor'
# Scraping Prometheus itself
scrape_configs:
- job_name: 'prometheus'
  scrape_interval: 5s
  static_configs:
  - targets: ['localhost:9090']
- job_name: 'kubernetes-service-endpoints'
  scrape_interval: 5s
  kubernetes_sd_configs:
  - role: endpoints
  relabel_configs:
  - action: labelmap
    regex: __meta_kubernetes_service_label_(.+)
  - source_labels: [__meta_kubernetes_namespace]
    action: replace
    target_label: kubernetes_namespace
  - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
    action: keep
    regex: true
  - source_labels: [__address__]
    action: replace
    regex: ([^:]+)(?::\d+)?
    replacement: $1:9090
    target_label: __address__
  - source_labels: [__meta_kubernetes_service_name]
    action: replace
    target_label: kubernetes_name

Port numbers are correct.端口号是正确的。 What am I doing wrong?我究竟做错了什么?

Your kube.netes_sd_configs is configured to look for endpoints , which are created by services.您的kube.netes_sd_configs配置为查找由服务创建的endpoints Do you have an endpoint created for your service?您是否为您的服务创建了端点? You could check with kubectl get endpoints in your namespace.您可以使用kubectl get endpoints进行检查。 If you don't want to create a service, I suppose you could configure Prometheus to scrape pod targets too, check the docs for more info.如果您不想创建服务,我想您也可以配置 Prometheus 来抓取 pod 目标,查看文档以获取更多信息。

Also the documentation for metrics and labels say the metric name must match the regular expression [a-zA-Z_:][a-zA-Z0-9_:]* , so the dash ( - ) in your metric name might be an issue too. 指标和标签的文档还说指标名称必须与正则表达式匹配[a-zA-Z_:][a-zA-Z0-9_:]* ,因此指标名称中的破折号 ( - ) 可能是个问题也。

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

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