本文說明如何查看現有虛擬機器 (VM) 執行個體的詳細資料。
查看 VM 的詳細資料,有助於瞭解其設定和狀態,例如連接的磁碟、建立時間戳記、機型和 VM 的 ID (可用於參照 VM 的不可變更值)。
事前準備
-
如果尚未設定驗證,請先完成設定。
驗證程序會確認您的身分,以便授予 Google Cloud 服務和 API 的存取權。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:
選取這個頁面上範例的預計用途分頁:
控制台
使用 Google Cloud 控制台存取 Google Cloud 服務和 API 時,您不需要設定驗證機制。
gcloud
-
安裝 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 進行驗證」。
必要的角色
如要取得查看 VM 詳細資料所需的權限,請要求管理員在 VM 或專案中,授予您 Compute 執行個體管理員 (v1) (roles/compute.instanceAdmin.v1) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
這個預先定義的角色具備 compute.instances.get 權限,可查看 VM 的詳細資料。
查看 VM 詳細資料
如要查看 VM 詳細資料,請選取下列任一選項:
控制台
前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。
在「VM instances」(VM 執行個體) 頁面,您可以查看運算執行個體的下列資訊:
上一個清單包含「VM 執行個體」頁面中顯示的預設資料欄。您可以按一下「資料欄顯示選項」,變更每個 VM 顯示的資料欄。
在「Name」(名稱) 欄中,按一下 VM 名稱,即可查看 VM 執行個體的其他詳細資料。
gcloud
如要查看 VM 的詳細資料,請使用 gcloud compute instances describe 指令。
gcloud compute instances describe VM_NAME \
--zone=ZONE
更改下列內容:
VM_NAME:VM 名稱。ZONE:VM 所在的可用區。
輸出結果會與下列內容相似:
canIpForward: false
confidentialInstanceConfig:
enableConfidentialCompute: false
cpuPlatform: Intel Broadwell
creationTimestamp: '2023-08-18T10:00:21.801-07:00'
deletionProtection: false
description: ''
disks:
- architecture: X86_64
autoDelete: true
boot: true
deviceName: example-vm
diskSizeGb: '10'
guestOsFeatures:
- type: UEFI_COMPATIBLE
- type: VIRTIO_SCSI_MULTIQUEUE
- type: GVNIC
- type: SEV_CAPABLE
index: 0
interface: SCSI
kind: compute#attachedDisk
licenses:
- https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses/debian-13-trixie
mode: READ_WRITE
source: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/disks/example-vm
type: PERSISTENT
displayDevice:
enableDisplay: false
fingerprint: CQp-QBEACqw=
id: '6404261768674286922'
keyRevocationActionType: NONE
kind: compute#instance
labelFingerprint: 42WmSpB8rSM=
lastStartTimestamp: '2023-08-18T10:00:28.182-07:00'
machineType: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/machineTypes/e2-medium
metadata:
fingerprint: lQ-dD2sMrMY=
items:
- key: enable-oslogin
value: 'true'
kind: compute#metadata
name: example-vm
networkInterfaces:
- accessConfigs:
- kind: compute#accessConfig
name: External NAT
natIP: 34.27.53.198
networkTier: PREMIUM
type: ONE_TO_ONE_NAT
fingerprint: QR3z6TgVFjg=
kind: compute#networkInterface
name: nic0
network: https://www.googleapis.com/compute/v1/projects/example-project/global/networks/default
networkIP: 10.128.0.28
stackType: IPV4_ONLY
subnetwork: https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/subnetworks/default
reservationAffinity:
consumeReservationType: ANY_RESERVATION
scheduling:
automaticRestart: true
onHostMaintenance: MIGRATE
preemptible: false
provisioningModel: STANDARD
selfLink: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instances/example-vm
serviceAccounts:
- email: 790569220780-compute@developer.gserviceaccount.com
scopes:
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring.write
- https://www.googleapis.com/auth/servicecontrol
- https://www.googleapis.com/auth/service.management.readonly
- https://www.googleapis.com/auth/trace.append
shieldedInstanceConfig:
enableIntegrityMonitoring: true
enableSecureBoot: false
enableVtpm: true
shieldedInstanceIntegrityPolicy:
updateAutoLearnPolicy: true
startRestricted: false
status: RUNNING
tags:
fingerprint: 42WmSpB8rSM=
zone: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a
REST
如要查看 VM 的詳細資料,請向 instances.get 方法發出 GET 要求。
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME
更改下列內容:
PROJECT_ID:VM 所在的專案 ID。ZONE:VM 所在的可用區。VM_NAME:VM 名稱。
輸出結果會與下列內容相似:
{
"canIpForward": false,
"confidentialInstanceConfig": {
"enableConfidentialCompute": false
},
"cpuPlatform": "Intel Broadwell",
"creationTimestamp": "2023-08-18T10:00:21.801-07:00",
"deletionProtection": false,
"description": "",
"disks": [
{
"architecture": "X86_64",
"autoDelete": true,
"boot": true,
"deviceName": "example-vm",
"diskSizeGb": "10",
"guestOsFeatures": [
{
"type": "UEFI_COMPATIBLE"
},
{
"type": "VIRTIO_SCSI_MULTIQUEUE"
},
{
"type": "GVNIC"
},
{
"type": "SEV_CAPABLE"
}
],
"index": 0,
"interface": "SCSI",
"kind": "compute#attachedDisk",
"licenses": [
"https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses/debian-13-trixie"
],
"mode": "READ_WRITE",
"source": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/disks/example-vm",
"type": "PERSISTENT"
}
],
"displayDevice": {
"enableDisplay": false
},
"fingerprint": "CQp-QBEACqw=",
"id": "6404261768674286922",
"keyRevocationActionType": "NONE",
"kind": "compute#instance",
"labelFingerprint": "42WmSpB8rSM=",
"lastStartTimestamp": "2023-08-18T10:00:28.182-07:00",
"machineType": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/machineTypes/e2-medium",
"metadata": {
"fingerprint": "lQ-dD2sMrMY=",
"items": [
{
"key": "enable-oslogin",
"value": "true"
}
],
"kind": "compute#metadata"
},
"name": "example-vm",
"networkInterfaces": [
{
"accessConfigs": [
{
"kind": "compute#accessConfig",
"name": "External NAT",
"natIP": "34.27.53.198",
"networkTier": "PREMIUM",
"type": "ONE_TO_ONE_NAT"
}
],
"fingerprint": "QR3z6TgVFjg=",
"kind": "compute#networkInterface",
"name": "nic0",
"network": "https://www.googleapis.com/compute/v1/projects/example-project/global/networks/default",
"networkIP": "10.128.0.28",
"stackType": "IPV4_ONLY",
"subnetwork": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/subnetworks/default"
}
],
"reservationAffinity": {
"consumeReservationType": "ANY_RESERVATION"
},
"scheduling": {
"automaticRestart": true,
"onHostMaintenance": "MIGRATE",
"preemptible": false,
"provisioningModel": "STANDARD"
},
"selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instances/example-vm",
"serviceAccounts": [
{
"email": "790569220780-compute@developer.gserviceaccount.com",
"scopes": [
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring.write",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/trace.append"
]
}
],
"shieldedInstanceConfig": {
"enableIntegrityMonitoring": true,
"enableSecureBoot": false,
"enableVtpm": true
},
"shieldedInstanceIntegrityPolicy": {
"updateAutoLearnPolicy": true
},
"startRestricted": false,
"status": "RUNNING",
"tags": {
"fingerprint": "42WmSpB8rSM="
},
"zone": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a"
}
決定執行個體的 CPU 和記憶體配置
您可以根據執行個體使用的機型,判斷分配給運算執行個體的 CPU 數量和記憶體,例如:
c3-standard-22:C3 是機器系列名稱,standard是執行個體的記憶體配置類型,22則是分配給執行個體的 vCPU 數量。一般而言,standard機型會採用每個 vCPU 4 GB 記憶體的比例。因此,這個機型的 RAM 為 88 GB。standard、highmem、highcpu、ultamem和megamem機器類型的記憶體與 CPU 比率,在每個機器系列中可能略有不同,因此請參閱機器系列頁面,判斷每個機器類型分配到的確切記憶體量。n2-custom-8-16384:如果是自訂機型,機型的前半部分是機器系列,但 N1 機型除外,因為 N1 機型完全不包含機器系列。custom後的第一個數字是 vCPU 數量,最後一個數字則是分配給執行個體的記憶體容量 (以 MB 為單位)。
如要進一步瞭解機型,請參閱「機器家族資源與比較指南」。