Prometheus: 疑難排解

您可能在 Prometheus 中遇到的錯誤

👋 歡迎來到 Stackhero 文件中心!

Stackhero 提供全代管的 Prometheus cloud 平台,專為高可靠性與簡易操作而設計:

  • 內建 Alert Manager,可直接將警報發送到 SlackMattermostPagerDuty 及其他主流平台。
  • 專屬電子郵件伺服器,讓您無需額外設定即可發送無限量電子郵件警報
  • 內含 Blackbox,可針對 HTTPICMPTCP 等多種協定進行全面監控探測。
  • 可透過線上設定檔編輯器快速設定您的實例,無需手動管理 YAML。
  • 一鍵升級,Stackhero 會自動處理更新流程,最大程度減少停機與人工干預。
  • 專屬私有基礎架構,內建高效能與強化安全性。

約 5 分鐘即可完成部署。Stackhero 幫您搞定所有安裝設定,讓您專注於監控本身,而非維護作業。立即體驗 Prometheus cloud hosting on Stackhero,讓您的監控與警報流程更有效率。

隨著 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

以下是解決此問題的一些方法:

如果您正在使用像 Node Exporter 這樣的目標伺服器,請考慮將其更新到最新版本。最近的更新通常能確保 Content-Type 標頭正確定義,這應該可以解決 Prometheus 中的錯誤。

對於自訂的目標伺服器,例如您開發的 API 路徑以返回 Prometheus 指標,您可以直接在回應中設置 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

您也可以在 prometheus.yml 配置文件中定義一個後備協議。如果目標伺服器未指定 Content-Type 標頭,將使用此協議。

以下是一個例子:

  - job_name: "my-job"
    # [...]
    fallback_scrape_protocol: PrometheusText0.0.4

支持的值有 PrometheusProtoPrometheusText0.0.4PrometheusText1.0.0OpenMetricsText0.0.1OpenMetricsText1.0.0