A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://cloud.google.com/compute/docs/autoscaler/scaling-stackdriver-monitoring-metrics below:

Scale based on Monitoring metrics | Compute Engine Documentation

Autoscaling based on Cloud Monitoring metrics lets you adjust the capacity needed according to measurements from your app. When you autoscale a MIG based on a metric, the autoscaler creates VMs when the metric value increases and deletes VMs when the value decreases.

For example, you can define how many VMs you need per user count, latency, or the number of messages in a Pub/Sub subscription. You can use either the built-in metrics provided by the Monitoring service, or the custom metrics that you export from your application.

This document describes how to autoscale a managed instance group (MIG) based on Monitoring metrics.

You can also autoscale a MIG based on CPU utilization, load balancing serving capacity, or schedules.

Before you begin Limitations

Scaling based on Monitoring metrics is restricted by the limitations for all autoscalers as well as by the following limitations:

Configure autoscaling based on Monitoring metrics

You can use a Monitoring metric value for autoscaling in two different ways:

Autoscale to maintain a metric at a target value

When you want to maintain a metric at a target value, specify a utilization target. The autoscaler creates VMs when the metric value is above the target and deletes VMs when the metric value is below the target.

When your metric has multiple values, apply a filter to autoscale using an individual value from the metric. For more details about metric filters and other fields that you can use in your configuration, see Monitoring metrics concepts.

Permissions required for this task

To perform this task, you must have the following permissions:

Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. If you don't have a managed instance group, create one. Otherwise, click the name of a MIG from the list to open that instance group page.

  3. Click Edit.

  4. Click Group size & autoscaling to expand the section.
  5. If autoscaling configuration doesn't exist, click Configure autoscaling.

    By default, the autoscaling configuration adds a signal based on CPU utilization. If you don't require this signal, you can edit it to change the signal type.

  6. In the Autoscaling signals section, if a signal for a Monitoring metric exists, you can click to edit it, or click Add a signal to add one.
  7. Set the Signal type to Cloud Monitoring metric.

  8. Click Configure. In the Resource and metric pane that opens, do the following:

    1. Click Select a metric.
      1. Select the metric that you want to use for autoscaling. You can filter the metrics based on any keywords—for example, memory, bytes, disk.
      2. Click Apply. The pane displays a chart that shows the data from the selected metric.
    2. If you want to use specific data from the metric, add a filter based on labels as follows:

      1. In the Filters section, click Add a filter.
      2. Select a Label and enter a Value.
      3. Click Done. The chart refreshes to show you the filtered value of the metric.
      Note: The filter project_id=PROJECT_ID is added by default because you can use the metric values from the resources in the current project only. If you selected a metric that comes from each VM (gce_instance), then an additional filter instance_group=MIG_NAME is also added because you can autoscale based on the metric values from the VMs in the current MIG only.
    3. To view the aggregated value of metric that will be used to autoscale your MIG, toggle the Show aggregation in chart button. The chart refreshes to show the aggregated value.

    4. In the Metric target options for autoscaling section, select Utilization target.

    5. Provide the following:

      1. Utilization target: Specify the value that the autoscaler must maintain. This must be a positive number. For example, both 24.5 and 100 are acceptable values.
      2. Utilization target type: Select a target type that corresponds to the metric's kind of measurement. For accurate comparisons, if the utilization target is measured per seconds, then use Delta / second as the target type. Likewise, use Delta / min for a utilization target measured per minutes.
        • Gauge: The autoscaler calculates the average value of the data collected in the last couple of minutes and compares that to the utilization target.
        • Delta / min: The autoscaler calculates the average rate of growth per minute and compares that to the utilization target.
        • Delta / second: The autoscaler calculates the average rate of growth per second and compares that to the utilization target.
    6. When you've finished configuring the metric, click Select.

  9. Review the metric details and click Done.

  10. To complete the configuration, click Save.

gcloud

To configure autoscaling based on Monitoring metrics, use the set-autoscaling command.

Note: If autoscaling is already enabled for a MIG, the set-autoscaling command overwrites the existing autoscaler to the new specifications.

Use the following command to autoscale based on a Monitoring metric with a utilization target.

gcloud compute instance-groups managed set-autoscaling MIG_NAME \
  --max-num-replicas=MAX_INSTANCES \
  --min-num-replicas=MIN_INSTANCES \
  --update-stackdriver-metric=METRIC_URL \
  --stackdriver-metric-utilization-target=TARGET_VALUE \
  --stackdriver-metric-utilization-target-type=TARGET_TYPE

If your metric has multiple values and you want to use an individual value for autoscaling, then use the --stackdriver-metric-filter flag as given in the following command.

gcloud compute instance-groups managed set-autoscaling MIG_NAME \
  --max-num-replicas=MAX_INSTANCES \
  --min-num-replicas=MIN_INSTANCES \
  --update-stackdriver-metric=METRIC_URL \
  --stackdriver-metric-utilization-target=TARGET_VALUE \
  --stackdriver-metric-utilization-target-type=TARGET_TYPE \
  --stackdriver-metric-filter="METRIC_FILTER"

Replace the following:

To see a full list of available commands and flags for the gcloud CLI, see the gcloud reference.

REST Note: Although autoscaling is a feature of managed instance groups, it is a separate API resource. Keep that in mind when you construct API requests for autoscaling.

To configure autoscaling based on Monitoring metrics for a zonal MIG, use the autoscalers resource or, for a regional MIG, use the regionAutoscalers resource.

Make the following call to autoscale a zonal MIG based on a Monitoring metric with a utilization target.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/autoscalers
{
 "name": "AUTOSCALER_NAME",
 "target": "zones/ZONE/instanceGroupManagers/MIG_NAME",
 "autoscalingPolicy": {
  "maxNumReplicas": MAX_INSTANCES,
  "minNumReplicas": MIN_INSTANCES,
  "customMetricUtilizations": [
    {
      "metric": "METRIC_URL",
      "utilizationTarget": TARGET_VALUE,
      "utilizationTargetType": TARGET_TYPE
    }
  ],
 }
}

If your metric has multiple values and you want to use an individual value for autoscaling, then use the filter parameter as given in the following API call.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/autoscalers
{
 "name": "AUTOSCALER_NAME",
 "target": "zones/ZONE/instanceGroupManagers/MIG_NAME",
 "autoscalingPolicy": {
  "maxNumReplicas": MAX_INSTANCES,
  "minNumReplicas": MIN_INSTANCES,
  "customMetricUtilizations": [
    {
      "metric": "METRIC_URL",
      "utilizationTarget": TARGET_VALUE,
      "utilizationTargetType": TARGET_TYPE,
      "filter": "METRIC_FILTER"
    }
  ],
 }
}

Replace the following:

Autoscale based on work available for each VM in a MIG

When you want to autoscale based on the quantity of work that is available for each VM in a MIG, specify a single instance assignment. The value of the single instance assignment that you set indicates how much work you expect each VM to handle. The autoscaler divides the metric value by the single instance assignment value to calculate how many VMs are needed.

A metric value of 0 indicates that there is no work for your MIG to complete. If your MIG's minimum number of instances is set to 0 and your metric value drops to 0, then the MIG scales in to 0 until the metric value increases.

When your metric has multiple values, apply a filter to autoscale using an individual value from the metric. For more details about metric filters and other fields that you can use in your configuration, see Monitoring metrics concepts.

Permissions required for this task

To perform this task, you must have the following permissions:

Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. If you don't have a managed instance group, create one. Otherwise, click the name of a MIG from the list to open that instance group page.

  3. Click Edit.

  4. Click Group size & autoscaling to expand the section.
  5. If autoscaling configuration doesn't exist, click Configure autoscaling.

    By default, the autoscaling configuration adds a signal based on CPU utilization. If you don't require this signal, you can edit it to change the signal type.

  6. In the Autoscaling signals section, if a signal for a Monitoring metric exists, you can click to edit it, or click Add a signal to add one.
  7. Set the Signal type to Cloud Monitoring metric.

  8. Click Configure. In the Resource and metric pane that opens, do the following:

    1. Click Select a metric.
      1. Select the metric that you want to use for autoscaling. You can filter the metrics based on any keywords—for example, memory, bytes, disk.
      2. Click Apply. The pane displays a chart that shows the data from the selected metric.
    2. If you want to use specific data from the metric, add a filter based on labels as follows:

      1. In the Filters section, click Add a filter.
      2. Select a Label and enter a Value.
      3. Click Done. The chart refreshes to show you the filtered metric value.
      Note: The filter project_id=PROJECT_ID is added by default because you can use the metric values from the resources in the current project only.
    3. To view the aggregated value of metric that will be used to autoscale your MIG, toggle the Show aggregation in chart button. The chart refreshes to show the aggregated value.

    4. In the Metric target options for autoscaling section, select Single VM instance assignment.

    5. Provide a Single instance assignment value that represents the amount of work to assign to each VM in the MIG.

    6. When you've finished configuring the metric, click Select.

  9. Review the metric details and click Done.

  10. To complete the configuration, click Save.

gcloud

To configure autoscaling based on Monitoring metrics, use the set-autoscaling command.

Note: If autoscaling is already enabled for a MIG, the set-autoscaling command overwrites the existing autoscaler to the new specifications.

In the command, specify the --stackdriver-metric-single-instance-assignment flag to indicate the amount of work that you expect each VM in the group to handle.

The following command creates an autoscaler based on work assignment for each VM.

gcloud compute instance-groups managed set-autoscaling MIG_NAME \
    --max-num-replicas=MAX_INSTANCES \
    --min-num-replicas=MIN_INSTANCES \
    --update-stackdriver-metric=METRIC_URL \
    --stackdriver-metric-filter="METRIC_FILTER" \
    --stackdriver-metric-single-instance-assignment=INSTANCE_ASSIGNMENT

Replace the following:

REST Note: Although autoscaling is a feature of managed instance groups, autoscalers are a separate API resource. Keep that in mind when you construct API requests for autoscaling.

To configure autoscaling based on Monitoring metrics for a zonal MIG, use the autoscalers resource or, for a regional MIG, use the regionAutoscalers resource.

Use the singleInstanceAssignment parameter to specify the amount of work that you expect each VM to handle.

For example, make the following call to create an autoscaler that scales a zonal MIG based on the instance assignment.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/autoscalers

{
 "name": "AUTOSCALER_NAME",
 "target": "zones/ZONE/instanceGroupManagers/MIG_NAME",
 "autoscalingPolicy": {
  "maxNumReplicas": MAX_INSTANCES,
  "minNumReplicas": MIN_INSTANCES,
  "customMetricUtilizations": [
    {
      "metric": "METRIC_URL",
      "filter": "METRIC_FILTER",
      "singleInstanceAssignment": INSTANCE_ASSIGNMENT
    }
  ],
 }
}

Replace the following:

Examples for autoscaling based on metrics

This section provides some examples of metrics used for autoscaling. For a complete list of metrics, see Google Cloud metrics.

Autoscale based on a custom metric

There might be a situation when the metric providing a relevant signal does not represent a total amount of available work or another resource applicable to the group, but instead an average, a percentile, or some other statistical property. For this example, assume that you scale based on the group's average processing latency.

Assume the following setup:

You have determined that when the metric value is above some specific value, you need to add more VMs to the group to handle the load, while when it is below that value, you can free up some resources. You want the autoscaler to gradually add or remove VMs at a rate that is proportional to how much the metric is above or below the target. For this example, assume that you have determined your target value to be 250 delta/sec.

You can configure autoscaling for the group using a utilization target of 250, which represents the rate of change of the metric value that the autoscaler will attempt to maintain:

Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Click the name of your MIG from the list to open the instance group overview page.

  3. Click Edit.

  4. Click Group size & autoscaling to expand the section.
  5. If autoscaling configuration doesn't exist, click Configure autoscaling.

    By default, the autoscaling configuration adds a signal based on CPU utilization. If you don't require this signal, you can edit it to change the signal type.

  6. In the Autoscaling signals section, if a signal for a Monitoring metric exists, you can click to edit it, or click Add a signal to add one.
  7. Set the Signal type to Cloud Monitoring metric.

  8. Click Configure. The Resource and metric pane opens.

    1. Click Select a metric.
      1. Choose your metric from Global > Custom metrics.
      2. Click Apply.
    2. In the Filters section, do the following:
      1. Click Add a filter.
      2. In the Label drop-down, select group_name.
      3. In the Value field, provide our-instance-group.
      4. Click Done. The chart refreshes to show the filtered value from the metric.
    3. In the Metric target options for autoscaling section, do the following:
      1. Select Utilization target.
      2. Enter the utilization target value as 250.
      3. Set the utilization target type to Delta / sec.
    4. After you've configured the metric, click Select.
  9. Review the metric details and then click Done.

  10. When you've finished, click Save.

gcloud
gcloud compute instance-groups managed set-autoscaling our-instance-group \
  --zone=us-central1-a \
  --max-num-replicas=50 \
  --min-num-replicas=0 \
  --update-stackdriver-metric=custom.googleapis.com/example_average_latency \
  --stackdriver-metric-filter="metric.labels.group_name = \"our-instance-group\" AND resource.type = \"global\"" \
  --stackdriver-metric-utilization-target=250 \
  --stackdriver-metric-utilization-target-type=delta-per-second
REST
POST https://compute.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/autoscalers
{
"name": "our-instance-group-autoscaler",
"target": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instanceGroupManagers/our-instance-group",
"autoscalingPolicy": {
  "maxNumReplicas": 50,
  "minNumReplicas": 0,
  "customMetricUtilizations": [
    {
      "filter": "metric.labels.group_name=\"our-instance-group\" AND resource.type = \"global\"",
      "utilizationTargetType": "delta-per-second",
      "utilizationTarget": 250.0,
      "metric": "custom.googleapis.com/example_average_latency"
    }
  ]
}
}
Autoscale based on unacknowledged messages in Pub/Sub

To configure autoscaling based on unacknowledged messages in a Pub/Sub subscription, use the subscription/num_undelivered_messages metric provided by pubsub and filter by the subscription ID.

The subscription/num_undelivered_messages metric exports the total number of messages in the subscription, including messages that are being processed but that are not yet acknowledged. Using a metric that does not include the messages being processed is not recommended because such a metric can drop-down to 0 when there is still work being done, which prompts autoscaling to scale in and possibly interrupt the actual work.

If you don't have a subscription, you can create a pull, push, or BigQuery subscription before you configure autoscaling.

Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Click the name of your MIG from the list to open the instance group overview page.

  3. Click Edit.

  4. Click Group size & autoscaling to expand the section.
  5. If autoscaling configuration doesn't exist, click Configure autoscaling.

    By default, the autoscaling configuration adds a signal based on CPU utilization. If you don't require this signal, you can edit it to change the signal type.

  6. In the Autoscaling signals section, if a signal for a Monitoring metric exists, you can click to edit it, or click Add a signal to add one.
  7. Set the Signal type to Cloud Pub/Sub queue.

  8. Select a Topic. If you want a new topic, click Create a topic to create one.

  9. Select the Subscription based on which you want to autoscale your MIG. If you want a new subscription, click Create a subscription to create one.

  10. In the Number of messages to assign to each VM field, specify the number of unacknowledged messages that you expect each VM to handle.

  11. Click Done.

  12. When you've finished, click Save.

gcloud
gcloud compute instance-groups managed set-autoscaling MIG_NAME \
  --max-num-replicas=MAX_INSTANCES \
  --min-num-replicas=MIN_INSTANCES \
  --update-stackdriver-metric=pubsub.googleapis.com/subscription/num_undelivered_messages \
  --stackdriver-metric-filter="resource.type=\"pubsub_subscription\" AND resource.labels.subscription_id=\"SUBSCRIPTION_ID\"" \
  --stackdriver-metric-single-instance-assignment=NUMBER_OF_MESSAGES_TO_ASSIGN_TO_EACH_VM
REST

To configure autoscaling for a zonal MIG, use the autoscalers resource or, for a regional MIG, use the regionAutoscalers resource.

For example, make the following call to create an autoscaler for a zonal MIG.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/autoscalers
{
"name": "AUTOSCALER_NAME",
"target": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME",
"autoscalingPolicy": {
  "maxNumReplicas": MAX_INSTANCES,
  "minNumReplicas": MIN_INSTANCES,
  "customMetricUtilizations": [
    {
      "singleInstanceAssignment": NUMBER_OF_MESSAGES_TO_ASSIGN_TO_EACH_VM,
      "filter": "resource.type = \"pubsub_subscription\" AND resource.labels.subscription_id=\"SUBSCRIPTION_ID\"",
      "metric": "pubsub.googleapis.com/subscription/num_undelivered_messages"
    }
  ]
}
}
Autoscale based on incoming network traffic

To configure autoscaling based on the incoming network traffic to VMs in your MIG, use the instance/network/received_bytes_count metric provided by compute.

Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Click the name of your MIG from the list to open the instance group overview page.

  3. Click Edit.

  4. Click Group size & autoscaling to expand the section.
  5. If autoscaling configuration doesn't exist, click Configure autoscaling.

    By default, the autoscaling configuration adds a signal based on CPU utilization. If you don't require this signal, you can edit it to change the signal type.

  6. In the Autoscaling signals section, if a signal for a Monitoring metric exists, you can click to edit it, or click Add a signal to add one.
  7. Set the Signal type to Cloud Monitoring metric.

  8. Click Configure. The Resource and metric pane opens.

    1. Click Select a metric.
      1. Select VM Instance > Instance > Received bytes (compute.googleapis.com/instance/network/received_bytes_count).
      2. Click Apply.
    2. In the Metric target options for autoscaling section, do the following:
      1. Make sure that Utilization target is selected.
      2. Enter a utilization target value.
      3. Set a utilization target type.
    3. After you've configured the metric, click Select.
  9. Review the metric details and then click Done.

  10. When you've finished, click Save.

gcloud
gcloud compute instance-groups managed set-autoscaling MIG_NAME \
  --max-num-replicas=MAX_INSTANCES \
  --min-num-replicas=MIN_INSTANCES \
  --update-stackdriver-metric=compute.googleapis.com/instance/network/received_bytes_count \
  --stackdriver-metric-utilization-target=TARGET_VALUE \
  --stackdriver-metric-utilization-target-type=TARGET_TYPE
REST
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/autoscalers
{
"name": "AUTOSCALER_NAME",
"target": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME",
"autoscalingPolicy": {
  "maxNumReplicas": MAX_INSTANCES,
  "minNumReplicas": MIN_INSTANCES,
  "customMetricUtilizations": [
    {
      "utilizationTargetType": "TARGET_TYPE",
      "utilizationTarget": TARGET_VALUE,
      "metric": "compute.googleapis.com/instance/network/received_bytes_count"
    }
  ]
}
}
Autoscale based on memory usage

To configure autoscaling based on the percent of used memory, specify the percent_used metric provided by the memory Ops Agent metrics. You should filter the metric by state to use only the used memory state. If you don't specify the filter, then the autoscaler takes the sum of memory usage by all memory states labeled as buffered, cached, free, slab, and used.

Note: The memory/percent_used metric is an Ops Agent metric. You must install the Ops Agent before you configure autoscaling based on this metric. Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Click the name of your MIG from the list to open the instance group overview page.

  3. On the instance group overview page, click Edit.

  4. Click Group size & autoscaling to expand the section.
  5. If autoscaling configuration doesn't exist, click Configure autoscaling.

    By default, the autoscaling configuration adds a signal based on CPU utilization. If you don't require this signal, you can edit it to change the signal type.

  6. In the Autoscaling signals section, if a signal for a Monitoring metric exists, you can click to edit it, or click Add a signal to add one.
  7. Set the Signal type to Cloud Monitoring metric.

  8. Click Configure. The Resource and metric pane opens.

    1. Click Select a metric.
      1. Select VM Instance > Memory > Memory utilization (compute.googleapis.com/instance/memory/percent_used).
      2. Click Apply.
    2. In the Filters section, do the following:
      1. Click Add a filter.
      2. In the Label drop-down, choose the state metric label.
      3. In the Value field, type used.
      4. Click Done.
    3. In the Metric target options for autoscaling section, do the following:
      1. Make sure that Utilization target is selected.
      2. Enter a utilization target value.
      3. Set the utilization target type to Gauge.
    4. After you've configured the metric, click Select.
  9. Review the metric details and then click Done.

  10. When you've finished, click Save.

gcloud
gcloud compute instance-groups managed set-autoscaling MIG_NAME \
  --max-num-replicas=MAX_INSTANCES \
  --min-num-replicas=MIN_INSTANCES \
  --update-stackdriver-metric=agent.googleapis.com/memory/percent_used \
  --stackdriver-metric-filter="metric.labels.state = \"used\""
  --stackdriver-metric-utilization-target-type=gauge \
  --stackdriver-metric-utilization-target=TARGET_VALUE  \
REST
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/autoscalers
{
"name": "AUTOSCALER_NAME",
"target": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME",
"autoscalingPolicy": {
  "maxNumReplicas": MAX_INSTANCES,
  "minNumReplicas": MIN_INSTANCES,
  "customMetricUtilizations": [
  {
    "filter": "metric.labels.state=\"used\"",
    "utilizationTargetType": "GAUGE",
    "utilizationTarget": TARGET_VALUE,
    "metric": "agent.googleapis.com/memory/percent_used"
  }
  ]
}
}
Autoscale based on disk I/O

To configure autoscaling based on the total count of disk I/O operations, use the operation_count metric provided by the disk Ops Agent metrics. If you want to scale based on read or write operations, filter the metric using the direction label. Similarly, to scale based on disk operations in a particular device, use the device label in the metric filter.

Note: The disk/operation_count metric is an Ops Agent metric. You must install the Ops Agent before you configure autoscaling based on this metric. Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Click the name of your MIG from the list to open the instance group overview page.

  3. On the instance group overview page, click Edit.

  4. Click Group size & autoscaling to expand the section.
  5. If autoscaling configuration doesn't exist, click Configure autoscaling.

    By default, the autoscaling configuration adds a signal based on CPU utilization. If you don't require this signal, you can edit it to change the signal type.

  6. In the Autoscaling signals section, if a signal for a Monitoring metric exists, you can click to edit it, or click Add a signal to add one.
  7. Set the Signal type to Cloud Monitoring metric.

  8. Click Configure. The Resource and metric pane opens.

    1. Click Select a metric.
      1. Select VM instance > Disk > Disk operations (agent.googleapis.com/disk/operation_count).
      2. Click Apply.
    2. In the Metric target options for autoscaling section, do the following:
      1. Make sure that Utilization target is selected.
      2. Enter a utilization target value.
      3. Set a utilization target type.
    3. After you've configured the metric, click Select.
  9. Review the metric details and then click Done.

  10. When you've finished, click Save.

gcloud
gcloud compute instance-groups managed set-autoscaling MIG_NAME \
  --max-num-replicas=MAX_INSTANCES  \
  --min-num-replicas=MIN_INSTANCES  \
  --update-stackdriver-metric=agent.googleapis.com/disk/operation_count \
  --stackdriver-metric-utilization-target=TARGET_VALUE  \
  --stackdriver-metric-utilization-target-type=TARGET_TYPE
REST
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/autoscalers
{
"name": "AUTOSCALER_NAME",
"target": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME",
"autoscalingPolicy": {
  "maxNumReplicas": MAX_INSTANCES,
  "minNumReplicas": MIN_INSTANCES,
  "customMetricUtilizations": [
  {
    "utilizationTargetType": "TARGET_TYPE",
    "utilizationTarget": TARGET_VALUE,
    "metric": "agent.googleapis.com/disk/operation_count"
  }
  ]
}
}
Autoscale based on size of another MIG

You can autoscale a MIG based on the size of another MIG within the same project. For example, you can have multi-tier application with a frontend MIG that autoscales based on a load balancer and a backend MIG that autoscales proportionally to the frontend. Use a single instance assignment to define how many backend VMs are needed for every frontend VM. If you need 1 backend VM for every 4 frontend VMs, then set the single instance assignment to 4 in the backend MIG.

To autoscale a MIG (MIG_1) based on the size of another MIG (MIG_2), use the instance_group/size metric provided by compute.

Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Click the name of your MIG from the list to open the instance group overview page.

  3. On the instance group overview page, click Edit.

  4. Click Group size & autoscaling to expand the section.
  5. If autoscaling configuration doesn't exist, click Configure autoscaling.

    By default, the autoscaling configuration adds a signal based on CPU utilization. If you don't require this signal, you can edit it to change the signal type.

  6. In the Autoscaling signals section, if a signal for a Monitoring metric exists, you can click to edit it, or click Add a signal to add one.
  7. Set the Signal type to Cloud Monitoring metric.

  8. Click Configure. The Resource and metric pane opens.

    1. Click Select a metric
      1. Select Instance Group > Instance_group > Instance group size (compute.googleapis.com/instance_group/size).
      2. Click Apply.
    2. In the Filters section, do the following:
      1. Click Add a filter.
      2. In the Label drop-down, choose the instance_group_name resource label.
      3. In the Value field, type the name of the MIG (MIG_2) based on which you want to autoscale your MIG.
      4. Click Done.
    3. In the Metric target options for autoscaling section, do the following:
      1. Select Single VM instance assignment.
      2. In the Single VM instance assignment field, enter 4, if you want to keep 1 VM in your current MIG (MIG_1) for every 4 VMs in MIG_2.
    4. After you've configured the metric, click Select.
  9. Review the metric details and then click Done.

  10. When you've finished, click Save.

gcloud
gcloud compute instance-groups managed set-autoscaling MIG_1 \
  --max-num-replicas=MAX_INSTANCES \
  --min-num-replicas=MIN_INSTANCES \
  --update-stackdriver-metric=compute.googleapis.com/instance_group/size \
  --stackdriver-metric-filter="resource.type = \"instance_group\" AND resource.labels.location = \"ZONE|REGION\" AND resource.labels.instance_group_name = \"MIG_2\"" \
  --stackdriver-metric-single-instance-assignment=4
REST
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/autoscalers
{
"name": "AUTOSCALER_NAME",
"target": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_1",
"autoscalingPolicy": {
  "maxNumReplicas": MAX_INSTANCES,
  "minNumReplicas": MIN_INSTANCES,
  "customMetricUtilizations": [
  {
    "singleInstanceAssignment": 4,
    "filter": "resource.type = \"instance_group\" and resource.labels.location = \"ZONE|REGION\" AND resource.labels.instance_group_name = \"MIG_2\"",
    "metric": "compute.googleapis.com/instance_group/size"
  }
  ]
}
}
Monitoring metrics concepts

This section provides a brief description of the Monitoring metrics concepts that you need to know while configuring autoscaling based on Monitoring metrics.

Metric filtering requirements

When you use a metric that has multiple values (categorized using labels), you can apply a filter to autoscale based on specific values from the metric. If the filter returns multiple values, then the values are added together. For best results, create a filter that is specific enough to return a single value.

Autoscaler filtering for metrics is compatible with the Monitoring filter syntax. The filter must meet the following requirements:

For a full reference of metric labels and monitored resource labels that you can filter on, see metrics list and monitored resources list.

Custom metric requirements

To use custom metrics, you must first create a custom metric that is associated with one of the monitored-resource types.

A custom metric used for autoscaling must have the following properties:

For information about creating a custom metric, see Using custom metrics.

What's next

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4