本文档介绍如何查看现有虚拟机 (VM) 实例的详细信息。
查看虚拟机的详细信息有助于查看其配置和状态,例如挂接的磁盘、创建时间戳、机器类型和虚拟机 ID(可用于使用不可变值引用虚拟机)。
准备工作
- 
  
  如果您尚未设置身份验证,请进行设置。身份验证用于验证您的身份,以便访问 Google Cloud 服务和 API。如需从本地开发环境运行代码或示例,您可以通过选择以下选项之一向 Compute Engine 进行身份验证:
  
   
   
     
   
  
   
   
     
   
  
   
   
     
   
  
 
 
 
  
    
      Select the tab for how you plan to use the samples on this page: ConsoleWhen you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication. gcloud- 
 
 
  
  
   
   
  
   
   
  
   
   
     
   
  
  
   
   
  
   
   
  
   
   
  
 
 
   
   
      安装 Google Cloud CLI。 安装完成后,运行以下命令来初始化 Google Cloud CLI: gcloud init如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。 
- Set a default region and zone.
 REST如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭证。 安装 Google Cloud CLI。 安装完成后,运行以下命令来初始化 Google Cloud CLI: gcloud init如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。 如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。 所需的角色如需获得查看虚拟机详细信息的权限,请让管理员向您授予虚拟机或项目的 Compute Instance Admin (v1) ( roles/compute.instanceAdmin.v1) IAM 角色。如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。此预定义角色可提供查看虚拟机的详细信息所需的 compute.instances.get权限。查看虚拟机的详细信息如需查看虚拟机的详细信息,请选择以下选项之一: 控制台gcloud如需查看虚拟机的详细信息,请使用 gcloud compute instances describe命令。gcloud compute instances describe VM_NAME \ --zone=ZONE请替换以下内容: - VM_NAME:虚拟机名称。
- ZONE:该虚拟机所在的可用区。
 输出类似于以下内容: 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-aREST如需查看虚拟机的详细信息,请向 instances.get方法发出GET请求。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME替换以下内容: - PROJECT_ID:虚拟机所在项目的 ID。
- ZONE:该虚拟机所在的可用区。
- VM_NAME:虚拟机名称。
 输出类似于以下内容: { "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 为单位)。
 如需详细了解机器类型,请参阅机器家族资源和比较指南。 后续步骤如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。 最后更新时间 (UTC):2025-10-19。 -