本頁說明如何使用預留建議找出並刪除未充分利用的隨需預留項目,避免為未使用的資源支付費用。
- 如要進一步瞭解如何設定預留項目推薦工具,以接收更多或更少的建議,請參閱「設定使用率偏低的預留項目建議」或「設定閒置預留項目建議」。
事前準備
- 請參閱限制,確認預留項目是否支援使用率偏低的預留項目建議。
-
如果尚未設定驗證,請先完成設定。
驗證程序會確認您的身分,以便授予 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 進行驗證」。
查看未充分運用的預留項目建議
如要查看使用率偏低的預留項目建議,請使用下列其中一個選項。
請使用下列任一方法完成這項工作。
控制台
前往 Google Cloud 控制台的「FinOps hub」(FinOps 中心)。
在「最佳最佳化建議」部分下方,您可以查看未充分利用預訂的建議。

在「Top Recommendations」(最佳建議) 部分,按一下與使用率偏低的預留項目相關的建議。
點選建議後,「Insight」(洞察) 部分會顯示使用率偏低的程度。
系統會開啟頁面,顯示建議的詳細資料。在「洞察」部分,您可以查看資源閒置程度。
如要查看預留項目的詳細資料,請按一下「View reservations」(查看預留項目)。
按一下「查看預留項目詳細資料」,即可查看「使用率」部分,其中會顯示預留項目大小和實際使用率。
按一下「編輯」即可啟用「設定」部分,您可以在這裡為 VM 數量設定新值,更符合預期用途。
如果不再需要預留資源,請刪除預留項目。
gcloud
如要查看有關保留項目使用率偏低的建議,請使用
gcloud recommender recommendations list指令,並加上--recommender=google.compute.RightSizeResourceRecommender旗標:gcloud recommender recommendations list \ --location=ZONE \ --recommender=google.compute.RightSizeResourceRecommender \ --format=yaml \ --project=PROJECT_ID
更改下列內容:
ZONE,其中包含要列出建議的預訂項目。- 將
PROJECT_ID替換為專案的 ID。
例如:
gcloud recommender recommendations list \ --location=us-central1-c \ --recommender=google.compute.RightSizeResourceRecommender \ --format=yaml \ --project=my-project
如果該地點沒有未充分利用的預訂,回應會是空白。否則,回應會包含每項建議的下列欄位:
operationGroups:您可以執行這些作業群組,套用最佳化建議description:建議說明
--- associatedInsights: - insight: projects/953727763714/locations/us-central1-f/insightTypes/google.compute.RightSizeResourceRecommender/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 underutilized reservation test-reservation etag: '"aff724ab8e40e1ef"' lastRefreshTime: '2024-06-10T07:00:00Z' name: projects/953727763714/locations/us-central1-f/recommenders/google.compute.RightSizeResourceRecommender/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
如要查看有關預訂資源使用率偏低的建議,請向
GET方法提出要求:recommendations.list並使用下列建議類型:- google.compute.RightSizeResourceRecommender
API 呼叫如下所示:
GET https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.RightSizeResourceRecommender/recommendations
請替換下列項目: -
PROJECT_ID:專案的 ID。 -ZONE:包含要列出建議的執行個體的可用區。以下範例說明如何使用
curl傳送要求,以及相關聯的回應範例。PROJECT_ID=my-project ZONE=us-central1-c RECOMMENDER_ID=google.compute.RightSizeResourceRecommender 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.RightSizeResourceRecommender/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 underutilized reservation test-reservation", "etag": "\"8d5603cac8fa9342\"", "lastRefreshTime": "2024-06-11T07:00:00Z", "name": "projects/9531234763714/locations/us-central1-f/recommenders/google.compute.RightSizeResourceRecommender/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 預留資源的運作方式。
- 瞭解如何設定資源用量不足的預訂建議。
- 瞭解如何設定閒置預訂建議。