gcloud compute operations list --filter="zone:(ZONE)"
將 ZONE 替換為要查看作業清單的區域。舉例來說,如要查看 us-cental1-c 中的作業清單,請執行下列指令:
gcloud compute operations list --filter="zone:(us-central1-c)"
輸出結果會與下列內容相似:
NAME TYPE TARGET HTTP_STATUS STATUS TIMESTAMP
systemevent-1543845145000... compute.instances.migrateOnHostMaintenance us-central1-c/instances/my-instance 200 DONE 2018-12-03T05:52:25.000-08:00
REST
您必須在全域、地區或區域層級指定作業的 API 要求。即時遷移、停止 VM 和自動重新啟動都是區域層級作業。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eCompute Engine operations are logged when a resource is mutated, such as during VM updates or host events, which alter the state of a VM.\u003c/p\u003e\n"],["\u003cp\u003eOperations can be viewed using the Google Cloud console, the Google Cloud CLI (gcloud), or REST, and they may be incomplete upon initial viewing.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication is only needed for gcloud or REST usage, and the provided steps outline the necessary commands for both.\u003c/p\u003e\n"],["\u003cp\u003eCompleted operations are retained for a period ranging from a minimum of 1 hour to a maximum of 14 days, during which time they are available for viewing.\u003c/p\u003e\n"],["\u003cp\u003eTo view operations, you must specify the scope of the request as either global, region, or zone level using gcloud or REST.\u003c/p\u003e\n"]]],[],null,["# View Compute Engine operations\n\nLinux Windows\n\n*** ** * ** ***\n\nWhen you call a Compute Engine API that mutates a resource, Compute Engine adds an entry\nto the list of operations. For example, when you make an update to a VM that\nmutates (alters) data, or when a [host event](/compute/docs/instances/host-maintenance-overview)\noccurs that changes the state of a VM, operations are created. This page\ndescribes how you can view a list of Compute Engine operations by\nusing the [Google Cloud console](https://console.cloud.google.com/), the [Google Cloud CLI](/compute/docs/gcloud-compute),\nor [REST](/compute/docs/reference/rest/v1).\n\nRemember that operations can take some time to complete, so you may find\nincomplete operations while viewing. When you want to see the final status of\nincomplete operations, repeatedly viewing operations is not recommended;\ninstead, you should [wait for operations to be done](/compute/docs/api/best-practices#wait-for-operations).\n\nBefore you begin\n----------------\n\n- If you haven't already, set up [authentication](/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:\n\n Select the tab for how you plan to use the samples on this page: \n\n ### Console\n\n\n When you use the Google Cloud console to access Google Cloud services and\n APIs, you don't need to set up authentication.\n\n ### gcloud\n\n 1.\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n | **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.\n 2. [Set a default region and zone](/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).\n\n ### REST\n\n\n To use the REST API samples on this page in a local development environment, you use the\n credentials you provide to the gcloud CLI.\n 1. [Install](/sdk/docs/install) the Google Cloud CLI. After installation, [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command: \n\n ```bash\n gcloud init\n ```\n 2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\n For more information, see\n [Authenticate for using REST](/docs/authentication/rest)\n in the Google Cloud authentication documentation.\n\nOperation Retention Period\n--------------------------\n\nWhile querying operations, keep in mind that completed operations are\nautomatically removed from the database after a certain period.\n\nCompute Engine retains completed operations for at least the minimum\nretention period of 1 hour, and up to the maximum retention period of 14 days.\nAlthough projects often observe a retention period for completed operations that\nis longer than the minimum of 1 hour, depending on the additional retention\nperiod is not recommended.\n\nNote that the retention periods don't apply to operations deleted by the users\nthrough `Operations.delete` method.\n\nViewing operations\n------------------\n\nTo view a list of operations for your project, perform the following steps: \n\n### Console\n\n1. In the Google Cloud console, go to the **Operations** page.\n\n [Go to Operations](https://console.cloud.google.com/compute/operations)\n2. For more details on an operation, click the operation summary. For\n example, to view the migration details for the `my-instance` VM,\n click the **Automatically migrate an instance** operation.\n\n\n### gcloud\n\nTo view a list of operations for your project\nusing `gcloud compute`, use the [`operations list`](/sdk/gcloud/reference/compute/operations/list)\nsub-command.\n\nTo view the list of operations in a specified zone, add the `--filter` flag.\n\n\u003cbr /\u003e\n\n```\ngcloud compute operations list --filter=\"zone:(ZONE)\"\n```\n\n\u003cbr /\u003e\n\nReplace \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e with the zone where you want to view a list of\noperations. For example, to view the list of operations in `us-cental1-c`,\nrun the following command: \n\n```\ngcloud compute operations list --filter=\"zone:(us-central1-c)\"\n```\n\nThe output is similar to the following: \n\n```\nNAME TYPE TARGET HTTP_STATUS STATUS TIMESTAMP\nsystemevent-1543845145000... compute.instances.migrateOnHostMaintenance us-central1-c/instances/my-instance 200 DONE 2018-12-03T05:52:25.000-08:00\n```\n\n\u003cbr /\u003e\n\n### REST\n\nAPI requests for operations must be specified at either the [global](/compute/docs/reference/rest/v1/globalOperations/list),\n[region](/compute/docs/reference/rest/v1/regionOperations/list), or [zone](/compute/docs/reference/rest/v1/zoneOperations/list) level.\nLive migration, VM stopping, and automatic restarts are all zone-level operations.\n\nFor zone operations, make a `GET` request to the [`zoneOperations.list`](/compute/docs/reference/rest/v1/zoneOperations/list) method. \n\n```\nGET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/operations\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the project ID for this request\n- \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone for this request\n\nLeave the request body empty.\n\nThe following is a sample output for a zone operation request. In this\noutput, details for a host migration displays. \n\n```\n{\n \"kind\": \"compute#operation\",\n \"id\": \"3216798767364213712\",\n \"name\": \"systemevent-1543845145000-57c1e7574b840-a195b637-5ff74d9b\",\n \"zone\": \"https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c\",\n \"operationType\": \"compute.instances.migrateOnHostMaintenance\",\n \"targetLink\": \"https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c/instances/my-instance\",\n \"targetId\": \"3070988523247098025\",\n \"status\": \"DONE\",\n \"statusMessage\": \"Instance migrated during Compute Engine maintenance.\",\n \"user\": \"system\",\n \"progress\": 100,\n \"insertTime\": \"2018-12-03T05:52:25.000-08:00\",\n \"startTime\": \"2018-12-03T05:52:25.000-08:00\",\n \"endTime\": \"2018-12-03T05:52:25.000-08:00\",\n \"selfLink\": \"https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c/operations/systemevent-1543845145000-57c1e7574b840-a195b637-5ff74d9b\"\n}\n```"]]