Prometheus: 故障排除
您可能遇到的 Prometheus 错误
👋 欢迎查阅 Stackhero 文档!
Stackhero 提供了一个完全托管的 Prometheus cloud 平台,专为高可靠性与简便性设计:
- 内置
Alert Manager,可将告警直接发送到Slack、Mattermost、PagerDuty及其他主流平台。- 配备专用邮件服务器,支持发送无限量邮件告警,无需额外配置。
- 集成
Blackbox,可对HTTP、ICMP、TCP等协议进行探测,实现全面监控。- 通过在线配置文件编辑器,快速完成实例配置,无需手动管理 YAML 文件。
- 一键升级,Stackhero 自动为您处理升级流程,最大限度减少停机和人工干预。
- 依托专属私有基础设施,内置高性能与强大安全性。
大约 5 分钟即可完成部署。Stackhero 负责所有初始化设置,让您专注于监控本身,无需为维护分心。欢迎体验 Stackhero 的 Prometheus cloud hosting,让您的监控与告警流程更加高效便捷。
解决错误 "received unsupported Content-Type "..." and no fallback_scrape_protocol specified for target"
随着 Prometheus v3 的发布,现在目标服务器必须在响应中包含 Content-Type 头,以告知 Prometheus 回复中包含的指标协议。这影响了像 Node Exporter 这样的工具,现在应该用适当的 Content-Type 来响应 Prometheus 的 HTTP 请求。有关更多详细信息,您可以查看 Prometheus 文档。
如果不满足此要求,您可能会遇到如下错误消息:
received unsupported Content-Type "application/octet-stream" and no fallback_scrape_protocol specified for target
以下是解决此问题的一些方法:
1. 更新您的目标服务器
如果您正在使用像 Node Exporter 这样的目标服务器,请考虑将其更新到最新版本。最近的更新通常可以确保正确定义 Content-Type 头,这应该可以解决 Prometheus 中的错误。
2. 为您的目标服务器定义 Content-Type 头
对于自定义目标服务器,例如您开发的用于返回 Prometheus 指标的 API 路由,您可以直接在响应中设置 Content-Type 头。
例如,如果您使用 HapiJS,而不是像这样返回您的指标:
return metrics
您可以这样设置 Content-Type 头:
return h.response(metrics).type('text/plain;version=0.0.4');
以下是根据您返回的指标协议支持的 Content-Type 头:
- PrometheusProto:
application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited - PrometheusText 0.0.4:
text/plain;version=0.0.4 - PrometheusText 1.0.0:
text/plain;version=1.0.0;escaping=allow-utf-8 - OpenMetricsText 0.0.1:
application/openmetrics-text;version=0.0.1 - OpenMetricsText 1.0.0:
application/openmetrics-text;version=1.0.0
3. 定义一个备用协议
您还可以在 prometheus.yml 配置文件中定义一个备用协议。如果目标服务器未指定 Content-Type 头,将使用此协议。
以下是一个示例:
- job_name: "my-job"
# [...]
fallback_scrape_protocol: PrometheusText0.0.4
支持的值有 PrometheusProto、PrometheusText0.0.4、PrometheusText1.0.0、OpenMetricsText0.0.1 和 OpenMetricsText1.0.0。