Loading...
Loading...
Diagnoses and resolves Google Compute Engine Managed Instance Group (MIG) autoscaling failures, scale-out blocks, and scale-in stalls. Use ONLY when a Compute Engine MIG fails to add or remove VM instances during load changes, hits quota or zonal stockout limits, reaches maxNumReplicas (CAPPED_AT_MAX_NUM_REPLICAS), conflicts with HTTP(S) load balancer maxRate settings, fails to scale in to zero instances, or fails to read Cloud Monitoring scaling metrics. DO NOT read or use for Google Kubernetes Engine (GKE) Horizontal Pod Autoscaler (HPA), GKE Cluster Autoscaler, standalone single-VM creation, or single-VM host maintenance reboots.
npx skill4agent add google/skills compute-mig-autoscaling-troubleshootingmaxNumReplicasminNumReplicas: 0scaleInControlmode--cool-down-periodUTILIZATIONRATEMCP Tools:,get_instance_group_manager_basic_info,list_instance_group_managers,list_managed_instances,list_instance_templates,get_instance_template_basic_infoget_instance_template_properties
gcloudgcloudgcloudgcloud --versionget_instance_group_manager_basic_infolist_instance_group_managerslist_managed_instanceslist_instance_templatesget_instance_template_basic_infoget_instance_template_propertiesroles/mcp.toolUserget_instance_group_manager_basic_infozoneInstanceGroupManagerBasicInfonameidinstance_templatetarget_sizestatusautoscaler.statusautoscaler.statusDetailsautoscaler.recommendedSizeautoscaler.autoscalingPolicylist-errorsupdate-autoscalingset-autoscalingautoscaler.*list-errorsgcloudgcloud auth logingcloud auth application-default loginGOOGLE_APPLICATION_CREDENTIALSgcloud config set project {project_id}
gcloud config set compute/region {region}
gcloud config set compute/zone {zone}
gcloud services enable compute.googleapis.com logging.googleapis.com monitoring.googleapis.comus-central1roles/compute.viewerroles/logging.viewerroles/logging.viewAccessorroles/bigquery.jobUserroles/bigquery.dataViewerroles/monitoring.viewerroles/compute.instanceAdmin.v1roles/iam.serviceAccountUserroles/compute.loadBalancerAdminroles/resourcemanager.projectIamAdminroles/mcp.toolUserservice-{project_number}@compute-system.iam.gserviceaccount.comroles/compute.serviceAgent{project_number}@cloudservices.gserviceaccount.comroles/compute.instanceGroupManagerServiceAgentstatus.isStableautoscaler.statusautoscaler.statusDetailsautoscaler.recommendedSizeautoscaler.autoscalingPolicytargetSizegcloud compute instance-groups managed describe--region={region}--zone={zone}gcloud compute instance-groups managed list-errors# 1. Inspect Autoscaler status, statusDetails, recommendedSize, and policy (Regional MIG):
gcloud compute instance-groups managed describe {mig_name} --project={project_id} --region={region} \
--format="yaml(name, targetSize, status.isStable, autoscaler.status, autoscaler.statusDetails, autoscaler.recommendedSize, autoscaler.autoscalingPolicy)"
# (For a Zonal MIG, replace --region={region} with --zone={zone}:)
gcloud compute instance-groups managed describe {mig_name} --project={project_id} --zone={zone} \
--format="yaml(name, targetSize, status.isStable, autoscaler.status, autoscaler.statusDetails, autoscaler.recommendedSize, autoscaler.autoscalingPolicy)"
# 2. Inspect per-instance actuation errors logged by the MIG controller:
gcloud compute instance-groups managed list-errors {mig_name} --project={project_id} --region={region} --limit=25autoscaler.statusDetails[]typemessageautoscaler.statusDetails[]AutoscalertypemessageCAPPED_AT_MAX_NUM_REPLICAS"The number of instances has reached themaxNumReplicas. The autoscaler cannot add more instances."autoscalingPolicy.maxNumReplicasNOT_ENOUGH_QUOTA_AVAILABLEQUOTA_EXCEEDED"Quota for someresources is exceeded. Increase the quota or delete resources to free upmore quota."QUOTA_EXCEEDEDlist-errorsCPUSIN_USE_ADDRESSESSSD_TOTAL_GBZONE_RESOURCE_STOCKOUTREGION_RESOURCE_STOCKOUTZONE_RESOURCE_POOL_EXHAUSTEDZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILSlist-errorsMISSING_CUSTOM_METRIC_DATA_POINTSCUSTOM_METRIC_INVALIDCUSTOM_METRIC_DATA_POINTS_TOO_SPARSE"The monitoring metric that wasspecified does not exist or does not have the required labels. Check themetric."service-{project_number}@compute-system.iam.gserviceaccount.comroles/compute.serviceAgentUNSUPPORTED_MAX_RATE_LOAD_BALANCING_CONFIGURATION"Autoscaling doesnot work with an HTTP/S load balancer configured for maxRate."BACKEND_SERVICE_DOES_NOT_EXISTMORE_THAN_ONE_BACKEND_SERVICEMISSING_LOAD_BALANCING_DATA_POINTSRATEmaxRateUTILIZATIONALL_INSTANCES_UNHEALTHY"All instances in the instance group areunhealthy (not in RUNNING state). If this is an error, check theinstances."RUNNINGMODE_ONLY_SCALE_OUTMODE_ONLY_UPMODE_OFFMIN_EQUALS_MAXSCALING_SCHEDULE_AFFECTING_MIN_REPLICASWARNING_NO_INSTANCESautoscalergce_autoscalergce_instance_group_managergce_instance_groupgce_instance--freshness=7dgcloud logging read1dsystem_eventprotoPayload.metadatacompute.autoscalers.resize@type:"type.googleapis.com/autoscaler.AutoscalerSizeChangeExplanation"protoPayload.metadata.oldSizeprotoPayload.metadata.newSizeprotoPayload.metadata.autoscalingModeprotoPayload.metadata.autoscalingReason.summaryprotoPayload.metadata.autoscalingReason.scalingSignalnamecalculatedSizecalculationDetails.servingSizecalculationDetails.signalTargetcalculationDetails.signalValueprotoPayload.metadata.autoscalingReason.scalingLimitnamelimitSizelimitPolicyMAX_REPLICAS_LIMITSCALE_IN_LIMITcompute.autoscalers.changeStatus@type: "type.googleapis.com/autoscaler.AutoscalerStatusChange"protoPayload.metadata.oldStatus.detailsprotoPayload.metadata.newStatus.details"OK""Quota for some resources is exceeded. Increase the quota ordelete resources to free up more quota."statusDetails[].typeAutoscalerchangeStatus# 1. Query failed MIG resize, autoscaler, and VM insertion Admin Activity logs (projecting errors[0].code):
gcloud logging read '(resource.type="autoscaler" OR resource.type="gce_autoscaler" OR resource.type="gce_instance_group_manager" OR resource.type="gce_instance_group" OR resource.type="gce_instance") AND severity>=ERROR AND protoPayload.methodName=~"compute\.(regionInstanceGroupManagers|instanceGroupManagers|instances|instanceGroups|autoscalers|regionAutoscalers)\.(resize|insert|addInstances|removeInstances|changeStatus|update|patch)" AND protoPayload.resourceName:"{mig_name}"' \
--project={project_id} --freshness=7d --limit=25 \
--format="table(timestamp, resource.type, protoPayload.methodName, protoPayload.status.message, protoPayload.response.error.errors[0].code, protoPayload.response.error.errors[0].message)"
# 2. Query autoscaler system_event resize decisions and status change explanations:
gcloud logging read '(resource.type="autoscaler" OR resource.type="gce_autoscaler") AND log_id("cloudaudit.googleapis.com/system_event") AND protoPayload.methodName=~"compute\.autoscalers\.(resize|changeStatus)"' \
--project={project_id} --freshness=7d --limit=25 \
--format="yaml(timestamp, protoPayload.methodName, protoPayload.metadata.oldSize, protoPayload.metadata.newSize, protoPayload.metadata.autoscalingReason, protoPayload.metadata.oldStatus.details, protoPayload.metadata.newStatus.details)"QUOTA_EXCEEDEDZONE_RESOURCE_POOL_EXHAUSTEDQUOTA_EXCEEDEDQuota 'CPUS' exceeded. Limit: 24.0 in region us-central1ZONE_RESOURCE_POOL_EXHAUSTEDZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILSANYroles/monitoring.viewerroles/compute.viewercompute.googleapis.com/instance_group/sizeresource.type="instance_group"resource.labels.instance_group_name="{mig_name}"autoscaler.googleapis.com/recommended_sizeresource.type="autoscaler"resource.labels.instance_group_manager_name="{mig_name}"autoscaler.googleapis.com/recommended_size >compute.googleapis.com/instance_group/sizemaxNumReplicasCAPPED_AT_MAX_NUM_REPLICASQUOTA_EXCEEDEDNOT_ENOUGH_QUOTA_AVAILABLEZONE_RESOURCE_POOL_EXHAUSTEDZONE_RESOURCE_STOCKOUTautoscaler.googleapis.com/recommended_size <compute.googleapis.com/instance_group/sizestabilizationPeriodSec600scaleInControlmaxScaledInReplicasmaxScaledInReplicas.fixedmaxScaledInReplicas.percentmaxScaledInReplicas.calculatedtimeWindowSecmodeONLY_SCALE_OUT--mode=only-scale-outactivityseverity_number >= 500ERROR_Default._AllLogssystem_event_Required._AllLogs_Defaultgcloud logging buckets update _Default --project={project_id} --location=global --enable-analytics_AllLogsresource.labelsJSONJSON_VALUE(...)'gce_instance''autoscaler'resource.type IN (...)instances.insertautoscalers.*instanceGroupManagers.resizeSELECT
TIMESTAMP_TRUNC(timestamp, HOUR) AS hour_bucket,
resource.type AS resource_type,
COALESCE(JSON_VALUE(resource.labels.location), JSON_VALUE(resource.labels.zone)) AS location,
REGEXP_EXTRACT(proto_payload.audit_log.resource_name, r'[^/]+$') AS target_resource,
proto_payload.audit_log.method_name AS method_name,
proto_payload.audit_log.status.message AS status_message,
COUNT(*) AS error_count
FROM `{project_id}.global._Default._AllLogs`
WHERE
timestamp >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
AND resource.type IN ('autoscaler', 'gce_autoscaler', 'gce_instance_group_manager', 'gce_instance_group', 'gce_instance')
AND severity_number >= 500
AND REGEXP_CONTAINS(
proto_payload.audit_log.method_name,
r'compute\.(regionInstanceGroupManagers|instanceGroupManagers|instanceGroups|autoscalers|regionAutoscalers|instances)\.(resize|addInstances|removeInstances|insert|update|patch|changeStatus)$'
)
GROUP BY hour_bucket, resource_type, location, target_resource, method_name, status_message
ORDER BY hour_bucket DESC, error_count DESC;QUOTA_EXCEEDEDNOT_ENOUGH_QUOTA_AVAILABLEQUOTA_EXCEEDEDCPUSIN_USE_ADDRESSESSSD_TOTAL_GBcompute.googleapis.comgcloud config set project {project_id}
gcloud services enable compute.googleapis.comgcloud compute regions describe {region} --project={project_id} \
--format="table(quotas:format='table(metric,limit,usage)')"IAM & Admin > Quotase2n2n2dc3CAPPED_AT_MAX_NUM_REPLICASmaxRate--cool-down-periodCAPPED_AT_MAX_NUM_REPLICAS--max-num-replicasupdate-autoscaling--region={region}gcloud compute instance-groups managed update-autoscaling {mig_name} \
--project={project_id} --zone={zone} --max-num-replicas={new_max_replicas}RATEUTILIZATIONUNSUPPORTED_MAX_RATE_LOAD_BALANCING_CONFIGURATIONRATEUTILIZATION--instance-group-zone={zone}--instance-group-region={region}--global--region={backend_service_region}# Zonal MIG attached to a global Backend Service:
gcloud compute backend-services update-backend {backend_service} --project={project_id} --global \
--instance-group={mig_name} --instance-group-zone={zone} --balancing-mode=UTILIZATION --max-utilization=0.8
# Regional MIG attached to a global Backend Service:
gcloud compute backend-services update-backend {backend_service} --project={project_id} --global \
--instance-group={mig_name} --instance-group-region={region} --balancing-mode=UTILIZATION --max-utilization=0.8gcloud compute instance-groups managed list-errors {mig_name} --project={project_id} --zone={zone}gcloud compute instance-templates describe {template_name} --project={project_id}--cool-down-period--stabilization-period--cool-down-period60update-autoscalingset-autoscalingset-autoscalingautoscalingPolicydescribe--max-num-replicas--target-cpu-utilizationgcloud compute instance-groups managed set-autoscaling {mig_name} --project={project_id} --zone={zone} \
--min-num-replicas={min_replicas} --max-num-replicas={max_replicas} \
--target-cpu-utilization={target_cpu} --cool-down-period=120600--stabilization-periodupdate-autoscalinggcloud compute instance-groups managed update-autoscaling {mig_name} \
--project={project_id} --zone={zone} --stabilization-period=600scaleInControlONLY_SCALE_OUTminNumReplicas: 0autoscaler.googleapis.com/recommended_sizecompute.googleapis.com/instance_group/size0autoscaler.autoscalingPolicy.modescaleInControlminNumReplicasgcloud compute instance-groups managed describe {mig_name} --project={project_id} --zone={zone} \
--format="yaml(autoscaler.autoscalingPolicy.mode, autoscaler.autoscalingPolicy.minNumReplicas, autoscaler.autoscalingPolicy.scaleInControl, autoscaler.autoscalingPolicy.coolDownPeriodSec)"scaleInControltimeWindowSecmaxScaledInReplicasmaxScaledInReplicas.fixedmaxScaledInReplicas.percentmaxScaledInReplicas.calculateddescribeONONLY_SCALE_OUTOFFgcloud--mode--mode=on--mode=only-scale-out--mode=offminNumReplicas: 0minNumReplicas: 000000scalingSchedules--stackdriver-metric-single-instance-assignmentsingleInstanceAssignmentmodescaleInControl# Enable full scaling (--mode=on) and relax scale-in throttling:
gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \
--mode=on --scale-in-control=max-scaled-in-replicas-percent=50,time-window=600
# Or clear scale-in controls completely for immediate scale-down after stabilization:
gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \
--mode=on --clear-scale-in-controlscaleInControlgcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \
--mode=on --scale-in-control=max-scaled-in-replicas-percent=10,time-window=600{project_number}# Step 1: Retrieve {project_number} for {project_id}:
gcloud projects describe {project_id} --format="value(projectNumber)"
# Step 2a: Restore Compute Engine Service Agent (reads Cloud Monitoring scaling metrics):
gcloud projects add-iam-policy-binding {project_id} \
--member="serviceAccount:service-{project_number}@compute-system.iam.gserviceaccount.com" \
--role="roles/compute.serviceAgent"
# Step 2b: Restore Google APIs Service Agent (creates and deletes MIG member VMs):
gcloud projects add-iam-policy-binding {project_id} \
--member="serviceAccount:{project_number}@cloudservices.gserviceaccount.com" \
--role="roles/compute.instanceGroupManagerServiceAgent"gce_instanceinstance_idzoneinstance_namegce_instanceINT64DOUBLEGAUGEDELTACUMULATIVEupdate-autoscaling--cpu-utilization-predictive-methodset-autoscaling# On a MIG that already scales on CPU utilization:
gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \
--cpu-utilization-predictive-method=optimize-availability
# Or configure CPU target + Predictive Autoscaling together (replaces policy):
gcloud compute instance-groups managed set-autoscaling {mig_name} --project={project_id} --zone={zone} \
--min-num-replicas={min_replicas} --max-num-replicas={max_replicas} \
--target-cpu-utilization=0.6 --cpu-utilization-predictive-method=optimize-availabilitygcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \
--mode=on --scale-in-control=max-scaled-in-replicas-percent=10,time-window=600--quietgcloud compute instance-groups managed delete {mig_name} --project={project_id} --zone={zone}
gcloud compute instance-templates delete {template_name} --project={project_id}