查看執行個體彈性

本文說明如何查看代管執行個體群組 (MIG) 的執行個體彈性設定,以及群組中各個 VM 使用的機型。

在 MIG 中新增或變更執行個體彈性後,您可以執行下列操作:

事前準備

  • 如果尚未設定驗證,請先完成設定。驗證程序會確認您的身分,以便授予 Google Cloud 服務和 API 的存取權。如要從本機開發環境執行程式碼或範例,您可以選取下列其中一個選項,向 Compute Engine 進行驗證:

    請根據您打算如何使用本頁範例,選取對應的分頁標籤:

    控制台

    使用 Google Cloud 控制台存取 Google Cloud 服務和 API 時,不需要設定驗證機制。

    gcloud

    1. 安裝 Google Cloud CLI。 安裝完成後,請執行下列指令,初始化 Google Cloud CLI:

      gcloud init

      若您採用的是外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。

  • 設定預設區域和可用區。
  • REST

    如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

      安裝 Google Cloud CLI。

      若您採用的是外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。

    詳情請參閱 Google Cloud 驗證說明文件中的「使用 REST 進行驗證」一節。

查看執行個體彈性設定

控制台

  1. 前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。

    前往「Instance groups」(執行個體群組) 頁面

  2. 在「Name」(名稱) 欄中,按一下要查看執行個體彈性設定的 MIG 名稱。

    MIG 的總覽頁面隨即開啟。

  3. 點按「Details」(詳細資料) 分頁標籤。

    在「Instance flexibility」(執行個體彈性) 區段中,「Instance selections」(執行個體選項) 表格會顯示執行個體選項名稱、排名和選項中的機器類型。如果 MIG 未設定執行個體彈性,就不會顯示「Instance flexibility」(執行個體彈性) 專區。

gcloud

如要查看執行個體彈性設定,請使用 instance-groups managed describe 指令。加入 --format 旗標,篩選 instanceFlexibilityPolicy.instanceSelections 屬性。

  gcloud compute instance-groups managed describe INSTANCE_GROUP_NAME \
      --region REGION \
      --format="json(instanceFlexibilityPolicy.instanceSelections)"

輸出內容範例如下:

{
  "instanceFlexibilityPolicy": {
    "instanceSelections": {
      "instance-selection-1": {
        "machineTypes": [
          "n1-standard-16",
          "n2-standard-16",
          "e2-standard-16"
        ],
        "rank": 1
      }
    }
  }
}

如果 MIG 未設定執行個體彈性,輸出內容會傳回 null。

更改下列內容:

  • INSTANCE_GROUP_NAME:要查看執行個體彈性設定的 MIG 名稱。
  • REGION:MIG 所在的區域。

REST

如要查看執行個體彈性設定,請使用 regionInstanceGroupManagers.get 方法。在要求網址中加入 fields 參數,篩選 instanceFlexibilityPolicy.instanceSelections 屬性。

  GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME?fields=instanceFlexibilityPolicy.instanceSelections

輸出內容範例如下:

{
  "instanceFlexibilityPolicy": {
    "instanceSelections": {
      "instance-selection-1": {
        "machineTypes": [
          "n1-standard-16",
          "n2-standard-16",
          "e2-standard-16"
        ],
        "rank": 1
      }
    }
  }
}

如果 MIG 未設定執行個體彈性,輸出內容會傳回 null。

更改下列內容:

  • PROJECT_ID:您的專案 ID。
  • REGION:MIG 所在的區域。
  • INSTANCE_GROUP_NAME:要查看執行個體彈性設定的 MIG 名稱。

查看各 VM 使用的機型

控制台

  1. 前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。

    前往「Instance groups」(執行個體群組) 頁面

  2. 在「Name」(名稱) 欄中,按一下要查看各 VM 所用機器類型的 MIG 名稱。

    MIG 的「Overview」(總覽) 頁面會開啟,列出群組中的所有 VM、機型和其他詳細資料。

gcloud

如要查看 MIG 中各個 VM 使用的機型,請使用 instance-groups managed list-instances 指令列出 VM,並加入 --format 旗標來篩選 propertiesFromFlexibilityPolicy.machineType 欄位。您也可以視需要篩選其他欄位。

  gcloud compute instance-groups managed list-instances INSTANCE_GROUP_NAME \
      --region REGION \
      --format='(name,instanceStatus,currentAction,propertiesFromFlexibilityPolicy.machineType,lastAttempt.errors.errors)'

輸出內容範例如下:

NAME: example-mig-0md2
STATUS: RUNNING
ACTION: NONE
MACHINE_TYPE: n1-standard-16
LAST_ERROR:

NAME: example-mig-vbgg
STATUS: RUNNING
ACTION: NONE
MACHINE_TYPE: n1-standard-16
LAST_ERROR:

更改下列內容:

  • REGION:MIG 所在的區域。
  • INSTANCE_GROUP_NAME:要查看執行個體彈性設定的 MIG 名稱。

REST

如要查看 MIG 中各個 VM 使用的機器類型,請使用 listManagedInstances 方法列出 VM,並檢查回應中的 propertiesFromFlexibilityPolicy.machineType 欄位。

  POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/listManagedInstances

以下是輸出範例,請尋找已設定 VM machineType 欄位的 propertiesFromFlexibilityPolicy 欄位。

{
  "managedInstances": [
    {
      "instance": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-b/instances/example-mig-0md2",
      "instanceStatus": "RUNNING",
      "id": "2656095434923471959",
      "version": {
        "instanceTemplate": "https://www.googleapis.com/compute/v1/projects/example-project/global/instanceTemplates/example-instance-template"
      },
      "targetStatus": "RUNNING",
      "name": "example-mig-0md2",
      "propertiesFromFlexibilityPolicy": {
        "machineType": "n1-standard-16"
      }
    },
    {
      "instance": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-b/instances/example-mig-vbgg",
      "instanceStatus": "RUNNING",
      "currentAction": "NONE",
      "id": "9171259522409694366",
      "version": {
        "instanceTemplate": "https://www.googleapis.com/compute/v1/projects/example-project/global/instanceTemplates/example-instance-template"
      },
      "targetStatus": "RUNNING",
      "name": "example-mig-vbgg",
      "propertiesFromFlexibilityPolicy": {
        "machineType": "n1-standard-16"
      }
    }
  ]
}

更改下列內容:

  • PROJECT_ID:您的專案 ID。
  • REGION:MIG 所在的區域。
  • INSTANCE_GROUP_NAME:要查看執行個體彈性設定的 MIG 名稱。

監控執行個體分布

雖然檢查靜態執行個體彈性政策和列出個別 VM 機器類型,可以提供目前設定的快照,但如要觀察 MIG 如何分配容量,則需要即時監控。

如要確認 VM 在需求或容量變動時,是否按照預期等級和位置分布,您可以查看特定 MIG 的執行階段執行個體分布情形,或多個 MIG 的匯總資料。如要瞭解如何查看執行個體分布情形,請參閱「監控 MIG 中的執行個體分布情形」。

後續步驟