查看和了解 MIG 数据分析


代管实例组 (MIG) 数据分析可帮助您了解属于 MIG 的虚拟机 (VM) 实例的 CPU 和内存用量。这些数据分析是根据系统指标或 Cloud Monitoring 服务收集的指标自动生成的。您可以使用这些数据分析来支持调整 MIG 机器类型大小的决策,以便更有效地使用虚拟机资源。

如需详细了解数据分析,请参阅数据分析

准备工作

  • 设置身份验证(如果尚未设置)。身份验证是通过其进行身份验证以访问 Google Cloud 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以按如下方式向 Compute Engine 进行身份验证。

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    gcloud

    1. 安装 Google Cloud CLI,然后通过运行以下命令初始化 Google Cloud CLI:

      gcloud init
    2. Set a default region and zone.
    3. REST

      如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。

        安装 Google Cloud CLI,然后通过运行以下命令初始化 Google Cloud CLI:

        gcloud init

      如需了解详情,请参阅 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。如需查看可用的虚拟机数据分析列表,请参阅 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。如需查看可用的虚拟机数据分析列表,请参阅 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_USAGE
  • LOW_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 对象数组。每个对象包含以下属性:
  • sampleProbability:(DOUBLE) 低于分位数函数值的 CPU 用量样本的相对数量。
  • quantileFunctionValue:(DOUBLE) CPU 用量的上限,它至少包含一部分样本(样本概率)。

    该值用 vCPU 总数的比率来表示,并且介于 [0, 1] 范围内。

pointsForMostUtilizedVm ARRAY 对象数组。每个对象包含以下属性:
  • sampleProbability:(DOUBLE) 低于分位数函数值的 CPU 用量样本的相对数量。
  • quantileFunctionValue:(DOUBLE) CPU 用量的上限,它至少包含一部分样本(样本概率)。

    该值用总 vCPU 的比率来表示,并且介于 [0, 1] 范围内。

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_INCREASE
  • CPU_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_USAGE
  • LOW_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 内存用量上限,至少包含利用率最低的虚拟机的样本(样本概率)。

该值用总内存量的比率来表示,并且介于 [0, 1] 范围内。

quantile_function_highest_value DOUBLE 内存用量的上限,至少包含利用率最高的虚拟机的样本部分(样本概率)。

该值用总内存量的比率来表示,并且介于 [0, 1] 范围内。

内存用量预测数据分析

Compute Engine 会创建内存用量预测数据分析来指示第二天的预测内存用量。

数据分析类型 ID 为 google.compute.instanceGroupManager.MemoryUsagePredictionInsight

典型的数据分析说明如下所示:

  • Predicted memory usage is 1536 MB.

下表提供了一些与内存用量预测数据分析关联的内容的详细信息。

属性 类型 说明
predicted_memory_mb DOUBLE 预测的内存量(以 MB 为单位)。

后续步骤