Compute Engine provides recommendations to help you identify resources like persistent disks (PDs), IP addresses, and custom disk images that aren't used. You can use idle resource recommendations to help minimize waste of resources and reduce your compute bill. For PDs that are not actively used, you can create a backup snapshot then delete the resource. For unused PDs, images, and IP addresses, you can delete them if you don't need them.
If you're interested in idle VM recommendations, see Viewing and applying idle VM recommendations.
Before you begin
-
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
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- 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.
-
Pricing
Idle resources recommendations are available free of charge.
Recommendation generation
If a resource has not been attached to a VM or other resource for 15 days, the Recommender classifies that resource as idle.
One of the following conditions must be met in order to classify a resource as idle and generate the corresponding recommended action:
Resource | Condition for resource to be classified as idle | Recommended action | Savings |
---|---|---|---|
PD | Created at least 15 days ago AND Never attached to a VM AND Is blank |
Delete | Save 100% of the cost of that disk (see disk pricing) |
PD | Detached for at least 15 days | Create snapshot and delete | Reduce the maintenance cost of that disk by 35% to 92% (see disk pricing) |
Custom image | Not used to create a disk for at least 15 days AND Not used in any instance template | Delete | Save 100% of the cost of that image (see image pricing) |
IP address | Not attached to any resource for at least 15 days | Delete | Save 100% of the cost of that IP address (see IP pricing) |
Recommendation frequency
Idle resource recommendations begin 15 days after resource creation, and they are updated once every 24 hours.
Viewing recommendations
To view recommendations about idle resources, use the gcloud CLI or REST.
Console
In the Google Cloud console, go to the Recommendations page.
All idle resources are listed under Unused Compute Engine resources.
gcloud
Use the
gcloud recommender recommendations list
command
with the --recommender=
RECOMMENDER_ID
flag:
gcloud recommender recommendations list \ --project=PROJECT_ID \ --location=LOCATION \ --recommender=RECOMMENDER_ID \ --format=yaml
Replace the following:
PROJECT_ID
: the ID of your project.LOCATION
: the location that contains the resources for which you want recommendations.- For PDs specify a zone or region, for example,
us-central1-c
. - For IPs:
- To list regional IPs, you must specify a region.
- To list global IPs, specify
global
. For more information about regional and global IP address resources, see IP addresses.
- For custom images specify
global
.
- For PDs specify a zone or region, for example,
RECOMMENDER_ID
: the id of recommender- For disks, specify
google.compute.disk.IdleResourceRecommender
. - For images, specify
google.compute.image.IdleResourceRecommender
. - For IPs, specify
google.compute.address.IdleResourceRecommender
.
- For disks, specify
For example, the following command lists idle PD recommendations in
us-central1-c
for test-project
:
gcloud recommender recommendations list \
--project=test-project \
--location=us-central1-c \
--recommender=google.compute.disk.IdleResourceRecommender \
--format=yaml
---
content:
operationGroups:
- operations:
- action: add
resource: //compute.googleapis.com/projects/test-project/global/snapshots/$snapshot-name
resourceType: compute.googleapis.com/Disk
path: /
value:
- name: $snapshot-name
sourceDisk: projects/test-project/locations/us-central1-c/disks/pd-name
storageLocations: us-central1
- action: remove
resource: //compute.googleapis.com/projects/test-project/zones/us-central1-c/disks/pd-name
resourceType: compute.googleapis.com/Disk
path: /
description: Save cost by snapshotting and then deleting idle persistent disk 'pd-name'
name: projects/test-project/locations/us-central1-c/recommenders/google.compute.disk.IdleResourceRecommender/recommendations/0fd31b24-cc05-4132-8431-ed54a22dd4f1
recommenderSubtype: SNAPSHOT_AND_DELETE_DISK
lastRefreshTime:
seconds: 1543912652
primaryImpact:
category: COST
costProjection:
cost:
currencyCode: USD
units: '-50'
duration:
seconds: 2592000
stateInfo: ACTIVE
etag: "cb0e6ac2cfc0b591"
Learn more about using gcloud CLI to work with recommendations.
REST
Call the
recommendations.list
method
and specify the recommender id,
for example google.compute.disk.IdleResourceRecommender
:
GET https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/recommenders/RECOMMENDER_ID/recommendations
Replace the following:
PROJECT_ID
: the ID of your project.LOCATION
: the location that contains the resources for which you want recommendations.- For PDs specify a zone or region, for example,
us-central1-c
. - For IPs:
- To list regional IPs, you must specify a region.
- To list global IPs, specify
global
. For more information about regional and global IP address resources, see IP addresses.
- For custom images specify
global
.
- For PDs specify a zone or region, for example,
RECOMMENDER_ID
: the id of recommender- For disks, specify
google.compute.disk.IdleResourceRecommender
. - For images, specify
google.compute.image.IdleResourceRecommender
. - For IPs, specify
google.compute.address.IdleResourceRecommender
.
- For disks, specify
The following example shows out to send a request with curl
, and the
associated sample response.
PROJECT_ID=test-project LOCATION=us-central1-c RECOMMENDER_ID=google.compute.disk.IdleResourceRecommender curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \ https://recommender.googleapis.com/v1/projects/$PROJECT_ID/locations/$LOCATION/recommenders/$RECOMMENDER_ID/recommendations
Example JSON response for idle PD recommendation:
{ "description" : "Save cost by deleting idle persistent disk 'pd-name'", "name": "projects/test-project/locations/us-central1-c/recommenders/" "google.compute.disk.IdleResourceRecommender/" "recommendations/0fd31b24-cc05-4132-8431-ed54a22dd4f1", "recommenderSubtype" : "SNAPSHOT_AND_DELETE_DISK", "lastRefreshTime": { "seconds": 1543912652 }, "primaryImpact": { "category": COST, "costProjection": { "cost": {"currencyCode": "USD", "units": -50}, "duration": { "seconds": 2592000 } } }, "stateInfo": ACTIVE, "content": { "operationGroups" : [ { "operations" : [ { "action": "add", "resourceType": "compute.googleapis.com/Disk", "resource" : "//compute.googleapis.com/projects/test-project/global/snapshots/$snapshot-name", "value": { "name": "$snapshot-name", "sourceDisk": "projects/test-project/zones/us-central1-c/disks/pd-name", "storageLocations": ["us-central1"], } }, { "action": "remove", "resourceType": "compute.googleapis/Disk", "resource": "//compute.googleapis.com/projects/test-project/" "zones/us-central1-c/disks/pd-name" } ] } ] }, "associatedInsights": [ { "insight": "projects/test-project/locations/us-central1-c/insightTypes/google.compute.disk.IdleResourceInsight/insights/31326443-bcc3-4776-9b86-48879fddb656" } ], "etag": "cb0e6ac2cfc0b591" }
Interpreting the recommendation response
Each recommendation that you receive through the gcloud CLI or REST contains operation groups, with operations that you can perform in serial to apply the recommendation. For example, idle PD recommendation operation groups include one or two operations:
If your idle PD has data on it, the recommendation includes an
add
operation to create a snapshot to back up the PD. For example:{ "action": "add", "resourceType": "compute.googleapis.com/Disk", "resource" : "//compute.googleapis.com/projects/test-project/global/snapshots/$snapshot-name", "path": "/", "value": { "name": "$snapshot-name", "sourceDisk": "projects/test-project/zones/us-central1-c/disks/pd-name", "storageLocations": ["us-central1"] } }
A
remove
operation to permanently delete the idle PD. For example:{ "action": "remove", "resourceType": "compute.googleapis.com/Disk", "resource" : "//compute.googleapis.com/projects/test-project/zones/us-central1-c/disks/pd-name", "path": "/" }
See Applying idle PD recommendations to create a snapshot of and to delete a PD, deleting idle IPs to remove unused IP addresses, and deleting idle custom images to remove unused custom disk images.
Viewing insights for idle resource recommendations
The Recommender generates recommendations based on resource insights. By viewing insights on resources you can learn more about those resources, such as how long a resource has been detached from a VM or whether a PD is blank.
If you want to view the insight that generated the recommendation, you can use the gcloud CLI or REST.
gcloud
Use the insights list
command
gcloud beta recommender insights list --project=PROJECT_NAME \ --location=LOCATION --insight-type=INSIGHT_TYPE
Replace the following:
LOCATION
: the location that contains the resources for which you want insights.- For PDs specify a zone or region, for example,
us-central1-c
. - For IPs:
- To list regional IPs, you must specify a region.
- To list global IPs, specify
global
. For more information about regional and global IP address resources, see IP addresses.
- For custom images specify
global
.
- For PDs specify a zone or region, for example,
INSIGHT_TYPE
: the id of the insight type- For disks, specify
google.compute.disk.IdleResourceInsight
. - For images, specify
google.compute.image.IdleResourceInsight
. - For IPs, specify
google.compute.address.IdleResourceInsight
.
- For disks, specify
REST
Use the insights.list
method.
GET https://recommender.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/insightTypes/INSIGHT_TYPE/insights
Replace the following:
PROJECT_ID
: the ID of your project.LOCATION
: the location that contains the resources for which you want insights.- For PDs specify a zone or region, for example,
us-central1-c
. - For IPs:
- To list regional IPs, you must specify a region.
- To list global IPs, specify
global
. For more information about regional and global IP address resources, see IP addresses.
- For custom images specify
global
.
- For PDs specify a zone or region, for example,
INSIGHT_TYPE
: the id of the insight type- For disks, specify
google.compute.disk.IdleResourceInsight
. - For images, specify
google.compute.image.IdleResourceInsight
. - For IPs, specify
google.compute.address.IdleResourceInsight
.
- For disks, specify
Here is an example response of an insight on an idle PD resource:
{ "name": "projects/test-project/locations/us-central1-c/insightTypes/google.compute.disk.IdleResourceInsight/insights/0ec21a13-bb04-3121-7321-dc43a11cc3e2", "description": "Disk 'pd-name' in zone 'us-central1-c' was last used 17 days ago. Consider taking snapshot and delete it.", "targetResources": [ "//compute.googleapis.com/projects/test-project/zones/us-central1-c/disks/pd-name" ], "insightSubtype": "IDLE_DISK", "content": { "diskLastUseTime": "2019-10-01 13:00:00", "isBlank": false, }, "lastRefreshTime": "2019-10-10 13:00:00", "observationPeriod": "15 days", "stateInfo": { "state": "ACTIVE" }, "category": "COST", "etag": "fds421j2349", "associatedRecommendations": [ { "projects/test-project/locations/us-central1-c/recommenders/" "google.compute.disk.IdleResourceRecommender/" "recommendations/0fd31b24-cc05-4132-8431-ed54a22dd4f1" } ] }
The example response includes the following fields:
diskLastUseTime
: The last time when the disk was attached to a VM. If the disk was never attached to a VM this is set to the disk's creation time.isBlank
: This field is set totrue
if disk is blank and was never attached to VM. Otherwise it isfalse
.
For more information about insights, see the reference docs.
Applying idle resource recommendations
If you receive a recommendation about an idle resource and you decide that you want to follow the recommendation, follow the instructions below.
Deleting idle IP address
See the addresses.delete
method,
gcloud compute addresses delete
command,
or the Releasing a static external IP address
documentation.
Deleting idle custom images
See the images.delete
method,
gcloud compute images delete
command,
or the Deleting an image
documentation.
Applying idle PD recommendations
If you need to create a snapshot of a PD prior to deleting it, see Creating persistent disk snapshots.
To delete an idle PD, see the gcloud compute disks delete
command.
For information about how to recover data from a snapshot and recreate your PD, see Restoring snapshots.