VM managed instance group sizing recommender

The VM instance group sizing recommender helps you optimize the resource utilization of your Compute Engine virtual machine managed 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 groups' machine types to more efficiently use VM resources.

Sizing recommendations are also known as rightsizing recommendations.

See Applying sizing recommendations for managed instance groups for more information.

Recommender ID

The VM instance group sizing recommender ID is:

g.u.00rz.compute.instanceGroupManager.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 group sizing recommendations, use the Compute Engine zone as the location in gcloud and API interactions.

Permissions

Required permissions

To view instance group sizing recommendations:

  • recommender.computeInstanceGroupManagerMachineTypeRecommendations.get
  • recommender.computeInstanceGroupManagerMachineTypeRecommendations.list

To modify state of instance group sizing recommendations:

  • recommender.computeInstanceGroupManagerMachineTypeRecommendations.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 managed instances group based on current usage.

Operation groups

Each recommendation generated by the VM instance group sizing recommender has operation groups that describe a set of sequential actions that must be taken to apply the recommendation.

Sizing recommendation for VM instances in a managed instance group

A sizing recommendation for a VM instance group includes two OperationGroup entities.

The first specifies three operations on the compute.googleapis.com/InstanceTemplate 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/InstanceTemplate",
     "resource": "//compute.googleapis.com/projects/example-project/global/instanceTemplates/it-name",
     "path": "/properties/machineType"
     "value": "n1-standard-4"
    }
    
  2. A copy operation that creates a new instance template resource. For example:

    {
       "action": "copy",
       "resourceType": "compute.googleapis.com/InstanceTemplate",
       "sourceResource": "//compute.googleapis.com/projects/example-project/global/instanceTemplates/it-name",
       "resource": "//compute.googleapis.com/projects/p1/global/instanceTemplates/$new-it-name",
       "sourcePath": "/",
       "path": "/"
     }
    

    Where $new-it-name is the new instance template name.

  3. A replace operation that replaces the machine type on the new instance template with the recommended type:

    {
      "action": "replace",
      "resourceType": "compute.googleapis.com/InstanceTemplate",
      "resource": "//compute.googleapis.com/projects/example-project/global/instanceTemplates/$new-it-name",
      "path": "/properties/machineType",
      "value" : "n1-standard-8"
    }
    

    Where $new-it-name is the new instance template name.

The second specifies a replace operation on the compute.googleapis.com/InstanceGroupManager resource. This operation replaces the current instance template it-name with the new one specified above that uses the recommended machine type:

 {
   "action" : "replace",
   "resourceType": "compute.googleapis.com/InstanceGroupManager",
   "resource": "//compute.googleapis.com/projects/example-project/zones/z1/instanceGroupManagers/instance-group",
   "path": "/versions/*/instanceTemplate",
   "pathValueMatchers": {
     "/versions/*/instanceTemplate": {
       "matchesPattern": ".*global/instanceTemplates/it-name"
     }
   }
   "value": "global/instanceTemplates/$new-it-name"
 }

Where $new-it-name is the new instance template name.

Examples

The following example shows how to list sizing recommendations for managed instance groups:

  1. Set required environment variables:

    PROJECT=TARGET_PROJECT_ID
    LOCATION=LOCATION_ID
    RECOMMENDER=g.u.00rz.compute.instanceGroupManager.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 zone where resources associated with the recommendations are located (for example, us-central1-a).

  2. List VM instance group 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",
              "resourceType": "compute.googleapis.com/InstanceTemplate",
              "resource": "//compute.googleapis.com/projects/test-project/global/instanceTemplates/it-name",
              "path": "/properties/machineType"
              "value": "n1-standard-4"
            },
            {
              "action": "copy",
              "resourceType": "compute.googleapis.com/InstanceTemplate",
              "sourceResource": "//compute.googleapis.com/projects/test-project/global/instanceTemplates/it-name",
              "resource": "//compute.googleapis.com/projects/test-project/global/instanceTemplates/$new-it-name",
              "sourcePath": "/",
              "path": "/"
            },
            {
              "action": "replace",
              "resourceType": "compute.googleapis.com/InstanceTemplate",
              "resource": "//compute.googleapis.com/projects/test-project/global/instanceTemplates/$new-it-name",
              "path": "/name",
              "value" : "$new-it-name"
            },
            {
              "action": "replace",
              "resourceType": "compute.googleapis.com/InstanceTemplate",
              "resource": "//compute.googleapis.com/projects/test-project/global/instanceTemplates/$new-it-name",
              "path": "/properties/machineType",
              "value" : "n1-standard-8"
            }
          ]
        },
        {
          "operations" : [
            {
              "action" : "replace",
              "resourceType": "compute.googleapis.com/InstanceGroupManager",
              "resource": "//compute.googleapis.com/projects/test-project/zones/us-west1-a/instanceGroupManagers/igm-name",
              "path": "/versions/*/instanceTemplate",
              "pathValueMatchers": {
                "/versions/*/instanceTemplate": {
                  "matchesPattern" : ".*global/instanceTemplates/it-name"
                }
              }
              "value": "global/instanceTemplates/$new-it-name"
            }
          ]
        }
      ]
    },
    "description" : "Improve performance by changing machine type from n1-standard-4 to n1-standard-8.",
    "etag": "\"eebe926c12f923da\"",
    "name": "projects/823742397239/locations/us-west1-a/recommenders/g.u.00rz.compute.instanceGroupManager.MachineTypeRecommender/recommendations/0fd31b24-cc05-4132-8431-ed54a22dd4f1",
    "lastRefreshTime": {
      "seconds": 1543912652
    },
    "primaryImpact": {
      "category": "PERFORMANCE"
    },
    "additionalImpact": [
      "category": "COST",
      "costProjection": {
        "cost": {"currencyCode": "USD", "units": 50},
        "duration": { "seconds": 2592000 }
      }
    ],
    "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