作業套件代理程式會收集執行個體的遙測資料,以供您進行疑難排解和效能調整。
事前準備
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
-
Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1
) -
如要在執行個體上安裝作業套件代理程式:
OSPolicyAssignment 編輯者 (
roles/osconfig.osPolicyAssignmentEditor
) 前往 Google Cloud 控制台的「Create an instance」(建立執行個體) 頁面。
如果出現系統提示,請選取您的專案,然後按一下 [Continue] (繼續)。
「建立執行個體」頁面隨即顯示,並顯示「機器設定」窗格。
在導覽窗格中,按一下「可觀測性」。「可觀測性」窗格隨即顯示。
在「作業套件代理程式」部分,選取「安裝作業套件代理程式來處理監控和記錄工作」核取方塊。
選取這個核取方塊後,系統會以功能受限模式啟用 VM 管理員,並建立 OS 政策指派作業,在執行個體上安裝作業套件代理程式。
視需要指定其他設定選項。詳情請參閱「建立執行個體時的設定選項」。
如要建立並啟動執行個體,請按一下「建立」。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。
必要的角色
如要取得必要權限,為 Ops Agent 監控和記錄建立執行個體,請要求管理員將專案的下列 IAM 角色授予您:
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
為作業套件代理程式監控和記錄建立執行個體
您只能使用 Google Cloud 控制台,建立設定為僅供作業套件代理程式監控和記錄的執行個體。本節簡要說明如何在建立執行個體時安裝 Ops Agent。詳情請參閱「在建立執行個體時安裝 Ops Agent」。
在現有執行個體中安裝作業套件代理程式
您可以使用 Google Cloud 控制台、gcloud CLI 或自動化工具,在一組執行個體或個別執行個體上安裝作業套件代理程式。如需詳細操作說明,請參閱「安裝 Ops 代理程式」。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-21 (世界標準時間)。
-