Prometheus不支持的内容类型

前端开发 2026-07-10

我想对我的Laravel应用抓取指标,因为应用运行在一个使用PHP-FPM、支持FastCGI的容器中,所以Prometheus无法抓取它。这也是我在nginx配置中暴露 /prometheus端点的原因(我仅在容器网络内限制了访问权限)。

该端点以 "text/html" 作为响应头返回指标,而Prometheus期望的响应头是 "text/paln"

我已经添加了一个中间件来强制设置Content-Type头,但仍然返回text/html头。

解决方案

You can fix this by setting the fallbackScrapeProtocol in prometheus to PrometheusText1.0.0

eg. using a service monitor as shown here:

https://documentation.breadnet.co.uk/kubernetes/prometheus/prometheus-recieved-unsupported-content-type/#what

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: intel-xpumanager
  labels:
    app: intel-xpumanager
spec:
+ fallbackScrapeProtocol: PrometheusText1.0.0
  selector:
    matchLabels:
      app: intel-xpumanager
  endpoints:
    - port: metrics
      path: /metrics
      interval: 5s
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章