啟用自動調度資源時,自動配置器會根據您指定的選項進行資源調度決策。Cloud Logging 會記錄每個調度決策。您可以在 Logs Explorer 中閱讀這些記錄,進一步瞭解自動配置器的資源調度決策。
透過 Logs Explorer,您可以查看與以下內容相關的事件:
- 自動調度器建議,可調整代管執行個體群組 (MIG) 的大小。如果自動配置器為 MIG 計算出新的建議大小,自動配置器記錄中便會描述建議大小的變更。請參閱「調整記錄項目大小」。
- 自動配置器狀態的變更。舉例來說,假設自動配置器原本能正常運作,但後來遇到問題,自動配置器記錄中便會描述此狀態變更。請參閱狀態變更記錄項目。
事前準備
- 閱讀自動調度資源說明文件。
- 擁有一個您想查看記錄的使用中自動配置器。
- 請參閱記錄檔探索工具的使用方式。
-
如果尚未設定驗證,請先完成設定。
驗證可確認您的身分,以便存取 Cloud de Confiance by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:
選取這個頁面上的分頁,瞭解如何使用範例:
控制台
使用 Cloud de Confiance 控制台存取 Cloud de Confiance by S3NS 服務和 API 時,無須設定驗證。
gcloud
-
安裝 Google Cloud CLI,然後 使用聯合身分登入 gcloud CLI。登入後,執行下列指令來初始化 Google Cloud CLI:
gcloud init
-
- 設定預設地區和區域。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI,然後 使用聯合身分登入 gcloud CLI。
詳情請參閱 Cloud de Confiance 驗證說明文件中的「使用 REST 進行驗證」。
查看自動配置器記錄
如要查看自動調整程式記錄,請使用 Cloud de Confiance 控制台、gcloud CLI 或 REST。
控制台
如果已啟用自動調度資源功能,您可以在Cloud de Confiance console中查看自動調度資源記錄。
- 前往「Logs Explorer」頁面。
- 將「資源」下拉式選單往下拉,然後選取「自動調度器」。
您也可以從 MIG 前往「Logs Explorer」頁面,方法如下:
前往 Cloud de Confiance 控制台的「Instance groups」(執行個體群組) 頁面。
按一下要查看記錄的 MIG 名稱。
按一下「監控」分頁標籤。
在「監控」分頁中,「記錄」面板位於頁面底部。按一下面板底部的「Toggle panel "Logs"」(切換「記錄」面板) keyboard_capslock ,即可展開面板。
如要開啟「記錄檔探索工具」頁面,請按一下「在記錄檔探索工具中查看」open_in_new。
記錄檔探索器會開啟,並執行預設查詢,擷取 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 的記錄項目範例。在本範例中,自動配置器根據預測自動調度資源,計算出 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 大小:
|
autoscalingReason |
自動調度資源原因的詳細資料。 |
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 的詳細資料。
|
autoscalingReason.scalingSignal.name
|
自動配置器計算 VM 數量時所依據的自動調度資源信號名稱,以記錄中的 calculatedSize 表示。 |
autoscalingReason.scalingSignal.signalPolicy
|
自動配置器判斷 calculatedSize 時所依據的自動調度資源信號設定。 |
autoscalingReason.summary
|
自動調度資源的原因說明。 |
newSize
|
目前建議的 MIG 大小。自動調度器會根據,將 MIG 大小調整為,如下所示:
autoscalingModenewSize |
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"
}
}
如要瞭解記錄項目的其他欄位,請參閱「稽核記錄項目的格式」。
後續步驟
- 使用您從記錄收到的資訊更新自動配置器。
- 瞭解自動配置器如何做出決策。
- 詳閱自動調度資源選項說明。