本文說明如何查看現有虛擬機器 (VM) 執行個體的詳細資料。
查看 VM 詳細資料有助於瞭解其設定和狀態,例如連接的磁碟、建立時間戳記、機型和 VM ID。您可以使用 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 instances」(VM 執行個體) 頁面中顯示的預設欄。您可以按一下「資料欄顯示選項」,變更每個 VM 顯示的資料欄。
在「名稱」欄中,按一下 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-11-bullseye
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-11-bullseye"
],
"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 記憶體的比例。因此,這個機器類型會有 88 GB 的 RAM。standard、highmem、highcpu、ultamem和megamem機型的記憶體與 CPU 比率可能因各個機器系列而略有不同,因此請參閱機器系列頁面,瞭解各機型分配到的確切記憶體量。n2-custom-8-16384:如果是自訂機器類型,機器類型的第一部分是機器系列,但 N1 機器類型除外,因為這類機器類型完全不包含機器系列。custom後的第一個數字是 vCPU 數量,最後一個數字是分配給執行個體的記憶體容量 (以 MB 為單位)。
如要進一步瞭解機器類型,請參閱機器系列資源和比較指南。