代管執行個體群組 (MIG) Insights 可協助您瞭解 MIG 中虛擬機器 (VM) 執行個體的 CPU 和記憶體用量。這些洞察資料是根據系統指標或 Cloud Monitoring 服務收集的指標自動產生。您可以根據這些洞察資料,決定是否要調整 MIG 的機型大小,以提高 VM 資源的使用效率。
如要進一步瞭解洞察,請參閱「洞察」。
事前準備
-
如果尚未設定驗證,請先完成設定。
驗證可確認您的身分,以便存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:
選取這個頁面上的分頁,瞭解如何使用範例:
控制台
使用 Google Cloud 控制台存取 Google Cloud 服務和 API 時,無須設定驗證。
gcloud
-
安裝 Google Cloud CLI。 完成後,執行下列指令來初始化 Google Cloud CLI:
gcloud init若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
-
- 設定預設地區和區域。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI。
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
詳情請參閱 Google Cloud 驗證說明文件中的「使用 REST 進行驗證」。
查看 MIG 建議的洞察資料
Compute Engine 會根據資源洞察產生機型建議。查看與特定 MIG 相關的洞察資料,進一步瞭解 MIG 的 CPU 和記憶體用量。
如要查看產生特定建議的洞察,請使用 gcloud CLI 或 REST。
gcloud
如要查看特定區域的所有可用深入分析詳細資料,請使用 insights list 指令。
gcloud recommender insights list --project=PROJECT_ID \ --location=LOCATION \ --insight-type=INSIGHT_TYPE_ID \ --format=FORMAT
更改下列內容:
PROJECT_ID:專案 ID。LOCATION:包含要查看洞察資料的資源的區域。INSIGHT_TYPE_ID:洞察類型的 ID。如需可用的 VM 深入分析清單,請參閱「MIG 深入分析類型」。FORMAT:偏好的輸出格式,例如json。
使用 json 輸出格式時,insights list 指令的典型輸出內容可能如下所示。
[
{
"name": "projects/PROJECT_ID/locations/us-central1-a/insightTypes/google.compute.instanceGroupManager.CpuUsagePredictionInsight/insights/0ec21a13-bb04-3121-7321-dc43a11cc3e3",
"description": "Predicted CPU usage is 1.5 vCPUs.",
"targetResources": [
"//compute.googleapis.com/projects/PROJECT_ID/zones/us-central1-a/instanceGroupManagers/test-instance"
],
"insightSubtype": "CPU_USAGE_PREDICTION",
"lastRefreshTime": "2021-09-15T06:50:45Z",
"observationPeriod": "14 days",
"stateInfo": {
"state": "ACTIVE"
},
"content": {
"predictedCpuCores": 1.5
},
"category": "PERFORMANCE",
"etag": "fds421j2340",
"associatedRecommendations": [
{
"recommendation": "projects/PROJECT_ID/locations/us-central1-a/recommenders/google.compute.instanceGroupManager.MachineTypeRecommender/recommendations/0fd31b24-cc05-4132-8431-ed54a22dd4f1"
}
]
}
]
REST
如要查看特定區域的所有可用洞察資料,請使用 insights.list 方法。
GET https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/insightTypes/INSIGHT_TYPE_ID/insights
更改下列內容:
PROJECT_ID:專案 ID。LOCATION:包含要查看洞察資料的資源的區域。INSIGHT_TYPE_ID:洞察類型的 ID。如需可用的 VM 深入分析清單,請參閱「MIG 深入分析類型」。
insights.list 方法的典型輸出內容可能如下所示。
[
{
"name": "projects/PROJECT_ID/locations/us-central1-a/insightTypes/google.compute.instanceGroupManager.CpuUsagePredictionInsight/insights/0ec21a13-bb04-3121-7321-dc43a11cc3e3",
"description": "Predicted CPU usage is 1.5 vCPUs.",
"targetResources": [
"//compute.googleapis.com/projects/PROJECT_ID/zones/us-central1-a/instanceGroupManagers/test-instance"
],
"insightSubtype": "CPU_USAGE_PREDICTION",
"lastRefreshTime": "2021-09-15T06:50:45Z",
"observationPeriod": "14 days",
"stateInfo": {
"state": "ACTIVE"
},
"content": {
"predictedCpuCores": 1.5
},
"category": "PERFORMANCE",
"etag": "fds421j2340",
"associatedRecommendations": [
{
"recommendation": "projects/PROJECT_ID/locations/us-central1-a/recommenders/google.compute.instanceGroupManager.MachineTypeRecommender/recommendations/0fd31b24-cc05-4132-8431-ed54a22dd4f1"
}
]
}
]
如要進一步瞭解洞察資料,請參閱參考文件。
MIG 洞察類型
您可以運用各種深入分析,取得 MIG 成效相關資訊。每種洞察類型都有特定的內容屬性。
下列各節提供可用的 MIG 洞察參考資料。
CPU 使用率洞察
如果 MIG 的 CPU 使用率在過去觀察期間內高於或低於平常,Compute Engine 就會建立 CPU 使用率洞察。
洞察類型 ID 為 google.compute.instanceGroupManager.CpuUsageInsight。
可用的子類型如下:
HIGH_CPU_USAGELOW_CPU_USAGE
這些項目與洞察資料說明相關聯,例如:
In the last 7 days for 80% of the time, CPU usage was greater than or equal to 83% for the least utilized VM instance. In the last 7 days for 80% of the time, CPU usage was greater than or equal to 93% for the most utilized VM instance.In the last 7 days for 80% of the time, CPU usage was lower than or equal to 10% for the most utilized VM instance. In the last 7 days for 80% of the time, CPU usage was lower than or equal to 3% for the least utilized VM instance.
下表提供與 CPU 使用率洞察資訊相關的內容詳細資料。
| 屬性 | 類型 | 說明 |
pointsForLeastUtilizedVm |
ARRAY | 物件陣列。每個物件都包含下列屬性:
|
pointsForMostUtilizedVm |
ARRAY | 物件陣列。每個物件都包含下列屬性:
|
CPU 用量預測深入分析
Compute Engine 會建立 CPU 使用率預測洞察資料,指出隔天的預測 CPU 使用率。
洞察類型 ID 為 google.compute.instanceGroupManager.CpuUsagePredictionInsight。
這項洞察資訊通常會顯示類似下列的說明:
Predicted CPU usage of a single instance is 1.5 vCPUs.
下表提供與 CPU 使用率預測洞察資訊相關的內容詳細資料。
| 屬性 | 類型 | 說明 |
predicted_cpu_cores
|
DOUBLE | 預測的 CPU 核心數量。 |
CPU 用量趨勢深入分析
如果 CPU 使用率在過去觀察期間內呈現上升或下降趨勢,Compute Engine 就會建立 CPU 使用率趨勢深入分析。
洞察類型 ID 為 google.compute.instanceGroupManager.CpuUsageTrendInsight。
可用的子類型如下:
CPU_USAGE_INCREASECPU_USAGE_DECREASE
這些通常與下列洞察資料說明相關聯:
In the last 7 days, average daily CPU usage has increased by 8% from 65% to 73%.In the last 7 days, average daily CPU usage has decreased by 10% from 55% to 45%.
下表提供與 CPU 使用率趨勢洞察資訊相關內容的部分詳細資料。
| 屬性 | 類型 | 說明 |
cpu_usage_percentage_at_start
|
DOUBLE | 測量觀察期開始時的每日平均 CPU 使用率。 這個值代表 vCPU 總數的百分比,範圍為 [0, 100]。 |
cpu_usage_percentage_at_end
|
DOUBLE | 測量觀察期結束時的每日平均 CPU 使用率。 這個值代表 vCPU 總數的百分比,範圍為 [0, 100]。 |
cpu_usage_percentage_change
|
DOUBLE | 預測觀測期間內 CPU 使用率每日平均值的變化。 預測功能會使用線性迴歸,模擬每日 CPU 用量的變化。 這個值代表 vCPU 總數的百分比,範圍為 [0, 100]。 |
記憶體用量洞察
如果記憶體用量在觀察期間內異常偏高或偏低,Compute Engine 就會建立記憶體用量洞察資料。
洞察類型 ID 為 google.compute.instanceGroupManager.MemoryUsageInsight。
可用的子類型如下:
HIGH_MEMORY_USAGELOW_MEMORY_USAGE
這些通常與下列洞察資料說明相關聯:
In the last 12 days for 80% of the time, memory usage was greater than or equal to 64%.In the last 7 days for 50% of the time, memory usage was lower than or equal to 10%.
下表提供與記憶體用量洞察資訊相關內容的部分詳細資料。
| 屬性 | 類型 | 說明 |
sample_probability
|
DOUBLE | 低於分位數函式值的記憶體用量樣本相對量。
值介於 [0, 1] 之間。 |
quantile_function_lowest_value
|
DOUBLE | 記憶體用量上限,至少會保留 最少用量 VM 的部分樣本 (樣本機率)。 這個值代表記憶體總量的比例,範圍為 [0, 1]。 |
quantile_function_highest_value
|
DOUBLE | 記憶體用量上限,至少會保留最常使用的 VM 樣本 (樣本機率) 的一部分。 這個值代表記憶體總量的比例,範圍為 [0, 1]。 |
記憶體用量預測深入分析
Compute Engine 會建立記憶體用量預測洞察,指出隔天的預測記憶體用量。
洞察類型 ID 為 google.compute.instanceGroupManager.MemoryUsagePredictionInsight。
典型的洞察說明如下:
Predicted memory usage is 1536 MB.
下表提供與記憶體用量預測洞察資訊相關的內容詳細資料。
| 屬性 | 類型 | 說明 |
predicted_memory_mb
|
DOUBLE | 預測的記憶體量,以 MB 為單位。 |
後續步驟
- 進一步瞭解 Compute Engine 根據深入分析建立的機型建議。