啟用自動調度資源時,自動配置器會根據您指定的選項進行資源調度決策。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,即可展開面板。
如要開啟「Logs explorer」(記錄檔探索工具) 頁面,請按一下「open_in_new」open_in_new「在記錄檔探索工具中查看」。
Logs Explorer 會開啟,並執行預設查詢,擷取 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
|
根據自動調度資源功能,限制 calculatedSize 的 VM 數量。
|
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 大小。自動配置器會根據
autoscalingMode,將 MIG 大小調整為
newSize,如下所示:
|
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"
}
}
如要瞭解記錄項目的其他欄位,請參閱「稽核記錄項目的格式」。
後續步驟
- 使用從記錄檔取得的資訊更新自動調整程式。
- 瞭解自動配置器如何制定決策。
- 詳閱自動調度資源選項說明。