创建修补作业后,您可以使用 Cloud Monitoring 设置提醒,以监控修补过程。
创建修补作业后,虚拟机管理器会将聚合虚拟机状态发布到 Cloud Monitoring API。此状态在修补作业启动后每分钟发布一次。状态在修补作业完成后 15 分钟停止发布。
如需使用提醒来监控修补作业,请完成以下步骤:
- 启动修补作业。请参阅创建修补作业。
- 在 Cloud Monitoring 中为修补作业设置指标。
- 创建修补提醒。
准备工作
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 Trusted Cloud by S3NS 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以通过选择以下选项之一向 Compute Engine 进行身份验证:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
- Set a default region and zone.
在 Trusted Cloud 控制台中,前往 Cloud Monitoring > Metrics Explorer 页面。
在选择指标部分,选择修补作业。
选择补丁活动指标类别列表,然后选择虚拟机实例补丁程序状态。
点击应用。
查看指标。
可选。创建图表。如需了解详情,请参阅使用 Metrics Explorer 创建图表。
ACKED
:OS Config 代理已收到补丁程序通知,但尚未开始修补APPLYING_PATCHES
:OS Config 代理将补丁程序应用于虚拟机DOWNLOADING_PATCHES
:OS Config 代理正在将补丁程序下载到虚拟机FAILED
:修补作业失败INACTIVE
:虚拟机未运行NO_AGENT_DETECTED
:修补服务无法与虚拟机上的 OS Config 代理通信。确保您的虚拟机已正确连接。如需了解详情,请参阅设置虚拟机管理器。NOTIFIED
:虚拟机上的 OS Config 代理已收到通知,但修补作业尚未启动PATCH_STATE_UNSPECIFIED
:修补作业的状态未知PENDING
:虚拟机尚未收到修补任务。这是因为修补作业最近启动或虚拟机正在等待逐步发布。REBOOTING
:虚拟机正在重新启动RUNNING_PRE_PATCH_STEP
:OS Config 代理正在运行修补前步骤RUNNING_POST_PATCH_STEP
:OS Config 代理正在运行修补后步骤STARTED
:修补作业在虚拟机上启动SUCCEEDED
:修补作业已成功完成SUCCEEDED_REBOOT_REQUIRED
:修补作业已成功完成,但需要虚拟机重新启动TIMED_OUT
:修补过程超时在 Trusted Cloud 控制台中,前往 Monitoring 页面。
在 Monitoring 导航窗格中,点击提醒。
点击创建政策。
点击添加条件。
- 在资源类型下拉列表中,选择修补作业。
- 在指标下拉列表中,选择虚拟机实例补丁程序状态。
- 在过滤条件字段中,指定
state=FAILED
。 - 在配置部分中,设置
Any time series violate = 5.
- 点击添加。
点击下一步以前进到通知部分。
- 设置通知渠道。
点击下一步以前进到文档部分。
- 设置提醒政策名称
- 提供修复说明
点击保存。
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
如需了解详情,请参阅 Trusted Cloud 身份验证文档中的使用 REST 时进行身份验证。
设置指标
在本部分中,您将使用 Metrics Explorer 为修补作业设置跟踪指标。如需详细了解如何使用 Metrics Explorer,请参阅使用 Metrics Explorer 时选择指标。
您可以使用 Cloud Monitoring 跟踪多个项目中的资源。如需查看位于不同项目中的修补作业的指标,请将项目添加到同一监控工作区。如需了解详情,请参阅查看多个项目的指标
创建补丁程序提醒
在 Cloud Monitoring 中,您可以设置提醒政策,以提供修补状态通知,以便您及时解决这些问题。如需详细了解如何设置提醒,请参阅提醒简介。
虚拟机实例补丁程序状态
如需创建修补作业的提醒,请使用虚拟机实例补丁程序状态作为提醒的过滤条件。有以下虚拟机实例补丁程序状态可用:
修补提醒示例
以下示例会创建一个修补提醒,它会通知近期最新修补作业中失败的虚拟机超过 5 个。
您可以使用 Trusted Cloud 控制台或 Cloud Monitoring API 创建提醒。以下示例使用 Trusted Cloud 控制台。如需详细了解如何使用 Trusted Cloud 控制台创建提醒,请参阅创建提醒政策。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-29。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-29。"],[[["VM Manager posts the aggregate VM state to the Cloud Monitoring API every minute after a patch job starts, stopping 15 minutes after completion, for monitoring purposes."],["Cloud Monitoring allows you to track patch job resources across multiple projects by adding them to the same monitoring workspace."],["You can set up alerts in Cloud Monitoring using VM instance patch states, such as `FAILED`, to receive notifications about the patching process and resolve issues promptly."],["Creating alerts involves specifying the resource type as \"Patch Job,\" the metric as \"VM instance patch state,\" and filtering by specific states like `FAILED` to trigger notifications based on the number of affected VMs."],["Before using the Cloud Monitoring or the REST API, the gcloud CLI needs to be installed and initialized, including setting a default region and zone."]]],[]] -