收集診斷資訊


本文說明如何使用診斷工具收集虛擬機器 (VM) 執行個體的相關資訊。使用工具收集的資訊進行基本疑難排解,然後再與支援團隊聯絡。

這項工具會執行下列作業:

  • 只會收集您指定的 VM 資訊。

  • 只將資訊儲存在專案中。

  • 將資訊儲存在 Cloud Storage 值區 10 天,預設只有您能存取。

與 Google 支援團隊分享收集到的資訊前,請先完成下列步驟:

  1. 查看機密或個人識別資訊 (PII) 的相關資訊。

  2. 視需要刪除或遮蓋資訊。

從 VM 收集的診斷資訊

這項診斷工具會收集下列資訊:

如要詳細瞭解 Compute Engine 如何收集這項資訊,請參閱公開存放區

限制

  • 您只能從依據 Windows Server 建立的 VM 收集診斷資訊。

事前準備

  • 對於 v20190714 之後的 Windows Server 映像檔公開版本,Compute Engine 預設會安裝診斷工具。否則,如果 Windows Server 映像檔版本早於 v20190714,或是使用自訂映像檔,請使用 googet install google-compute-engine-diagnostics 指令安裝工具。
  • 如果尚未設定驗證,請先完成設定。 「驗證」是指驗證身分的程序,確認您有權存取 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

      1. 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.

      2. Set a default region and zone.
      3. 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」。

從 VM 收集診斷資訊

您可以直接從 VM 執行診斷工具,也可以使用 Google Cloud CLI 遠端執行。在 Windows VM 中,診斷工具位於 C:\Program Files\Google\Compute Engine\diagnostics 目錄。

這項工作需要的權限

如要執行這項工作,您必須具備以下權限

  • 專案的 roles/iam.serviceAccountTokenCreator 權限

gcloud

  1. 授予專案的 iam.serviceAccountTokenCreator 角色:

    gcloud projects add-iam-policy-binding PROJECT_ID \
        --member user:EMAIL \
        --role roles/iam.serviceAccountTokenCreator
    

    更改下列內容:

    • PROJECT_ID:專案 ID
    • EMAIL:要授予「iam.serviceAccountTokenCreator」角色的電子郵件地址
  2. 將診斷資訊匯出為物件至 Cloud Storage 值區。

    gcloud compute diagnose export-logs VM_NAME \
      [--collect-process-traces]
    

    選用的 --collect-process-traces 旗標會指定診斷工具是否要收集執行中系統的 10 分鐘追蹤記錄,包括 CPU、磁碟、檔案和網路活動。在 Windows VM 上,這會使用 Windows Performance Recorder

    更改下列內容:

    • VM_NAME:要從中收集診斷資訊的 VM 名稱
  3. 匯出記錄程序可能需要幾分鐘才能完成。使用 gcloud compute instances get-serial-port-output 指令查看狀態。

  4. Compute Engine 會將包含診斷資訊的值區名稱格式化為 diagnostic_logs_project_PROJECT_NUMBER。使用 gcloud CLI 查看或下載 bucket,或在Google Cloud 控制台的「Cloud Storage」頁面中執行下列操作:

    前往「儲存空間」

後續步驟