Share via


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

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

架構

Azure 監視器提供反向 Proxy 容器(Azure 監視器 端汽車容器),可提供擷取 Prometheus 遠端寫入計量的抽象概念,並協助驗證封包。 Azure 監視器端汽車容器目前支援使用者指派的身分識別和 Microsoft Entra 標識符型驗證,以內嵌 Prometheus 遠端寫入計量至 Azure 監視器工作區。

支援的版本

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

設定遠端寫入

設定遠端寫入取決於您的叢集組態和您使用的驗證類型。

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

如需如何設定 Kubernetes 叢集遠端寫入的詳細資訊,請參閱下列文章:

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

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

確認遠端寫入正常運作

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

Kubectl 命令

使用下列命令來檢視側車容器中的記錄。 如果 輸出具有 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 監視器工作區中,請參閱 針對常見問題和解決方案進行遠端寫入 疑難解答。

下一步