英文:
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链接)。
但是在Web服务器重新启动后,以前记录的指标在Prometheus上不显示(点击图像2链接)。
我不清楚为什么以前从Web服务器(目标)抓取的指标在目标节点重新启动后不显示。我可以在图形视图中看到以前抓取的指标(请参见图像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).
But on webserver restart, previously recorded metrics are not shown on Prometheus (click on image 2 link).
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.
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论