Prometheus过去的指标在目标节点重新启动后未显示。

huangapple go评论76阅读模式
英文:

prometheus past metrics not shown on target node restart

问题

我是你的中文翻译助手,以下是翻译好的内容:

我对Prometheus还不熟悉,需要帮助理解为什么目标节点重新启动后不显示过去的指标数据。

我已经设置了一个Golang Web服务器(目标)。该服务器使用Go Prometheus Docs中的Golang Prometheus客户端准备指标,并在端口3000上公开指标。Prometheus从该目标中抓取数据。

Prometheus配置文件:

global:
  scrape_interval: 10s
  scrape_timeout: 10s
scrape_configs:
  - job_name: 'webServer1'
    static_configs:
      - targets: ['webServer1:8080']

我还在docker-compose中设置了保留标志:

prometheus:
  image: prom/prometheus
  volumes:
    - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
  ports:
    - "127.0.0.1:9090:9090"
  command:
    - '--config.file=/etc/prometheus/prometheus.yml'
    - '--storage.tsdb.path=/prometheus'
    - '--web.console.libraries=/etc/prometheus/console_libraries'
    - '--web.console.templates=/etc/prometheus/consoles'
    - '--storage.tsdb.retention.time=200h'
    - '--web.enable-lifecycle'

我已经对Web服务器(目标)进行了仪表化,以计算对/bar端点的HTTP请求次数。我可以在Prometheus上看到正确的请求计数(点击图像1链接)。

图像1

但是在Web服务器重新启动后,以前记录的指标在Prometheus上不显示(点击图像2链接)。

图像2

我不清楚为什么以前从Web服务器(目标)抓取的指标在目标节点重新启动后不显示。我可以在图形视图中看到以前抓取的指标(请参见图像3链接),但在表格视图中看不到。

图像3

英文:

I am new to Prometheus and need help to understand why past metric data is not shown when the target node restarts.

I have set up a Golang web server (target). This server makes use of the Go Prometheus Docs Golang Prometheus client to prepare metrics and exposes metrics on port 3000. Prometheus scrapes data from this target.

Prometheus Config file:

global:   scrape_interval: 10s   scrape_timeout: 10s
    scrape_configs:
  - job_name: 'webServer1'
    static_configs:
    - targets: ['webServer1:8080']

I have Also set the retention flag in docker-compose

prometheus:
image: prom/prometheus
volumes:
  - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
ports:
  - "127.0.0.1:9090:9090"
command:
  - '--config.file=/etc/prometheus/prometheus.yml'
  - '--storage.tsdb.path=/prometheus'
  - '--web.console.libraries=/etc/prometheus/console_libraries'
  - '--web.console.templates=/etc/prometheus/consoles'
  - '--storage.tsdb.retention.time=200h'
  - '--web.enable-lifecycle'

I have instrumented a web server (target) to count the number of HTTP requests made to /bar endpoint. I can see the correct request count on Prometheus (click on image 1 link).

image 1

But on webserver restart, previously recorded metrics are not shown on Prometheus (click on image 2 link).

image 2

It's unclear to me why metrics earlier scraped from the webserver (target) are not shown above on target node restart. I can see previously scraped metrics in graph view (see image 3 link). But not in the table view.

image 3

答案1

得分: 2

看起来你把主机名作为指标名称的一部分了。这会导致每个容器都产生新的指标。表格视图只显示每个目标最近一次抓取时包含的指标。

要解决这个问题,从指标名称中删除主机名部分,这样在重新启动时名称就不会改变。如果这确实是有用的信息,可以将它们作为标签添加,尽管这几乎肯定是一个坏主意

英文:

Looks like you made the hostname part of the metric name. This produces new metrics for every container. The table view only shows metrics that were contained in the most recent scrape for each target.

To fix the issue remove the hostname part from the metric name so the names don't change between restarts. If this is really useful information, add them as a label instead, although that is almost certainly a bad idea.

huangapple
  • 本文由 发表于 2021年9月17日 20:39:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/69223588.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定