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。