将 IoT 中心从操作监视迁移到诊断设置Migrate your IoT Hub from operations monitoring to diagnostics settings

使用操作监视跟踪 IoT 中心内的操作状态的客户可以将该工作流迁移到 Azure 诊断设置(Azure Monitor 的一项功能)。Customers using operations monitoring to track the status of operations in IoT Hub can migrate that workflow to Azure diagnostics settings, a feature of Azure Monitor. 诊断设置针对许多 Azure 服务提供了资源级诊断信息。Diagnostics settings 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. 本文提供了将工作负荷从操作监视移动到诊断设置的步骤。This article provides steps to move your workloads from operations monitoring to diagnostics settings. 若要详细了解弃用日程表,请参阅利用 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 turn on diagnostics settings, then turn off operations monitoring.

通过诊断设置启用日志记录Enable logging with diagnostics settings

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

  2. 选择“诊断设置”。Select Diagnostics settings.

  3. 选择“启用诊断”。Select Turn on diagnostics.

    启用诊断

  4. 为诊断设置提供名称。Give the diagnostic settings a name.

  5. 选择希望将日志发送到的目标。Choose where you want to send the logs. 可选择以下三个选项的任意组合:You can select any combination of the three options:

    • 存档到存储帐户Archive to a storage account
    • 流式传输到事件中心Stream to an event hub
    • 发送到 Log AnalyticsSend to Log Analytics
  6. 选择要监视的操作,并为这些操作启用日志。Choose which operations you want to monitor, and enable logs for those operations. 诊断设置可以报告的操作如下:The operations that diagnostic settings can report on are:

    • 连接Connections
    • 设备遥测Device telemetry
    • 云到设备的消息Cloud-to-device messages
    • 设备标识操作Device identity operations
    • 文件上传File uploads
    • 消息路由Message routing
    • 云到设备孪生操作Cloud-to-device twin operations
    • 设备到云孪生操作Device-to-cloud twin operations
    • 孪生操作Twin operations
    • 作业操作Job operations
    • 直接方法Direct methods
  7. 保存新设置。Save the new settings.

如果想要通过 PowerShell 打开诊断设置,请使用以下代码:If you want to turn on diagnostics settings with PowerShell, use the following code:

Connect-AzureRmAccount -EnvironmentName AzureChinaCloud
Select-AzureRmSubscription -SubscriptionName <subscription that includes your IoT Hub>
Set-AzureRmDiagnosticSetting -ResourceId <your resource Id> -ServiceBusRuleId <your service bus rule Id> -Enabled $true

新设置在大约 10 分钟后生效。New settings take effect in about 10 minutes. 在此之后,日志将出现在“诊断设置”边栏选项卡上配置的存档目标中。After that, logs appear in the configured archival target on the Diagnostics settings blade. 有关配置诊断的详细信息,请参阅从 Azure 资源收集和使用日志数据For more information about configuring diagnostics, see Collect and consume log data from your azure resources.

关闭操作监视Turn off operations monitoring

Note

从 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 turned on in Azure Monitor diagnostic settings 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 diagnostics settings vary slightly. 请更新当前使用操作监视的应用程序以映射到诊断设置使用的架构,这非常重要。It's important that you update the applications that use operations monitoring today to map to the schema used by diagnostics settings.

此外,诊断设置还提供了五个新的跟踪类别。Also, diagnostics settings 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 Understand the schema for diagnostics settings.

后续步骤Next steps