VM instance sizing recommender

The VM instance sizing recommender helps you optimize the resource utilization of your Compute Engine virtual machine instances. These recommendations are generated automatically based on system metrics or metrics gathered by the Stackdriver Monitoring service over the previous 8 days. You can use these recommendations to resize your instance machine types to more efficiently use VM resources.

Sizing recommendations are also known as rightsizing recommendations.

See Applying sizing recommendations for VM instances for more information.

Recommender ID

The VM instance sizing recommender ID is:

g.u.00rz.compute.instance.MachineTypeRecommender

You use this ID when you view and modify recommendations using gcloud commands, or the REST and RPC APIs.

Location

The Recommender gcloud commands and APIs require you to specify a location for recommendations that you view or modify. For VM instance sizing recommendations, use the Compute Engine zone as the location in gcloud and API interactions.

Permissions

Required permissions

To view VM instance sizing recommendations:

  • recommender.computeInstanceMachineTypeRecommendations.get
  • recommender.computeInstanceMachineTypeRecommendations.list

To modify state of VM instance sizing recommendations:

  • recommender.computeInstanceMachineTypeRecommendations.update

Granting Permissions

To grant these permissions, assign roles as follows:

  • To view recommendations only, grant the Compute Recommender Viewer (roles/recommender.computeViewer) role.
  • To view and modify recommendations, grant the Compute Recommender Admin (roles/recommender.computeAdmin) role.
  • To grant the serviceusage.services.use permission, grant the Service Usage Consumer role (roles/serviceusage.serviceUsageConsumer).

As an alternative, you can also grant the following primitive roles:

  • To view recommendations only, grant the Viewer (roles/viewer) role.
  • To view and modify recommendations, grant the Owner (roles/owner) or Editor (roles/editor) role.
    • These roles also include the serviceusage.services.use permission.

Recommendation Subtypes

This Recommender supports the following subtypes:

  • CHANGE_MACHINE_TYPE - Recommends changing the current machine type of a virtual machine instances based on current usage.

Operation groups

Each recommendation generated by the VM instance sizing recommender has an operation group that describes a set of actions that must be taken in order to apply the recommendation.

Sizing recommendation for a standalone VM instance

A sizing recommendation for a standalone VM instance includes one OperationGroup with two operations on the compute.googleapis.com/Instance resource:

  1. A test operation to make sure that the current machine type is the same as when the recommendation was made. For example:

    {
     "action": "test",
     "resourceType": "compute.googleapis.com/Instance",
     "resource" : "//compute.googleapis.com/projects/example-project/zones/z1/instances/vm-name",
     "path": "/machineType",
     "valueMatcher": {
       "matchesPattern": ".*zones/us-central1-f/machineTypes/n1-standard-32"
     }
    }
    
  2. A replace operation that replaces the machine type with the recommended type. For example:

     {
       "action": "replace",
       "resourceType": "compute.googleapis.com/Instance",
       "resource" : "//compute.googleapis.com/projects/example-project/zones/z1/instances/vm-name",
       "path": "/machineType",
       "value": "zones/us-central1-f/machineTypes/n1-standard-4"
     }
    

Examples

The following example shows how to list VM instance sizing recommendations:

  1. Set required environment variables:

    PROJECT=TARGET_PROJECT_ID
    LOCATION=LOCATION_ID
    RECOMMENDER=g.u.00rz.compute.instance.MachineTypeRecommender
    

    where:

    • TARGET_PROJECT_ID is the project whose recommendations you want to list. This can be a different project than your current project.

      • For gcloud commands, you must use the project ID
      • For API requests, you can use the project number or project ID. Project number is recommended.

      The project number is returned in responses from both the API and gcloud commands.

    • LOCATION_ID is the GCP location where resources associated with the recommendations are located (for example, us-central1-a).

  2. List VM instance sizing recommendations:

    gcloud

    Enter the following:

    gcloud beta recommender recommendations list \
        --project=${PROJECT} \
        --location=${LOCATION} \
        --recommender=${RECOMMENDER} \
        --format=json
    

    REST

    Enter the following:

    curl \
        -H "Authorization: Bearer $(gcloud auth print-access-token)"  \
        -H "x-goog-user-project: ${PROJECT}" \
        "https://recommender.googleapis.com/v1beta1/projects/${PROJECT}/locations/${LOCATION}/recommenders/${RECOMMENDER}/recommendations"
    

The output is similar to the following:

[
  {
    "content": {
     "operationGroups": [
        {
          "operations": [
            {
              "action": "test",
              "path": "/machineType",
              "resource": "//compute.googleapis.com/projects/example-project/zones/us-central1-a/instances/instance-1",
              "resourceType": "compute.googleapis.com/Instance",
              "valueMatcher": {
                "matchesPattern": ".*zones/us-central1-a/machineTypes/n1-standard-4"
              }
            },
            {
              "action": "replace",
              "path": "/machineType",
              "resource": "//compute.googleapis.com/projects/example-project/zones/us-central1-a/instances/instance-1",
              "resourceType": "compute.googleapis.com/Instance",
              "value": "zones/us-central1-a/machineTypes/custom-2-5120"
            }
          ]
        }
      ]
    },
    "description": "Save cost by changing machine type from n1-standard-4 to custom-2-5120.",
    "etag": "280b34810bba8a1a",
    "lastRefreshTime": "2019-06-28T06:49:21Z",
    "name": "projects/548293842938/locations/us-central1-a/recommenders/g.u.00rz.compute.instance.MachineTypeRecommender/recommendations/a523ff7e-ed03-4143-a3a5-5b396b99cba9",
    "primaryImpact": { ... }
    },
    "stateInfo": {
      "state": "ACTIVE"
    },
    "recommenderSubtype": "CHANGE_MACHINE_TYPE"
  }
]

See Using the API for instructions on performing additional tasks on recommendations using the Recommender gcloud commands and APIs.

Was this page helpful? Let us know how we did:

Send feedback about...

Recommender Documentation