啟用自動調度資源時,自動配置器會根據您指定的選項進行資源調度決策。Cloud Logging 會記錄每個調度決策。您可以在記錄探索器中閱讀這些記錄,進一步瞭解自動調度器的資源調度決策。
透過記錄檔探索工具,您可以查看與以下內容相關的事件:
- 自動調度器建議,可調整代管執行個體群組 (MIG) 的大小。如果自動配置器為 MIG 計算出新的建議大小,自動配置器記錄中便會描述建議大小的變更。請參閱「調整記錄項目大小」。
- 自動配置器狀態的變更。舉例來說,假設自動配置器原本能正常運作,但後來遇到問題,自動配置器記錄中便會描述此狀態變更。請參閱狀態變更記錄項目。
事前準備
- 閱讀自動調度資源說明文件。
- 擁有一個您想查看記錄的使用中自動配置器。
- 檢閱記錄檔探索工具的使用方式。
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Trusted Cloud by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
- Set a default region and zone.
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
詳情請參閱 Trusted Cloud 驗證說明文件中的「Authenticate for using REST」。
查看自動配置器記錄
如要查看自動調整規模記錄,請使用 Trusted Cloud 控制台、gcloud CLI 或 REST。
主控台
如果已啟用自動調度資源功能,您可以在Trusted Cloud console中查看自動調度資源記錄。
- 前往「Logs Explorer」(記錄檔探索工具) 頁面。
- 將「資源」下拉式選單往下拉,然後選取「自動調度器」。
您也可以從 MIG 前往「記錄檔探索工具」頁面,方法如下:
前往 Trusted Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
按一下要查看記錄的 MIG 名稱。
按一下「監控」分頁標籤。
在「監控」分頁中,「記錄」面板位於頁面底部。按一下這個面板尾端的圖示,即可開啟面板。
如要開啟「記錄檔探索工具」頁面,請按一下這個面板中的「在記錄檔探索工具中查看」圖示。記錄檔探索工具會開啟,並預設查詢擷取 MIG 的所有自動調度器記錄。
gcloud
如要查詢所有與自動調度資源有關的記錄,請使用
logging read
指令。例如:gcloud logging read "resource.type=autoscaler" --limit 10 \ --format json
如要查看特定 MIG 的自動調度器記錄,請指定
instance_group_manager_name
,如下所示:gcloud logging read "resource.type=autoscaler AND \ resource.labels.instance_group_manager_name=example-igm" \ --limit 10 --format json
如要查看與自動配置器調整大小操作相關的記錄項目,請指定
compute.autoscalers.resize
方法名稱:gcloud logging read "resource.type=autoscaler AND \ resource.labels.instance_group_manager_name=example-igm AND \ protoPayload.methodName=compute.autoscalers.resize" \ --limit 10 --format json
如要查看與自動配置器狀態變更相關的記錄項目,請指定
compute.autoscalers.changeStatus
方法名稱:gcloud logging read "resource.type=autoscaler AND \ resource.labels.instance_group_manager_name=example-igm AND \ protoPayload.methodName=compute.autoscalers.changeStatus" \ --limit 10 --format json
REST
向 Logging V2 API 發出要求。要求主體必須包含搜尋記錄時要使用的
filter
參數,以及您想要查看記錄的project
。舉例來說,如要發出要求,取得特定 MIG 的大小調整動作清單:POST https://logging.googleapis.com/v2/entries:list { "filter": "resource.type=autoscaler AND resource.labels.instance_group_manager_name=example-igm AND protoPayload.methodName=compute.autoscalers.resize", "pageSize": 10, "resourceNames": [ "projects/example-project" ] }
如要發出要求,取得特定 MIG 的狀態變更清單:
POST https://logging.googleapis.com/v2/entries:list { "filter": "resource.type=autoscaler AND resource.labels.instance_group_manager_name=example-igm AND protoPayload.methodName=compute.autoscalers.changeStatus", "pageSize": 10, "resourceNames": [ "projects/example-project" ] }
調整記錄項目大小
自動調整器計算 MIG 的建議大小時,Compute Engine 會建立記錄項目,擷取新舊建議大小。如果是可用區 MIG,記錄項目也會擷取建議大小變更的原因。
以下是區域 MIG 的記錄項目範例。在這個範例中,自動調度器根據預測自動調度資源,計算出
3
個 VM,以達到35%
的 CPU 使用率目標。不過,自動調度資源政策中設定的執行個體數量上限只有2
。因此,自動配置器會將建議大小限制為2
。{ insertId: "1l68z7sg4jw7kzo" logName: "projects/example-project/logs/cloudaudit.googleapis.com%2Fsystem_event" protoPayload: { @type: "type.googleapis.com/google.cloud.audit.AuditLog" metadata: { @type: "type.googleapis.com/autoscaler.AutoscalerSizeChangeExplanation" autoscalingMode: "ON" autoscalingReason: { scalingLimit: { limitPolicy: { maxNumReplicas: 2 } limitSize: 2 name: "MAX_INSTANCES" } scalingSignal: { calculatedSize: 3 calculationDetails: { servingSize: 1 signalTarget: 0.35 signalValue: 1.03533 } name: "PREDICTED_CPU_UTILIZATION" signalPolicy: { coolDownPeriodSec: 15 cpuUtilization: { predictiveMethod: "OPTIMIZE_AVAILABILITY" utilizationTarget: 0.35 } } } summary: "The autoscaler's recommended size changed from 1 to 2 because the autoscaler predicted that in 15 seconds the average CPU utilization across 1 serving instance will be 103.533%, which is above the utilization target of 35%. The calculated size was 3 to achieve the target CPU utilization but the size was limited by the maximum number of instances set in the autoscaling policy." } newSize: 2 oldSize: 1 } methodName: "compute.autoscalers.resize" resourceName: "projects/example-project/zones/us-east1-d/autoscalers/example-autoscaler" serviceName: "compute.googleapis.com" } receiveTimestamp: "2022-06-13T22:34:43.045973046Z" resource: { labels: { autoscaler_id: "1234567890123456789" autoscaler_name: "example-autoscaler" instance_group_manager_id: "1357908642148074125" instance_group_manager_name: "example-igm" location: "us-east1-d" project_id: "example-project" } type: "autoscaler" } severity: "INFO" timestamp: "2022-06-13T22:34:42.810216614Z" }
下表說明記錄項目的欄位:
屬性 值 autoscalingMode
記錄項目記錄時的自動調度模式。無論模式為何,自動配置器都會計算建議大小,以記錄中的 newSize
表示。自動調度器會根據自動調度模式,以以下方式調整 MIG 大小:ON
:自動調度器會將 MIG 大小調整為newSize
。OFF
:自動調度器不會調整 MIG 大小。ONLY_SCALE_OUT
:只有在newSize
大於 MIG 的目標大小時,自動配置器才會調整 MIG 大小。
autoscalingReason
自動調度資源的原因詳細資料。這個欄位只會顯示區域 MIG。 autoscalingReason.scalingLimit
詳細說明自動調度資源功能如何限制 calculatedSize
,這是自動調度器根據自動調度資源信號計算出的大小。可能限制calculatedSize
的自動調度資源功能包括執行個體數量上限或下限、縮減控制項,或穩定期。如果calculatedSize
沒有限制,記錄中就不會顯示scalingLimit
欄位。autoscalingReason.scalingLimit.limitPolicy
自動調度資源功能的設定,限制了 calculatedSize
。如果穩定性限制了calculatedSize
,系統就不會設定limitPolicy
欄位,因為穩定性是自動調度資源的預設功能。autoscalingReason.scalingLimit.limitSize
自動調度資源功能限制的 VM 數量 calculatedSize
。autoscalingReason.scalingLimit.name
限制 calculatedSize
的自動調度功能名稱。autoscalingReason.scalingSignal
用於計算 MIG 應有的 VM 數量的自動調度資源信號詳細資料。如果自動調度資源政策有多項信號,自動配置器會考量需要最多 VM 的信號。 autoscalingReason.scalingSignal.calculatedSize
MIG 應根據自動調度資源信號擁有的 VM 數量。如果適用 scalingLimit
,自動調度器會將calculatedSize
限制為scalingLimit.limitSize
。autoscalingReason.scalingSignal.calculationDetails
用來判斷 calculatedSize
的詳細資料。servingSize
:MIG 中的 VM 數量,不包括仍在初始化期間的 VM。signalTarget
:自動配置器為 CPU 使用率 (即時)、預測 CPU 使用率、負載平衡使用率或設定使用率目標的指標維持的目標值。singleInstanceAssignment
:如果資源調度是根據代表待完成工作總量的指標值,則singleInstanceAssignment
是每個 VM 可處理的工作量。signalValue
:自動調度訊號的值。如果設定signalTarget
,自動調度器會比較signalValue
與signalTarget
,計算所需的 VM 數量,並以calculatedSize
表示。
autoscalingReason.scalingSignal.name
自動調度器計算 VM 數量時所依據的自動調度信號名稱,以記錄中的 calculatedSize
表示。autoscalingReason.scalingSignal.signalPolicy
自動調度器據以判斷 calculatedSize
的自動調度資源信號設定。autoscalingReason.summary
說明自動調度資源的原因。 newSize
目前建議的 MIG 大小。自動調度器會根據 autoscalingMode
,將 MIG 大小調整為newSize
,如下所示:ON
:自動調度器會將 MIG 大小調整為newSize
。OFF
:自動調度器不會調整 MIG 大小。ONLY_SCALE_OUT
:只有在newSize
大於 MIG 的目標大小時,自動配置器才會調整 MIG 大小。
oldSize
MIG 先前建議的大小。 如要瞭解記錄項目的其他欄位,請參閱稽核記錄項目的格式。
狀態變更記錄項目
自動調整器狀態變更時,Compute Engine 會建立記錄項目,擷取新舊狀態訊息。您可以使用這些狀態訊息來找出自動配置器未按預期方式運作的原因,或針對您注意到的先前問題進行除錯。如需部分常見狀態訊息,請參閱「常見的傳回狀態訊息」。
protoPayload
中的下列欄位會說明舊狀態和新狀態:metadata.newStatus.details
:自動調度程式的新狀態。metadata.oldStatus.details
:自動配置器的先前狀態。
以下是記錄項目的範例,說明狀態變更。在本例中,您可能會注意到新的狀態訊息,指出負載平衡設定有問題。
{ insertId: "ivho6kg4icqfio" logName: "projects/example-project/logs/cloudaudit.googleapis.com%2Fsystem_event" protoPayload: { metadata: { @type: "type.googleapis.com/autoscaler.AutoscalerStatusChange" newStatus: { details: "The autoscaler is configured to scale based on a load balancing signal but the instance group has not received any utilization data from the load balancer or the utilization is constantly 0. Check that the load balancing configuration is working" } oldStatus: { details: "OK" }, methodName: "compute.autoscalers.changeStatus" resourceName: "projects/example-project/zones/us-east1-b/autoscalers/example-autoscaler" serviceName: "compute.googleapis.com" } receiveTimestamp: "2022-06-08T03:54:12.332329320Z" resource: { labels: { autoscaler_id: "1234567890123456789" autoscaler_name: "example-autoscaler" instance_group_manager_id: "1357908642148074125" instance_group_manager_name: "example-igm" location: "us-east1-b" project_id: "example-project" } type: "autoscaler" } severity: "INFO" timestamp: "2022-06-08T03:54:10.675416812Z" } }
如要瞭解記錄項目的其他欄位,請參閱稽核記錄項目的格式。
後續步驟
- 使用您從記錄收到的資訊更新自動配置器。
- 瞭解自動配置器如何做出決策。
- 詳閱自動調度資源選項說明。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-19 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-19 (世界標準時間)。"],[[["\u003cp\u003eAutoscaler logs, accessible via Cloud Logging's Logs Explorer, document each scaling decision made by the autoscaler based on user-specified options.\u003c/p\u003e\n"],["\u003cp\u003eThe Logs Explorer allows you to view events related to the autoscaler's resizing recommendations for managed instance groups (MIGs) and changes in the autoscaler's status, such as operational issues.\u003c/p\u003e\n"],["\u003cp\u003eYou can use the Google Cloud console, gcloud CLI, or REST API to access and view the autoscaler logs.\u003c/p\u003e\n"],["\u003cp\u003eLog entries include details about resize actions, like the calculated vs.recommended sizes, and status changes, along with explanations for the changes, allowing for a better understanding of autoscaler behavior.\u003c/p\u003e\n"],["\u003cp\u003eAutoscaler log data contains insights about the autoscaling mode, reasons for scaling, limits applied to calculated sizes, the signals driving scaling decisions, and the resulting changes in instance group size.\u003c/p\u003e\n"]]],[],null,[]] -