使用 Telemetry API

您可以將 Ops Agent 設為使用 Telemetry (OTLP) API,將記錄、指標和追蹤記錄傳送至 Google Cloud 專案。Telemetry API (telemetry.googleapis.com) 是開放原始碼 OpenTelemetry 通訊協定的實作項目。將 Ops Agent 設定為使用這項 API 時,Ops Agent 會使用 Telemetry API 傳送遙測資料,而非專屬的 Cloud Monitoring API、Logging API 或 Trace API。

如果您在 Ops Agent 中採用 Telemetry API,並使用圖表或快訊政策監控 API 用量,則必須更新這些構件,監控 telemetry.googleapis.com 端點,而非 monitoring.googleapis.com、logging.googleapis.com 或 cloudtrace.googleapis.com 端點。

事前準備

如要使用 Telemetry API,請按照下列步驟操作:

  1. 如果尚未啟用,請在 Google Cloud 專案中啟用 Telemetry API。您可以執行下列指令來啟用 API:

    gcloud services enable telemetry.googleapis.com
    
  2. 如果預設值不足,請調整 Telemetry API 配額。Telemetry API 的配額與 Cloud Monitoring API 和 Cloud Logging API 的配額不同。如要瞭解 Telemetry API 的配額和限制,請參閱下列內容:

    您可能需要調整這些配額,以配合擷取的遙測資料量。

  3. 如要收集追蹤記錄,請將「Cloud Telemetry Traces Writer」(roles/telemetry.tracesWriter) 角色授予 Ops Agent 使用的服務帳戶。這個角色提供寫入追蹤記錄所需的權限。

設定 Ops Agent 以使用 Telemetry API

Ops Agent 提供設定選項,可切換使用專屬 API (預設) 和 Telemetry API 傳送遙測資料。如要使用 Ops Agent 和 Telemetry API 收集遙測資料,請按照下列各節說明,完成下列步驟:

  1. 安裝支援 Telemetry API 的 Ops Agent 版本。
  2. 更新 Ops Agent config.yaml 檔案,設定設定選項。
  3. 重新啟動 Ops Agent,即可擷取變更。

使用 2.71.0 以上版本的 Ops Agent

如要搭配使用 Telemetry API 與 Ops Agent,請安裝 2.71.0 以上版本的 Ops Agent。如要瞭解如何安裝 Ops Agent,請參閱「在個別 VM 中安裝 Ops Agent」。

設定設定選項

將代理程式 config.yaml 檔案中的 otlp_exporter 設定選項設為 true,授予 Ops Agent Telemetry API 的存取權:

global:
   otlp_exporter: true

重新啟動 Ops Agent

Linux

  1. 如要重新啟動代理程式,請在執行個體上執行下列指令:
    sudo systemctl restart google-cloud-ops-agent
    
  2. 如要確定代理程式已重新啟動,請執行下列指令,並驗證「指標代理程式」和「Logging 代理程式」元件是否已啟動:
    sudo systemctl status "google-cloud-ops-agent*"
    

Windows

  1. 使用遠端桌面協定或類似工具連線至執行個體,並登入 Windows。
  2. 以滑鼠右鍵按一下 PowerShell 圖示,然後選取「以系統管理員身分執行」,以管理員權限開啟 PowerShell 終端機。
  3. 如要重新啟動代理程式,請執行下列 PowerShell 指令:
    Restart-Service google-cloud-ops-agent -Force
    
  4. 如要確認代理程式已重新啟動,請執行下列指令,並驗證「指標代理程式」和「Logging 代理程式」元件是否已啟動:
    Get-Service google-cloud-ops-agent*
    

設定 Ops Agent,使其不使用 Telemetry API

如要使用 Telemetry API 停止收集遙測資料,並使用 Cloud Monitoring API、Logging API 和 Trace API 繼續收集遙測資料,請按照下列步驟操作:

  1. 從 config.yaml 檔案中移除 otlp_exporter 選項。 或者,您也可以將選項設為 false。

  2. 重新啟動 Ops Agent,即可擷取變更。

後續步驟