为什么 Spring Boot 3 会记录 HTTP 406 Not Acceptable 来响应 Prometheous 抓取请求?

问题描述 投票:0回答:1

我正在使用 Spring Boot 应用程序,并尝试设置 Prometheus 来监控生产期间的性能。 但是当我启动 prometheus 服务器时,由于以下异常,它无法从 Spring Boot 收集抓取数据。

[org.springframework.web.HttpMediaTypeNotAcceptableException: No acceptable representation]

我对此进行了更深入的研究并发现了以下内容:

GET "/actuator/prometheus", parameters={}, headers={host:[localhost:8080], user-agent:[Prometheus/2.49.0-rc.0], accept:[application/openmetrics-text;version=1.0.0;q=0.5,application/openmetrics-text;version=0.0.1;q=0.4,text/plain;version=0.0.4;q=0.3,*/*;q=2], accept-encoding:[gzip], x-prometheus-scrape-timeout-seconds:[3]} in DispatcherServlet 'dispatcherServlet'
2023-12-19T14:45:03.521+05:30  WARN 3767 --- [0.0-8080-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: No acceptable representation]
2023-12-19T14:45:03.521+05:30 TRACE 3767 --- [0.0-8080-exec-3] o.s.web.servlet.DispatcherServlet        : No view rendering, null ModelAndView returned.
2023-12-19T14:45:03.521+05:30 DEBUG 3767 --- [0.0-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Completed 406 NOT_ACCEPTABLE, headers={Access-Control-Allow-Origin:[*], Access-Control-Allow-Methods:[POST, PUT, GET, OPTIONS, DELETE], Access-Control-Max-Age:[3600], Access-Control-Allow-Headers:[Content-Type, Authorization, Control-Length, X-Requested-With], Vary:[Origin, Access-Control-Request-Method, Access-Control-Request-Headers], Vary:[Origin, Access-Control-Request-Method, Access-Control-Request-Headers], Vary:[Origin, Access-Control-Request-Method, Access-Control-Request-Headers], Accept:[text/plain;version=0.0.4;charset=utf-8, application/openmetrics-text;version=1.0.0;charset=utf-8], X-Content-Type-Options:[nosniff], X-XSS-Protection:[0], Cache-Control:[no-cache, no-store, max-age=0, must-revalidate], Pragma:[no-cache], Expires:[0], X-Frame-Options:[DENY]}

这是控制台中我的 Spring Boot 应用程序的日志。

我能够理解问题是由于 Prometheus 请求的标头而发生的,但是,我不确定如何配置我的 Spring Boot 应用程序,以便为 Prometheus 生成兼容的响应?

请建议一些解决此问题的方法?

http-headers prometheus spring-boot-3
1个回答
0
投票

我发现这是因为 Prometheus 发送带有 header 的请求

Accept: application/openmetrics-text;version=1.0.0;q=0.5,application/openmetrics-text;version=0.0.1;q=0.4,text/plain;version=0.0.4;q=0.3,*/*;q=2

所以,看起来质量值应该在0.0和1.0之间

© www.soinside.com 2019 - 2024. All rights reserved.