本頁說明如何使用預訂建議找出並刪除閒置的隨選預訂項目,避免系統針對您未使用的資源收費。
- 如要進一步瞭解 Compute Engine 如何產生預留項目建議,請參閱「閒置和未充分利用預留項目的偵測方式」。
- 如要進一步瞭解如何設定預留項目建議工具,以便接收更多或更少的建議,請參閱「設定閒置預留項目建議」或「設定未充分利用的預留項目建議」。
事前準備
- 請查看限制,確認預留項目是否支援閒置預留項目建議。
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Trusted Cloud by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
- Set a default region and zone.
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
詳情請參閱 Trusted Cloud 驗證說明文件中的「Authenticate for using REST」。
查看閒置預留項目建議
如要查看閒置預訂的相關建議,請使用下列其中一個選項。
請使用下列其中一種方法完成這項工作。
主控台
在 Trusted Cloud 控制台,前往「FinOps hub」(FinOps 中心)。
gcloud
如要查看閒置預訂項目的相關建議,請使用
gcloud recommender recommendations list
指令,並加上--recommender=google.compute.IdleResourceRecommender
旗標:gcloud recommender recommendations list \ --location=ZONE \ --recommender=google.compute.IdleResourceRecommender \ --format=yaml \ --project=PROJECT_ID
更改下列內容:
ZONE
,其中包含要列出建議的預訂項目。- 將
PROJECT_ID
替換為專案的 ID。
例如:
gcloud recommender recommendations list \ --location=us-central1-c \ --recommender=google.compute.IdleResourceRecommender \ --format=yaml \ --project=my-project
如果該地點沒有閒置預訂,回應會是空白。否則,回應會包括每個建議的下列各欄位:
operationGroups
:可執行的一組作業,用於套用最佳化建議description
:建議說明
--- associatedInsights: - insight: projects/953727763714/locations/us-central1-f/insightTypes/google.compute.IdleResourceInsight/insights/ecf77776-4a2a-4e6e-aad2-b7f9c632e5f9 content: operationGroups: - operations: - action: remove path: / resource: //compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation resourceType: compute.googleapis.com/Reservation overview: currentReservation: machineType: n1-standard-1 reservationName: test-reservation reservedMachineCount: '1' zone: us-central1-f description: Save cost by deleting the idle reservation test-reservation etag: '"aff724ab8e40e1ef"' lastRefreshTime: '2024-06-10T07:00:00Z' name: projects/953727763714/locations/us-central1-f/recommenders/google.compute.IdleResourceRecommender/recommendations/56f8ac5d-8380-4cb8-a76f-bbc270fb4b8e primaryImpact: category: COST costProjection: cost: currencyCode: USD nanos: -199820000 units: '-1072' costInLocalCurrency: currencyCode: USD nanos: -199820000 units: '-1072' duration: 2592000s priority: P2 recommenderSubtype: DELETE_RESERVATION stateInfo: state: ACTIVE targetResources: - //compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation
如要進一步瞭解如何使用 Google Cloud CLI 處理建議,請參閱 gcloud 範例。
REST
如要查看閒置預訂項目的相關建議,請向
recommendations.list
方法發出GET
要求,並使用下列建議類型:- google.compute.IdleResourceRecommender
API 呼叫如下所示:
GET https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.IdleResourceRecommender/recommendations
請替換下列項目: -
PROJECT_ID
:專案 ID。 -ZONE
:包含要列出建議的執行個體。以下範例說明如何使用
curl
傳送要求,以及相關聯的回應範例。PROJECT_ID=my-project ZONE=us-central1-c RECOMMENDER_ID=google.compute.IdleResourceRecommender curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: $PROJECT_ID" \ https://recommender.googleapis.com/v1/projects/$PROJECT_ID/locations/$ZONE/recommenders/$RECOMMENDER_ID/recommendations
閒置預訂建議的 JSON 回應範例:
{ "associatedInsights": [ { "insight": "projects/9531234763714/locations/us-central1-f/insightTypes/google.compute.IdleResourceInsight/insights/ecf77776-4a2a-4e6e-aad2-b7f9c632e5f9" } ], "content": { "operationGroups": [ { "operations": [ { "action": "remove", "path": "/", "resource": "//compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation", "resourceType": "compute.googleapis.com/Reservation" } ] } ], "overview": { "currentReservation": { "machineType": "n1-standard-1", "reservationName": "test-reservation", "reservedMachineCount": "1", "zone": "us-central1-f" } } }, "description": "Save cost by deleting the idle reservation test-reservation", "etag": "\"8d5603cac8fa9342\"", "lastRefreshTime": "2024-06-11T07:00:00Z", "name": "projects/9531234763714/locations/us-central1-f/recommenders/google.compute.IdleResourceRecommender/recommendations/56f8ac5d-8380-4cb8-a76f-bbc270fb4b8e", "primaryImpact": { "category": "COST", "costProjection": { "cost": { "currencyCode": "USD", "nanos": -199820000, "units": "-1072" }, "costInLocalCurrency": { "currencyCode": "USD", "nanos": -199820000, "units": "-1072" }, "duration": "2592000s" } }, "priority": "P2", "recommenderSubtype": "DELETE_RESERVATION", "stateInfo": { "state": "ACTIVE" }, "targetResources": [ "//compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation" ] }
如要進一步瞭解各個欄位,請參閱 Recommender API 說明文件。
解讀建議回應
透過 gcloud CLI 或 REST 接收的每項建議都包含一組作業,您可以按順序執行這些作業來套用建議。如果是閒置預留項目,作業群組會包含
remove
作業,可刪除預留項目:{ "action": "remove", "path": "/", "resource": "//compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation", "resourceType": "compute.googleapis.com/Reservation" }
套用閒置預留項目建議
根據閒置預留項目建議,您可以調整預留項目大小,或在不再需要時刪除預留項目。
後續步驟
- 進一步瞭解 Compute Engine 預留資源的運作方式。
- 瞭解如何設定閒置預訂建議。
- 瞭解如何設定未充分利用的預訂建議。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-18 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-18 (世界標準時間)。"],[[["\u003cp\u003eThis document outlines how to use reservation recommendations to identify and delete idle on-demand reservations, helping you avoid unnecessary charges.\u003c/p\u003e\n"],["\u003cp\u003eIdle reservation recommendations are generated by Compute Engine, and they can be configured to receive more or fewer recommendations.\u003c/p\u003e\n"],["\u003cp\u003eTo view idle reservation recommendations, you can use the Google Cloud console, the gcloud command-line tool, or the REST API, all of which are detailed in this document.\u003c/p\u003e\n"],["\u003cp\u003eThe recommendations received will detail operations, such as a \u003ccode\u003eremove\u003c/code\u003e action, that you can perform to delete the reservation that is detected as idle, including examples of the associated gcloud and REST commands.\u003c/p\u003e\n"],["\u003cp\u003eIdle reservation recommendations can be applied by either adjusting the reservation size or deleting it if it's no longer needed, as well as other learning material to help the user understand more.\u003c/p\u003e\n"]]],[],null,[]] -