共用方式為


適用於 Prometheus 的 Azure 監視器受控服務遠端寫入

適用於 Prometheus 的 Azure 監視器受控服務旨在取代自我管理 Prometheus,因此您不需要管理 Kubernetes 叢集中的 Prometheus 伺服器。 您也可以選擇使用受控的服務,將來自自我管理 Prometheus 叢集的資料進行集中,以供長期資料保留,並在叢集之間建立集中式檢視。 在此情況下,您可以使用 remote_write 將資料從自控 Prometheus 傳送至 Azure 受控服務。

架構

您可以設定在 Kubernetes 叢集上執行的 Prometheus,以遠端寫入 Azure 監視器工作區。 目前使用者指派的受控識別或 Microsoft Entra ID 應用程式是使用 Prometheus 遠端寫入設定將計量內嵌至 Azure 監視器工作區的支援驗證類型。

Azure 監視器亦提供反向 Proxy 容器 (Azure 監視器側車容器),其提供內嵌 Prometheus 遠端寫入計量的抽象概念,並協助驗證封包。

建議您直接在環境中執行的自我管理 Prometheus 設定中設定遠端寫入。 如果您偏好的驗證不支援直接設定,則可以使用 Azure 監視器側車容器。

支援的版本

  • 受控識別驗證需要大於 v2.45 的 Prometheus 版本。
  • Microsoft Entra ID 應用程式驗證需要大於 v2.48 的 Prometheus 版本。

設定遠端寫入

設定遠端寫入的程序取決於您的叢集設定與您使用的驗證類型。

  • 針對 Azure Kubernetes Service (AKS) 與已啟用 Azure Arc 的 Kubernetes 叢集,建議使用受控識別。
  • Microsoft Entra ID 可用於 Azure Kubernetes Service (AKS) 與已啟用 Azure Arc 的 Kubernetes 叢集,而且在另一個雲端或內部部署中執行的 Kubernetes 叢集也需要該服務。

如需為任一使用者指派的受控識別和 Microsoft Entra ID 應用程式設定遠端寫入的詳細資訊,請參閱在 Kubernetes 上為 Prometheus 運算子設定遠端寫入。 此選項可用於在任何環境中執行的自我管理 Prometheus。

您也可以使用邊車容器來設定在 Kubernetes 叢集上的 Prometheus 遠端寫入。 參閱以下文章,以尋求如何使用邊車容器來設定在 Kubernetes 叢集上之遠端寫入的更多資訊。

從虛擬機器和虛擬機器擴展集遠端寫入

您可以使用遠端寫入,將 Prometheus 資料從虛擬機器和虛擬機擴展集傳送至 Azure 監視器工作區。 伺服器可以由 Azure 管理,或位於任何其他環境中。 如需詳細資訊,請參閱將 Prometheus 計量從虛擬機器傳送至 Azure 監視器工作區 (部分機器翻譯)。

確認遠端寫入正常運作

使用下列方法確認 Prometheus 資料已傳送至您的 Azure 監視器工作區。

Kubectl 命令

使用下列命令來檢視 Sidecar 容器中的記錄。 若 avgBytesPerRequestavgRequestDuration 的輸出有非零值,則遠端寫入資料會流動。

kubectl logs <Prometheus-Pod-Name> <Azure-Monitor-Side-Car-Container-Name> --namespace <namespace-where-Prometheus-is-running>
# example: kubectl logs prometheus-prometheus-kube-prometheus-prometheus-0 prom-remotewrite --namespace monitoring

此命令的輸出格式如下:

time="2022-11-02T21:32:59Z" level=info msg="Metric packets published in last 1 minute" avgBytesPerRequest=19713 avgRequestDurationInSec=0.023 failedPublishing=0 successfullyPublished=122

搭配 PromQL 的 Azure 監視器計量瀏覽器

若要檢查計量是否流向 Azure 監視器工作區,請從 Azure 入口網站中的 Azure 監視器工作區選取 [計量]。 使用計量瀏覽器來查詢您預期從自我管理 Prometheus 環境傳回的計量。 如需詳細資訊,請參閱計量瀏覽器

Azure 監視器工作區中的 Prometheus 總管

Prometheus Explorer 提供與 Azure 環境中的 Prometheus 計量互動的便捷方式,讓監視和疑難排解更有效率。 若要使用 Prometheus 總管,請前往 Azure 入口網站中的 Azure 監視器工作區,然後選取 [Prometheus 總管] 以查詢您預期自我管理 Prometheus 環境傳回的計量。 如需詳細資訊,請參閱 Prometheus 總管

Grafana

在 Grafana 中使用 PromQL 查詢,並確認結果傳回預期的資料。 如需為 Prometheus 設定 Azure 受控服務的 Grafana 的詳細資料,請參閱使用適用於 Prometheus 的 Azure 監視器受控服務作為使用受控系統識別的 Grafana 資料來源

針對遠端寫入進行疑難排解

如果遠端資料未出現在 Azure 監視器工作區中,請參閱針對常見問題和解決方案的遠端寫入進行疑難排解

下一步