全部產品
Search
文件中心

Managed Service for Prometheus:使用Remote Read地址以實現自建Prometheus訪問雲上Prometheus資料

更新時間:May 28, 2025

可觀測監控 Prometheus 版提供了Remote Read的標準介面,您可以通過這個介面遠端存取雲上Prometheus的監控資料。本文以開源Prometheus訪問阿里雲可觀測監控 Prometheus 版監控資料為例介紹如何使用Remote Read地址。

重要

Prometheus Remote Read 模式需要讀出大量原始時序資料到本地 Prometheus 引擎計算,具有較多使用限制,因此推薦您直接使用可觀測監控 Prometheus 版提供的 HTTP API 查詢協議。

可觀測監控 Prometheus 版提供完整的 Prometheus 查詢 API,相比直接 Remote Read 到本地計算有數十倍效能提升,可直接用HTTP請求發起查詢,也支援Grafana直接對接。相關配置,請參見使用HTTP API地址對接Grafana或自建應用中接入Prometheus資料

Prometheus Remote Read 模式限制舉例:

  • 需要在本地維護 Prometheus 計算引擎,有較高的機器成本。

  • 每次拉取大量資料計算,需要經過多層網路裝置,整體延遲較高。

  • Remote Read 服務限制較多,資料量較大時容易達到限制上限。

使用限制

Remote Read介面暫不支援HTTP/2。

前提條件

已建立Managed Service for Prometheus執行個體。詳細步驟,請參見建立執行個體

(可選)步驟一:為RAM使用者授予CMS讀寫權限

如果您的阿里雲Prometheus執行個體是由阿里雲主帳號建立,且您需要使用RAM使用者的AccessKey ID和AccessKey Secret進行遠程讀寫,則需要先為RAM使用者授予CMS的讀寫權限。

  1. 使用阿里雲主帳號或Resource Access Management員登入RAM控制台,在左側導覽列選擇許可權管理 > 授權

  2. 授權頁面,單擊新增授權。在新增授權頁面,進行如下配置。

    參數

    說明

    資源範圍

    按需選擇資源範圍。

    授權主體

    指定授權主體,即需要添加許可權的RAM使用者。

    權限原則

    您可以根據需求為RAM使用者添加以下許可權:

    • AliyunCloudMonitorFullAccess:CMS的完整許可權,添加該許可權後,RAM使用者擁有對各子產品執行個體的查看、編輯、刪除等所有操作許可權。

    • AliyunCloudMonitorReadOnlyAccess:CMS的唯讀許可權,添加該許可權後,RAM使用者只支援查看各子產品的執行個體資訊,不支援修改、刪除等操作。

  3. 單擊確認新增授權,單擊關閉

步驟二:擷取Remote Read地址

  1. 登入CloudMonitor控制台,在左側導覽列選擇Prometheus 監控 > 執行個體列表,進入執行個體列表頁面。

  2. 在頁面頂部功能表列選擇執行個體所在的地區,並在目的地組群右側的操作列單擊設定

  3. 設定頁簽上,根據需求複製公網或內網的Remote Read地址。

    image

步驟三:配置開源版Prometheus

  1. 安裝Prometheus,安裝方法請參見開源版Prometheus下載地址

  2. 編輯Prometheus.yml設定檔,並在檔案末尾增加以下內容,將remote_read連結替換為上文步驟二中擷取的地址,然後儲存檔案。

    global:
      scrape_interval: 15s
      evaluation_interval: 15s
    scrape_configs:
      - job_name: 'prometheus'
        static_configs:
        - targets: ['localhost:9090']
    remote_read:
      # 替換為您的Remote Read地址。
      - url: "http://ts-xxxxxxxxxxxx.hitsdb.rds.aliyuncs.com:3242/api/prom_read"
        read_recent: true
  3. 重啟開源版Prometheus服務。

步驟四:在自建Prometheus上查看阿里雲Prometheus資料

  1. 在瀏覽器登入自建Prometheus。

    http://localhost:9090
  2. Prometheus頁面,單擊頁面頂部功能表列的Graph

  3. Graph頁簽的搜尋方塊中輸入要查詢的SQL語句,然後單擊搜尋方塊右側的Execute

    例如查詢指定IP的CPU使用率。

    100 - (avg by (instance) (rate(node_cpu_seconds_total{instance="指定IP:9100", mode="idle"}[5m])) * 100)

    image