View and apply idle reservation recommendations


This page describes how you can use idle reservation recommendations to identify and delete idle on-demand reservations, so that you can avoid being charged for resources that you're not using.

Before you begin

  • Review the limitations to check if your reservation supports idle reservation recommendations.
  • If you haven't already, set up authentication. Authentication is the process by which your identity is verified for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine as follows.

    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

    1. Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init
    2. Set a default region and zone.

    REST

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.

      Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init

    For more information, see Authenticate for using REST in the Google Cloud authentication documentation.

View idle reservation recommendations

To view recommendations about idle reservations, use one of the following options.

Console

In the Google Cloud console, go to the FinOps hub.

Go to FinOps hub

gcloud

To view recommendations about idle reservations, use the gcloud recommender recommendations list command with the --recommender=google.compute.IdleResourceRecommender flag:

gcloud recommender recommendations list \
  --location=ZONE \
  --recommender=google.compute.IdleResourceRecommender \
  --format=yaml

Replace ZONE with the zone that contains reservations to list recommendations for.

For example:

gcloud recommender recommendations list \
  --location=us-central1-c \
  --recommender=google.compute.IdleResourceRecommender \
  --format=yaml

If there are no idle reservations in the location, the response is empty. Otherwise, the response includes the following fields for each recommendation:


---
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

Learn more about working with recommendations using Google Cloud CLI in gcloud examples.

REST

To view recommendations about idle reservations, make a GET request to the recommendations.list method and use the following recommendation type:

  • google.compute.IdleResourceRecommender

The API call looks like:

GET https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.IdleResourceRecommender/recommendations

Replace the following:

  • PROJECT_ID: the ID of your project.
  • ZONE: the zone that contains instances to list recommendations for.

The following example shows out to send a request with curl, and the associated sample response.

nimishc - this response needs to be updated

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

Example JSON response for an idle reservation recommendation:

{
  "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"
  ]
}

You can find more details about each field in the Recommender API documentation.

Interpreting the recommendation response

Each recommendation that you receive through the gcloud CLI or REST contains an operations group, with operations that you can perform in serial to apply the recommendation. For idle reservations, the operation groups include a remove operation to delete the reservation:

{
  "action": "remove",
  "path": "/",
  "resource": "//compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation",
  "resourceType": "compute.googleapis.com/Reservation"
}

Apply idle reservation recommendations

After you receive an idle reservation recommendation and you decide that you no longer need the resources, delete the reservation.

What's next