将 IoT 中心从操作监视迁移到 Azure Monitor 资源日志Migrate your IoT Hub from operations monitoring to Azure Monitor resource logs

使用操作监视来跟踪 IoT 中心内操作状态的客户可以将该工作流迁移到 Azure Monitor 资源日志(Azure Monitor 的一项功能)。Customers using operations monitoring to track the status of operations in IoT Hub can migrate that workflow to Azure Monitor resource logs, a feature of Azure Monitor. 资源日志为许多 Azure 服务提供资源级诊断信息。Resource logs supply resource-level diagnostic information for many Azure services.

IoT 中心的操作监视功能已弃用,已从门户中删除。The operations monitoring functionality of IoT Hub is deprecated, and has been removed from the portal. 本文提供了将工作负载从操作监视移动到 Azure Monitor 资源日志的步骤。This article provides steps to move your workloads from operations monitoring to Azure Monitor resource logs. 若要详细了解弃用日程表,请参阅利用 Azure Monitor 和 Azure 资源运行状况监视 Azure IoT 解决方案For more information about the deprecation timeline, see Monitor your Azure IoT solutions with Azure Monitor and Azure Resource Health.

更新 IoT 中心Update IoT Hub

若要在 Azure 门户中更新 IoT 中心,请先创建诊断设置,然后关闭操作监视。To update your IoT Hub in the Azure portal, first create a diagnostic setting, then turn off operations monitoring.

创建诊断设置Create a diagnostic setting

  1. 登录 Azure 门户,导航到 IoT 中心。Sign in to the Azure portal and navigate to your IoT hub.

  2. 在左窗格中的“监视”下,选择“诊断设置” 。On the left pane, under Monitoring, select Diagnostics settings. 然后选择“添加诊断设置”。Then select Add diagnostic setting.

    突出显示“监视”部分的“诊断设置”的屏幕截图。

  3. 在“诊断设置”窗格中,为该诊断设置指定一个名称。On the Diagnostic setting pane, give the diagnostic setting a name.

  4. 在“类别详细信息”下,选择要监视的操作的类别。Under Category details, select the categories for the operations you want to monitor. 若要详细了解可用于 IoT 中心的操作类别,请参阅资源日志For more information about the categories of operations available with IoT Hub, see Resource logs.

  5. 在“目标详细信息”下,选择要将日志发送到的位置。Under Destination details, choose where you want to send the logs. 可以选择以下这些目标的任意组合:You can select any combination of these destinations:

    • 存档到存储帐户Archive to a storage account
    • 流式传输到事件中心Stream to an event hub
    • 通过 Log Analytics 工作区发送到 Azure Monitor 日志Send to Azure Monitor Logs via a Log Analytics workspace

    以下屏幕截图显示了一个诊断设置,该诊断设置将“连接”和“设备遥测”类别中的操作路由到 Log Analytics 工作区:The following screenshot shows a diagnostic setting that routes operations in the Connections and Device telemetry categories to a Log Analytics workspace:

    屏幕截图显示了已完成的诊断设置。

  6. 选择“保存”,保存这些设置。Select Save to save the settings.

新设置在大约 10 分钟后生效。New settings take effect in about 10 minutes. 在此之后,日志就会出现在已配置的目标中。After that, logs appear in the configured destination. 有关配置诊断的详细信息,请参阅从 Azure 资源收集和使用日志数据For more information about configuring diagnostics, see Collect and consume log data from your Azure resources.

若要详细了解如何创建诊断设置(包括使用 PowerShell 和 Azure CLI 进行创建),请参阅 Azure Monitor 文档中的诊断设置For more detailed information about how to create diagnostic settings, including with PowerShell and the Azure CLI, see Diagnostic settings in the Azure Monitor documentation.

关闭操作监视Turn off operations monitoring

备注

从 2019 年 3 月 11 日开始,IoT 中心的 Azure 门户接口不再有操作监视功能。As of March 11, 2019, the operations monitoring feature is removed from IoT Hub's Azure portal interface. 以下步骤不再适用。The steps below no longer apply. 若要进行迁移,请确保使用上面的 Azure Monitor 诊断设置将正确的类别路由到目标。To migrate, make sure that the correct categories are routed to a destination with an Azure Monitor diagnostic setting above.

在工作流中测试新的诊断设置后,可以关闭操作监视功能。Once you test the new diagnostics settings in your workflow, you can turn off the operations monitoring feature.

  1. 在 IoT 中心菜单中,选择“操作监视”。 In your IoT Hub menu, select Operations monitoring.

  2. 在每个监视类别下,选择“无”。 Under each monitoring category, select None.

  3. 保存操作监视更改。Save the operations monitoring changes.

更新使用操作监视的应用程序Update applications that use operations monitoring

操作监视和资源日志在架构上略有不同。The schemas for operations monitoring and resource logs vary slightly. 请更新当前使用操作监视的应用程序,以映射到资源日志使用的架构,这非常重要。It's important that you update the applications that use operations monitoring today to map to the schema used by resource logs.

此外,IoT 中心资源日志还提供了五个新类别以用于跟踪。Also, IoT Hub resource logs offers five new categories for tracking. 更新应用程序的现有架构后,还要添加新类别:After you update applications for the existing schema, add the new categories as well:

  • 云到设备孪生操作Cloud-to-device twin operations
  • 设备到云孪生操作Device-to-cloud twin operations
  • 孪生查询Twin queries
  • 作业操作Jobs operations
  • 直接方法Direct Methods

有关特定架构结构,请参阅资源日志For the specific schema structures, see Resource logs.

以低延迟监视设备连接和断开连接事件Monitoring device connect and disconnect events with low latency

若要监视生产环境中的设备连接和断开连接事件,我们建议订阅事件网格上的“设备已断开连接” 事件以获取警报并监视设备连接状态。To monitor device connect and disconnect events in production, we recommend subscribing to the device disconnected event on Event Grid to get alerts and monitor the device connection state. 使用此教程了解如何在 IoT 解决方案中集成 IoT 中心的设备已连接和设备已断开连接事件。Use this tutorial to learn how to integrate Device Connected and Device Disconnected events from IoT Hub in your IoT solution.

后续步骤Next steps

监视 IoT 中心Monitor IoT Hub