首页 > 解决方案 > 运行 Prometheus 时,我的所有端点都开始返回 404

问题描述

我有运行良好的 SpringBoot 应用程序,当我使用 Postman 访问我的 API 端点时,我的端点会返回正确的响应。

与我的执行器相同。他们工作正常。

我还添加了 spring 依赖项micrometer-core,并将micrometer-registry-prometheus其添加到我的 Actuators 新路径“/prometheus”中。此路径也可以正常工作并返回指标。

由于我想查看图形,我从官方网站(zip 文件)下载了独立的 Prometheus 应用程序(所以没有 docker 映像)并将其解压缩。

里面有 prometheus.exe 和 prometheus.yaml 文件。

即使根本没有修改这个 yaml 文件,只要我双击 prometheus.exe 启动它(它会正确启动它),我的所有端点都会停止返回 200 OK 并开始返回 404 Not Found 响应。

然后我修改它以添加我的工作名称和路径

-job_name: 'spring-actuators'
 metric_path: '/myappname/actuator/prometheus'
 scrape_interval: 5s
 static_configs:
 - targets: ['localhost:9090']

即使更改为现在从“myappname”中抓取指标,每次我尝试使用 Postman 向我的 API 发送请求时,只要我启动 prometheus,我仍然会收到 404 响应。

我注意到 postman.exe 控制台在服务器准备好请求后也立即显示错误:

level=info ts=2021-06-02T15:42:03.421Z caller=main.go:775 msg="Server is ready to receive web requests."
level=error ts=2021-06-02T15:42:10.374Z caller=db.go:780 component=tsdb msg="compaction failed" err="compact head: persist head block: rename block dir: rename data\\01F76P79CQDPFVGZS5XNTDTK4P.tmp-for-creation data\\01F76P79CQDPFVGZS5XNTDTK4P: Access is denied."

标签: eclipsespring-bootprometheus

解决方案


您的应用在 Prometheus 的同一端口上公开端点9090。更改您的 Spring Boot 应用程序以在80809090. 然后在该端口抓取您的应用程序。

-job_name: 'spring-actuators'
 metric_path: '/myappname/actuator/prometheus'
 scrape_interval: 5s
 static_configs:
 - targets: ['localhost:8080']

推荐阅读