Using multiple policies

Create an autoscaler with multiple policies and the autoscaler will scale based on the policy that provides the largest number of virtual machines in the group. This ensures that there is always enough virtual machines to handle your application workloads and lets you scale applications with multiple possible bottlenecks.

Before you begin

How autoscaler handles multiple policies

The autoscaler handles multiple policies by calculating the recommended number of virtual machines for each policy and then picking the policy that leaves the largest number of virtual machines in the group.

An autoscaler can handle one policy per metric type except in the case of Cloud Monitoring metrics; you can choose up to five policies for Cloud Monitoring metrics. For example, you can create an autoscaler that uses one CPU utilization policy, one load balancing policy, and up to five custom metric policies.

For example, if you defined an autoscaler with all of the following policy definitions:

  • cpuUtilization with target of 0.8.
  • loadBalancingUtilization with target of 0.6.
  • customMetricUtilization for metric1 with target of 1000.
  • customMetricUtilization for metric2 with target of 2000.

And the autoscaler measures the following average values for the managed instance group that contains 10 virtual machines:

  • 0.5 for CPU utilization.
  • 0.4 load balancing utilization.
  • 1100 for metric1.
  • 2700 for metric2.

Using the average values, the autoscaler calculates recommended changes to the number of virtual machines, based on each policy:

  • 7 virtual machines based on CPU utilization.
  • 7 virtual machines based on load balancing utilization.
  • 11 virtual machines based on metric1.
  • 14 virtual machines based on metric2.

Given that there is more than one policy for this autoscaler, the autoscaler chooses the largest recommend value, in this case, 14 machines, and resizes the managed instance group to 14 virtual machines.

Create an autoscaler with multiple policies

Creating an autoscaler with multiple policies is slightly different depending on whether you are using the gcloud command-line tool or the API.


  1. Go to the Instance groups page.
  2. Select the desired instance group from the list and click Edit.
  3. On the instance group details page under Autoscaling, select On from the drop-down menu to turn on autoscaling.
  4. In the Autoscale based on section, select Multiple metrics from drop-down menu.

    Screenshot selecting multiple policies

  5. Fill in fields for CPU utilization and load balancing utilization, if desired.

  6. To add custom metric policies, click the + icon under the Target monitoring metrics section and fill in the fields for a custom metric policy.

    Screenshot showing custom metrics

    You can add multiple custom metric policies by clicking the + icon.


To create an autoscaler with multiple policies, pass in multiple policy specifications using the respective command-line flags. The following command creates an autoscaler that uses CPU utilization and two custom metrics:

gcloud compute instance-groups managed set-autoscaling example-managed-instance-group \
    --target-cpu-utilization 0.8 \
    --custom-metric-utilization,utilization-target=1000.0,utilization-target-type=GAUGE \
    --custom-metric-utilization,utilization-target=2000.0,utilization-target-type=DELTA_PER_SECOND \
    --max-num-replicas 50

With the exception of the custom metric flags, you can only pass in one flag maximum for each metric type.

For custom metrics, you can provide multiple custom metrics by repeating the following flags:

--custom-metric-utilization metric=METRIC,utilization-target=TARGET,utilization-target-type=TYPE


In the API, make a POST request with the request body containing all of the desired policies:


  "autoscalingPolicy" : {
      "utilizationTarget": 0.8
        "metric": "",
        "utilizationTarget": 1000,
        "metric": "",
        "utilizationTarget": 2000,
        "utilizationTargetType": "DELTA_PER_SECOND"
      "utilizationTarget": 0.6
    "maxNumReplicas": 50,
    "minNumReplicas": 1
  "target": "",
  "name": "example-autoscaler"