虚拟机 (VM) 实例数据分析可帮助您了解 Compute Engine 虚拟机的 CPU、内存和网络使用情况。系统会根据系统指标或 Cloud Monitoring 收集的指标自动生成数据分析。您可以使用数据分析来决定如何调整机器类型大小以更有效地使用虚拟机资源。
如需详细了解数据分析,请参阅数据分析。
准备工作
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 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
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
PROJECT_ID
:您的项目的 ID。LOCATION
:要查看其数据分析的资源所在的可用区。INSIGHT_TYPE_ID
:数据分析类型的 ID。如需查看可用虚拟机数据分析的列表,请参阅虚拟机实例数据分析类型。FORMAT
:您的首选输出格式,例如json
。PROJECT_ID
:您的项目的 ID。LOCATION
:要查看其数据分析的资源所在的可用区。INSIGHT_TYPE_ID
:数据分析类型的 ID。如需查看可用虚拟机数据分析的列表,请参阅虚拟机实例数据分析类型。HIGH_CPU_USAGE
LOW_CPU_USAGE
In the last 12 days for 90% of the time, CPU usage was greater than or equal to 83%.
In the last 10 days for 70% of the time, CPU usage was lower than or equal to 20%.
sampleProbability
:(DOUBLE) 低于分位数函数值的 CPU 用量样本的相对数量。quantileFunctionValue
:(DOUBLE) CPU 用量的上限,它至少包含一部分样本(样本概率)。
该值用 vCPU 总数的比率来表示,并且介于 [0, 1] 范围内。Predicted CPU usage is 0.1 vCPUs.
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%.
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%.
sampleProbability
:(DOUBLE) 低于分位数函数值的内存用量样本的相对数量。quantileFunctionValue
:(DOUBLE) 内存用量的上限,它至少包含一部分样本(样本概率)。
该值用总内存量的比率来表示,并且介于 [0, 1] 范围内。Predicted memory usage is 1536 MB.
LOW_RECEIVED_NETWORK_THROUGHPUT
LOW_SENT_NETWORK_THROGHPUT
In the last 7 days for 80% of the time, received network throughput was lower than or equal to 500 B/s.
In the last 7 days for 80% of the time, sent network throughput was lower than or equal to 200 B/s.
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
查看虚拟机数据分析建议
Compute Engine 会根据资源数据分析生成建议。这些建议包括机器类型建议和空闲虚拟机建议。
通过查看与特定虚拟机关联的数据分析,您可以详细了解虚拟机的 CPU、内存和网络使用情况。
如需查看生成特定建议的数据分析,请使用 gcloud CLI 或 API。
gcloud
如需查看特定可用区的所有可用数据分析的详情,请使用
insights list
命令并提供--format
选项。gcloud recommender insights list --project=PROJECT_ID \ --location=LOCATION \ --insight-type=INSIGHT_TYPE_ID \ --format=FORMAT
替换以下内容:
使用
json
输出格式的insights list
命令的典型输出可能如下所示。[ { "associatedRecommendations": [ { "recommendation": "projects/PROJECT_ID/locations/us-central1-a/recommenders/google.compute.instance.MachineTypeRecommender/recommendations/7618763b-fee2-42e5-8b9b-e6eee0b2077f" } ], "category": "PERFORMANCE", "content": { "predictedCpuCores": 0.15 }, "description": "Predicted CPU usage is 0.1 vCPUs.", "etag": "\"fdb51460cac758a0\"", "insightSubtype": "CPU_USAGE_PREDICTION", "lastRefreshTime": "2021-09-15T06:50:45Z", "name": "projects/PROJECT_ID/locations/us-central1-a/insightTypes/google.compute.instance.CpuUsagePredictionInsight/insights/cb2ab4e6-2c5e-4f0e-8cbe-1487e8bae8c0", "observationPeriod": "604800s", "severity": "LOW", "stateInfo": { "state": "ACTIVE" }, "targetResources": [ "//compute.googleapis.com/projects/PROJECT_ID/zones/us-central1-a/instances/instance-name-1" ] } ]
REST
如需详细了解特定可用区的所有可用数据分析,请使用
insights.list
方法。GET https://recommender.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/insightTypes/INSIGHT_TYPE_ID/insights
替换以下内容:
insights.list
方法的典型输出可能如下所示。[ { "associatedRecommendations": [ { "recommendation": "projects/PROJECT_ID/locations/us-central1-a/recommenders/google.compute.instance.MachineTypeRecommender/recommendations/7618763b-fee2-42e5-8b9b-e6eee0b2077f" } ], "category": "PERFORMANCE", "content": { "predictedCpuCores": 0.15 }, "description": "Predicted CPU usage is 0.1 vCPUs.", "etag": "\"fdb51460cac758a0\"", "insightSubtype": "CPU_USAGE_PREDICTION", "lastRefreshTime": "2021-09-15T06:50:45Z", "name": "projects/PROJECT_ID/locations/us-central1-a/insightTypes/google.compute.instance.CpuUsagePredictionInsight/insights/cb2ab4e6-2c5e-4f0e-8cbe-1487e8bae8c0", "observationPeriod": "604800s", "severity": "LOW", "stateInfo": { "state": "ACTIVE" }, "targetResources": [ "//compute.googleapis.com/projects/PROJECT_ID/zones/us-central1-a/instances/instance-name-1" ] } ]
如需详细了解数据洞见,请参阅参考文档。
虚拟机实例数据分析的类型
您可以使用不同的数据分析来检索有关虚拟机性能的信息。每种数据分析类型都有特定的内容属性。
以下部分提供了可用的虚拟机数据分析的参考信息。
CPU 用量数据分析
如果虚拟机的 CPU 用量在最近一个观察期内高于或低于正常水平,Compute Engine 便会创建 CPU 用量数据分析。
该数据分析类型的 ID 为
google.compute.instance.CpuUsageInsight
。可用的子类型包括:
它们与数据分析说明相关联,如下所示:
下表提供了一些与 CPU 用量数据分析关联的内容的详细信息。
属性 类型 说明 points
ARRAY 对象数组。每个对象包含以下属性:
CPU 用量预测数据分析
Compute Engine 会创建 CPU 用量预测数据分析,以指示第二天的预测 CPU 用量。
该数据分析类型的 ID 为
google.compute.instance.CpuUsagePredictionInsight
。可在此数据分析中找到的典型说明如下所示:
下表提供了一些与 CPU 用量预测数据分析关联的内容的详细信息。
属性 类型 说明 predicted_cpu_cores
DOUBLE 预测的 CPU 核心数。 CPU 用量趋势数据分析
如果 CPU 用量在最近一个观察期内呈现上升或下降的趋势,Compute Engine 便会创建 CPU 用量趋势数据分析。
该数据分析类型的 ID 为
google.compute.instance.CpuUsageTrendInsight
。可用的子类型包括:
它们通常与数据分析说明相关联,如下所示:
下表提供了一些与 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.instance.MemoryUsageInsight
。可用的子类型包括:
它们通常与数据分析说明相关联,如下所示:
下表提供了一些与内存用量数据分析关联的内容的详细信息。
属性 类型 说明 points
ARRAY 对象数组。每个对象包含以下属性: 内存用量预测数据分析
Compute Engine 会创建内存用量预测数据分析来指示第二天的预测内存用量。
该数据分析类型的 ID 为
google.compute.instance.MemoryUsagePredictionInsight
。典型的数据分析说明如下所示:
下表提供了一些与内存用量预测数据分析关联的内容的详细信息。
属性 类型 说明 predicted_memory_mb
DOUBLE 预测的内存量(以 MB 为单位)。 网络吞吐量数据分析
如果观察期内传入或传出流量的网络吞吐量异常低,Compute Engine 便会创建网络吞吐量数据分析。
该数据分析类型的 ID 为
google.compute.instance.NetworkThroughputInsight
。可用的子类型包括:
它们通常与数据分析说明相关联,如下所示:
下表提供了一些与网络吞吐量数据分析关联的内容的详细信息。
属性 类型 说明 sample_probability
DOUBLE 低于分位数函数值的网络吞吐量样本的相对数量。 该值介于 [0, 1] 范围内。
quantile_function_value_in_bytes_per_second
DOUBLE 网络吞吐量的上限,它至少包含一部分样本(样本概率)。该值以每秒字节数为单位。 后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-08。
-