このページでは、予約に関する推奨事項を使用してアイドル状態のオンデマンド予約を特定して削除する方法について説明します。この目的は、使用していないリソースに対する料金請求を防ぐことです。
- 予約に関する推奨事項がどのように Compute Engine によって生成されるかについては、アイドル状態の予約と十分に活用されていない予約の検出の仕組みをご覧ください。
- 受け取る推奨事項の数を増やす、または減らすように予約 Recommender を構成する方法については、アイドル状態の予約に関する推奨事項を構成するまたは使用率が低い予約に関する推奨事項を構成するをご覧ください。
始める前に
- 制限事項を参照して、予約がアイドル状態の予約に関する推奨事項をサポートしているかどうかを確認します。
-
まだ設定していない場合は、認証を設定します。認証とは、 Google Cloud サービスと API にアクセスするために ID を確認するプロセスです。ローカル開発環境からコードまたはサンプルを実行するには、次のいずれかのオプションを選択して Compute Engine に対する認証を行います。
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
ZONE
は、推奨事項を一覧取得する予約を含むゾーンに置き換えます。PROJECT_ID
はプロジェクトの ID に置き換えます。operationGroups
: 推奨事項を適用する際に実行できるオペレーションのグループdescription
: 推奨事項の説明- google.compute.IdleResourceRecommender
- Compute Engine の予約の仕組みに関する詳細を確認する。
- アイドル状態の VM に関する推奨事項を構成する方法を学習する。
- 使用率が低い予約に関する推奨事項を構成する方法を学習する。
REST
このページの REST API サンプルをローカル開発環境で使用するには、gcloud CLI に指定した認証情報を使用します。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳細については、 Google Cloud 認証ドキュメントの REST を使用して認証するをご覧ください。
アイドル状態の予約に関する推奨事項を表示する
アイドル状態の予約に関する推奨事項を表示するには、次のいずれかの方法を使用します。
次のいずれかの方法でこのタスクを完了します。
コンソール
Google Cloud コンソールで、[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
次のように置き換えます。
次に例を示します。
gcloud recommender recommendations list \ --location=us-central1-c \ --recommender=google.compute.IdleResourceRecommender \ --format=yaml \ --project=my-project
ロケーションにアイドル状態の VM がない場合、レスポンスは空になります。それ以外の場合、レスポンスには推奨事項ごとに次のフィールドが含まれます。
--- 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
リクエストを行い、次の推奨事項タイプを使用します。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" }
アイドル状態の予約に関する推奨事項を適用する
アイドル状態の予約に関する推奨事項に基づいて、予約サイズを調整するか、不要になった場合は予約を削除します。
次のステップ
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-11 UTC。
-