Compute Engine provides idle VM recommendations to help you identify virtual machine (VM) instances that have not been used. These recommendations are generated automatically based on system metrics gathered by the Cloud Monitoring service over the previous 14 days. You can use idle VM recommendations to find and stop idle VM instances to reduce waste of resources and reduce your compute bill.
Before you begin
- If you want to use the command-line examples in this guide, do the following:
- Install or update to the latest version of the Google Cloud CLI.
- Set a default region and zone.
- If you want to use the API examples in this guide, set up API access.
Pricing
Idle VM recommendations are available free of charge.
Limitations
For standalone VMs, idle recommendations are not available in following cases:
- Instances with local SSDs
- Instances with GPU/TPUs
- App Engine flex resources
- Dataflow resources
- Google Kubernetes Engine resources
Viewing idle VM instance recommendations
To view recommendations about idle VMs, use the gcloud CLI or the API.
gcloud
Use the
gcloud recommender recommendations list
command
with --recommender=google.compute.instance.IdleResourceRecommender
:
gcloud recommender recommendations list \ --project=PROJECT_ID \ --location=ZONE \ --recommender=google.compute.instance.IdleResourceRecommender \ --format=yaml
Replace the following:
PROJECT_ID
: the ID of your projectZONE
: the zone that contains instances to list recommendations for
For example:
gcloud recommender recommendations list \ --project=my-project \ --location=us-central1-c \ --recommender=google.compute.instance.IdleResourceRecommender \ --format=yaml
If there are no idle VMs in the location, the response is empty. Otherwise, the response includes the following fields for each recommendation:
operationGroups
: groups of operations that you can perform in serial order to apply the recommendationdescription
: a human-readable explanation of the recommendation
---
content:
...
operationGroups:
- operations:
- action: test
path: /status
resource: //compute.googleapis.com/projects/my-project/zones/us-central1-c/instances/vm-name
resourceType: compute.googleapis.com/Instance
value: RUNNING
- action: replace
path: /status
resource: //compute.googleapis.com/projects/my-project/zones/us-central1-c/instances/vm-name
resourceType: compute.googleapis.com/Instance
value: TERMINATED
description: Save cost by stopping Idle VM 'vm-name'.
etag: '"83da314c23f634e1"'
lastRefreshTime: '2020-02-24T07:56:40Z'
name: projects/141732092341/locations/us-central1-c/recommenders/google.compute.instance.IdleResourceRecommender/recommendations/0e061a3a-f921-4216-b1b4-62e16942cd1a
primaryImpact:
category: COST
costProjection:
cost:
currencyCode: USD
nanos: -91533961
units: '-262'
duration: 2592000s
recommenderSubtype: STOP_VM
stateInfo:
state: ACTIVE
Learn more about working with recommendations using gcloud in gcloud examples.
API
Call the
recommendations.list
method
and use the following recommendation type:
- google.compute.instance.IdleResourceRecommender
The API call looks like:
GET https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.instance.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 bash script uses an access token returned by
Application Default Credentials,
for a curl
request. For information about about setting up Application
Default Credentials, see
Provide credentials for Application Default Credentials.
PROJECT_ID=my-project ZONE=us-central1-c RECOMMENDER_ID=google.compute.instance.IdleResourceRecommender curl -H "Authorization: Bearer $(gcloud auth application-default 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 VM recommendation:
{
"description" : "Save cost by stopping Idle VM `vm-name`",
"name": "projects/1574864402/locations/us-central1-c/recommenders/"
"google.compute.instance.IdleResourceRecommender/"
"recommendations/0fd31b24-cc05-4132-8431-ed54a22dd4f1",
"lastRefreshTime": {
"seconds": 1543912652
},
"primaryImpact": {
"category": COST,
"costProjection": {
"cost": {"currencyCode": "USD", "units": -50},
"duration": { "seconds": 2592000 }
}
},
"stateInfo": ACTIVE,
"content":
"groups" : [
{
"operations" : [
{
"action": "test",
"resourceType": "compute.googleapis.com/Instance",
"resource": "//compute.googleapis.com/projects/my-project/"
"zones/us-central1-c/instances/vm-name",
"path": "/status",
"value": "RUNNING"
},
{
"action": "replace",
"resourceType": "compute.googleapis.com/Instance",
"resource": "//compute.googleapis.com/projects/my-project/"
"zones/us-central1-c/instances/vm-name",
"path": "/status",
"value": "TERMINATED"
}
]
}
]
},
"etag" : "cb0e6ac2cfc0b591"
}
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 API contains an operations group, with operations that you can perform in serial to apply the recommendation. Idle VM recommendation operation groups include two operations:
A test operation to verify the current
status
of the VM. For example:{ "action": "test", "resourceType": "compute.googleapis.com/Instance", "resource" : "//compute.googleapis.com/projects/my-project/zones/us-central1-c/instances/vm-name", "path": "/status", "value": "RUNNING" }
A replace operation to change the
status
of the VM. For example:{ "action": "replace", "resourceType": "compute.googleapis.com/Instance", "resource" : "//compute.googleapis.com/projects/my-project/zones/us-central1-c/instances/vm-name", "path": "/status", "value": "TERMINATED" }
The first operation is a test
, which means that you should test that the
resource
is still RUNNING
. You can do this by
checking the VM state.
The second operation, replace
, means that you should replace the resource's
status
with a new value, TERMINATED
. You can do that by stopping the VM,
which is described below.
Applying idle VM recommendations
After you receive an idle VM recommendation and you decide that you no longer need the instance, use the Google Cloud console, the gcloud CLI, or the API to stop and optionally delete the instance.
If you stop but do not delete an instance and its disks, you still pay for its disks.
Console
- In the Google Cloud console, go to the VM instances page.
- Select the instance that you want to stop.
- Click Stop.
gcloud
Use the instances stop
command
and specify the VM_NAME
that you want to stop.
gcloud compute instances stop VM_NAME --zone=ZONE
Replace the following:
VM_NAME
: the name of the VM instance you want to stopZONE
: the zone that contains the instance you want to stop
API
In the API, construct a POST
request to stop an instance.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/stop
Replace the following:
PROJECT_ID
: the ID of your projectZONE
: the zone that contains the instance you want to stopVM_NAME
: the name of the VM instance you want to stop
If you're sure that the VM instance and its disks can be removed you can delete the instance.
How detection of idle VM instances works
Compute Engine generates recommendations about idle VM instances based on usage metrics from the last 14 days, or, for new VMs, starting from 5 days since VM creation. If CPU and network usage have been low during the observed period of time, the Recommender classifies the VM as idle.
To classify a VM as idle, all of the following conditions must be met:
- CPU utilization is less than 0.03 vCPUs for 97% of VM runtime.
- Received network traffic is less than 2600 bytes per second (B/s) for 95% of VM runtime.
- Sent network traffic is less than 1000 B/s for 95% of VM runtime.
Frequency of recommendations
Idle VM recommendations are initially generated after a VM is created and running for 5 days. Subsequently, recommendations are updated at least once per day.
Relation with machine type recommendations
Machine type recommendations recommend the optimal size for a VM. You might receive a machine type recommendation to downsize an idle VM.
If you must keep an idle VM running despite its low utilization, use machine type recommendations to help you choose the optimal size for underutilized VMs.
What's next
- Learn more about how stopping, resetting, and deleting a VM instance affects the instance and its resources.