您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

教程:使用时序见解直观显示和分析 Azure 数字孪生空间中的事件Tutorial: Visualize and analyze events from your Azure Digital Twins spaces by using Time Series Insights

部署 Azure 数字孪生实例、预配空间并实现用于监视特定条件的自定义函数以后,即可将空间中的事件和数据可视化,查找趋势和异常。After you deploy your Azure Digital Twins instance, provision your spaces, and implement a custom function to monitor specific conditions, you can visualize the events and data coming from your spaces to look for trends and anomalies.

第一个教程中,你配置了一栋虚构大楼的空间图,其中一个房间包含用于移动、二氧化碳和温度的传感器。In the first tutorial, you configured the spatial graph of an imaginary building, with a room that contains sensors for motion, carbon dioxide, and temperature. 第二个教程中,已预配了图形和用户定义的函数。In the second tutorial, you provisioned your graph and a user-defined function. 此函数监视这些传感器值并在条件适当的情况下触发通知,The function monitors these sensor values and triggers notifications for the right conditions. 这里的条件适当是指房间为空房间且温度和二氧化碳水平正常。That is, the room is empty, and the temperature and carbon dioxide levels are normal.

本教程介绍如何将这些通知和来自 Azure 数字孪生设置的数据与 Azure 时序见解集成。This tutorial shows you how you can integrate the notifications and data coming from your Azure Digital Twins setup with Azure Time Series Insights. 然后,你可以将某段时间的传感器值可视化,You can then visualize your sensor values over time. 查找各种趋势,例如,哪个房间使用频率最高、一天中最忙的时间是什么时间。You can look for trends such as which room is getting the most use and which are the busiest times of the day. 也可检测异常,例如,哪些房间让人感觉又闷又热,或者大楼中某个区域发送的温度值是否始终很高,表明空调故障。You can also detect anomalies such as which rooms feel stuffier and hotter, or whether an area in your building is sending consistently high temperature values, indicating faulty air conditioning.

本教程介绍如何执行下列操作:In this tutorial, you learn how to:

  • 使用 Azure 事件中心对数据进行流式传输。Stream data by using Azure Event Hubs.
  • 使用时序见解进行分析。Analyze with Time Series Insights.

先决条件Prerequisites

本教程假定你已配置预配 Azure 数字孪生设置。This tutorial assumes that you have configured and provisioned your Azure Digital Twins setup. 在继续操作之前,请确保已具备以下条件:Before proceeding, make sure that you have:

使用事件中心对数据进行流式传输Stream data by using Event Hubs

可以使用事件中心服务创建流式传输数据所需的管道。You can use the Event Hubs service to create a pipeline to stream your data. 本部分介绍如何将事件中心创建为 Azure 数字孪生和时序见解实例之间的连接器。This section shows you how to create your event hub as the connector between your Azure Digital Twins and Time Series Insights instances.

创建事件中心Create an event hub

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左窗格中,选择“创建资源” 。In the left pane, select Create a resource.

  3. 搜索并选择“事件中心” 。Search for and select Event Hubs. 选择“创建” 。Select Create.

  4. 为事件中心命名空间输入一个“名称” 。Enter a Name for your Event Hubs namespace. 选择“标准” 作为定价层,然后选择你的订阅、用于数字孪生实例的资源组,以及位置Choose Standard for Pricing tier, your Subscription, the Resource group that you used for your Digital Twins instance, and the Location. 选择“创建” 。Select Create.

  5. 在事件中心命名空间部署中,选择“概述” 窗格,然后选择“转到资源” 。In the Event Hubs namespace deployment, select the Overview pane, then select Go to resource.

    部署后的事件中心命名空间

  6. 在事件中心命名空间的“概览”窗格中,选择顶部的“事件中心”按钮 。In the Event Hubs namespace Overview pane, select the Event Hub button at the top. “事件中心”按钮Event Hub button

  7. 为事件中心输入一个“名称”,然后选择“创建” 。Enter a Name for your event hub, and select Create.

    事件中心在部署以后,会显示在其命名空间的“事件中心”窗格中,其“状态”为“活动”。 After the event hub is deployed, it appears in the Event Hubs pane of the Event Hubs namespace with an Active status. 选择此事件中心,打开其“概览”窗格。 Select this event hub to open its Overview pane.

  8. 选择顶部的“使用者组”按钮,为使用者组输入一个名称,例如 tsieventsSelect the Consumer group button at the top, and enter a name such as tsievents for the consumer group. 选择“创建” 。Select Create.

    事件中心使用者组

    使用者组在创建以后,会显示在事件中心的“概览”窗格底部的列表中。 After the consumer group is created, it appears in the list at the bottom of the event hub's Overview pane.

  9. 打开事件中心的“共享访问策略”窗格,然后选择“添加”按钮。 Open the Shared access policies pane for your event hub, and select the Add button. 输入 ManageSend 作为策略名称,确保所有复选框都已选中,然后选择“创建”。 Enter ManageSend as the policy name, make sure all the check boxes are selected, and select Create.

    事件中心连接字符串

  10. 打开已创建的 ManageSend 策略,将“连接字符串--主键”和“连接字符串--辅助键”的值复制到一个临时文件中。 Open the ManageSend policy that you created, and copy the values for Connection string--primary key and Connection string--secondary key to a temporary file. 在下一部分,将需要这些值来创建事件中心的终结点。You'll need these values to create an endpoint for the event hub in the next section.

为事件中心创建终结点Create an endpoint for the event hub

  1. 在命令窗口中,确保当前位置为 Azure 数字孪生示例的 occupancy-quickstart\src 文件夹。In the command window, make sure you're in the occupancy-quickstart\src folder of the Azure Digital Twins sample.

  2. 在编辑器中打开 actions\createEndpoints.yaml 文件。Open the file actions\createEndpoints.yaml in your editor. 将内容替换为以下内容:Replace the contents with the following:

    - type: EventHub
      eventTypes:
      - SensorChange
      - SpaceChange
      - TopologyOperation
      - UdfCustom
      connectionString: Primary_connection_string_for_your_event_hub
      secondaryConnectionString: Secondary_connection_string_for_your_event_hub
      path: Name_of_your_Event_Hub
    - type: EventHub
      eventTypes:
      - DeviceMessage
      connectionString: Primary_connection_string_for_your_event_hub
      secondaryConnectionString: Secondary_connection_string_for_your_event_hub
      path: Name_of_your_Event_Hub
    
  3. 将占位符 Primary_connection_string_for_your_event_hub 替换为事件中心的“连接字符串--主键”的值。 Replace the placeholders Primary_connection_string_for_your_event_hub with the value of Connection string--primary key for the event hub. 确保此连接字符串的格式如下:Make sure the format of this connection string is as follows:

    Endpoint=sb://nameOfYourEventHubNamespace.servicebus.windows.net/;SharedAccessKeyName=ManageSend;SharedAccessKey=yourShareAccessKey1GUID;EntityPath=nameOfYourEventHub
    
  4. 将占位符 Secondary_connection_string_for_your_event_hub 替换为事件中心的“连接字符串--辅助键”的值。 Replace the placeholders Secondary_connection_string_for_your_event_hub with the value of Connection string--secondary key for the event hub. 确保此连接字符串的格式如下:Make sure the format of this connection string is as follows:

    Endpoint=sb://nameOfYourEventHubNamespace.servicebus.windows.net/;SharedAccessKeyName=ManageSend;SharedAccessKey=yourShareAccessKey2GUID;EntityPath=nameOfYourEventHub
    
  5. 将占位符 Name_of_your_Event_Hub 替换为事件中心的名称。Replace the placeholders Name_of_your_Event_Hub with the name of your Event Hub.

    重要

    输入所有值,不带任何引号。Enter all values without any quotes. 在 YAML 文件中,请确保在冒号之后至少有一个空格字符。Make sure there's at least one space character after the colons in the YAML file. 也可使用任何联机 YAML 验证程序(例如此工具)来验证 YAML 文件内容。You can also validate your YAML file contents by using any online YAML validator, such as this tool.

  6. 保存并关闭该文件。Save and close the file. 在命令窗口中运行以下命令,在系统提示时使用 Azure 帐户登录。Run the following command in the command window, and sign in with your Azure account when prompted.

    dotnet run CreateEndpoints
    

    它为事件中心创建两个终结点。It creates two endpoints for your event hub.

    事件中心的终结点

使用时序见解进行分析Analyze with Time Series Insights

  1. Azure 门户的左窗格中,选择“创建资源” 。In the left pane of the Azure portal, select Create a resource.

  2. 搜索并选择新的“时序见解”资源。 Search for and select a new Time Series Insights resource. 选择“创建” 。Select Create.

  3. 为时序见解实例输入一个名称,然后选择你的订阅Enter a Name for your Time Series Insights instance, and then select your Subscription. 选择用于数字孪生实例的“资源组” ,然后选择“位置”。 Select the Resource group that you used for your Digital Twins instance, and your Location. 在完成时选择“下一步: 事件源”按钮或“事件源” 选项卡。Select Next: Event Source button or the Event Source tab.

    用于创建时序见解实例的选择

  4. 在“事件源” 选项卡中,输入名称,选择“事件中心” 作为源类型,并确保正确选择其他值。In the Event Source tab, enter a Name, select Event Hub as the Source type, and make sure the other values are selected correctly. 选择 ManageSend 作为“事件中心访问策略名称”, ,然后选择在上一部分创建的使用者组,作为“事件中心使用者组”。 Select ManageSend for Event Hub access policy name, and then select the consumer group that you created in the previous section for Event Hub consumer group. 选择“查看 + 创建” 。Select Review + create.

    用于创建事件源的选择

  5. 在“查看 + 创建” 窗格中,查看所输入的信息,然后选择“创建” 。In the Review + Create pane, review the information you entered, and select Create.

  6. 在部署窗格中,选择刚刚创建的“时序见解”资源。In the deployment pane, select the Time Series Insights resource you just created. 它将打开时序见解环境的“概述” 窗格。It opens the Overview pane for your Time Series Insights environment.

  7. 选择顶部的“转到环境” 按钮。Select the Go to Environment button at the top. 如果出现数据访问警告,则请打开时序见解实例的“数据访问策略”窗格,选择“添加”,选择“参与者”作为角色,然后选择适当的用户。 If you get a data access warning, open the Data Access Policies pane for your Time Series Insights instance, select Add, select Contributor as the role, and select the appropriate user.

  8. “转到环境”按钮会打开时序见解资源管理器The Go to Environment button opens the Time Series Insights explorer. 如果它不显示任何事件,请模拟设备事件,方法是:浏览到数字孪生示例的 device-connectivity 项目,然后运行 dotnet runIf it doesn't show any events, simulate device events by browsing to the device-connectivity project of your Digital Twins sample, and running dotnet run.

  9. 生成一些模拟的事件以后,请返回到时序见解资源管理器,选择顶部的刷新按钮。After a few simulated events are generated, go back to the Time Series Insights explorer, and select the refresh button at the top. 此时会看到系统针对模拟的传感器数据生成分析图表。You should see analytical charts being created for your simulated sensor data.

    时序见解资源管理器中的图表

  10. 然后,可以在时序见解资源管理器中针对来自房间、传感器和其他资源的不同事件和数据生成图表和热度地图。In the Time Series Insights explorer, you can then generate charts and heatmaps for different events and data from your rooms, sensors, and other resources. 在左侧使用“度量值”和“拆分方式”下拉框创建自己的可视化效果。 On the left side, use the MEASURE and SPLIT BY drop-down boxes to create your own visualizations.

    例如,选择“事件”作为“度量值”,选择“DigitalTwins-SensorHardwareId”作为“拆分方式”,以便为每个传感器生成热度地图。 For example, select Events for MEASURE and DigitalTwins-SensorHardwareId for SPLIT BY, to generate a heatmap for each of your sensors. 热度地图将类似于下图:The heatmap will be similar to the following image:

    时序见解资源管理器中的热度地图

清理资源Clean up resources

如果不希望继续探索 Azure 数字孪生,可以删除本教程中创建的资源:If you want to stop exploring Azure Digital Twins beyond this point, feel free to delete resources created in this tutorial:

  1. Azure 门户的左菜单中依次选择“所有资源”、 数字孪生资源组、“删除”。 From the left menu in the Azure portal, select All resources, select your Digital Twins resource group, and then select Delete.

    提示

    如果在删除数字孪生实例时遇到麻烦,请使用已推出的包含修补程序的服务更新。If you experienced trouble deleting your Digital Twins instance, a service update has been rolled out with the fix. 请重新尝试删除实例。Please retry deleting your instance.

  2. 可以根据需要删除工作计算机上的示例应用程序。If necessary, delete the sample applications on your work machine.

后续步骤Next steps

请继续阅读下一篇文章,详细了解 Azure 数字孪生中的空间智能图和对象模型。Go to the next article to learn more about spatial intelligence graphs and object models in Azure Digital Twins.