将异常检测器模块部署到 IoT EdgeDeploy an Anomaly Detector module to IoT Edge

了解如何将认知服务异常检测器模块部署到 IoT Edge 设备。Learn how to deploy the Cognitive Services Anomaly Detector module to an IoT Edge device. 将模块部署到 IoT Edge 后,它将与其他模块一起在 IoT Edge 中作为容器实例运行。Once it's deployed into IoT Edge, the module runs in IoT Edge together with other modules as container instances. 它公开了与在标准 Docker 容器环境中运行的异常检测器容器实例完全相同的 API。It exposes the exact same APIs as an Anomaly Detector container instance running in a standard docker container environment.

先决条件Prerequisites

创建异常检测器资源Create an Anomaly Detector resource

  1. 登录到 Azure 门户Sign into the Azure portal.

  2. 选择创建异常检测器 资源。Select Create Anomaly Detector resource.

  3. 输入所有必需的设置:Enter all required settings:

    设置Setting ValueValue
    名称Name 所需名称(2-64 个字符)Desired name (2-64 characters)
    订阅Subscription 选择相应的订阅Select appropriate subscription
    位置Location 选择附近任何可用的位置Select any nearby and available location
    定价层Pricing Tier F0 - 每秒 10 次调用,每月 20,000 个事务。F0 - 10 Calls per second, 20K Transactions per month.
    或者:Or:
    S0 - 每秒 80 次调用S0 - 80 Calls per second
    资源组Resource Group 选择可用的资源组Select an available resource group
  4. 单击“创建”并等待创建资源。Click Create and wait for the resource to be created. 创建资源后,导航到“资源”页After it is created, navigate to the resource page

  5. 收集配置的 endpoint 和 API 密钥:Collect configured endpoint and an API key:

    门户中的“密钥和终结点”选项卡Keys and Endpoint tab in the portal 设置Setting ValueValue
    概述Overview 终结点Endpoint 复制终结点。Copy the endpoint. 它看起来类似于 https://<your-resource-name>.cognitiveservices.azure.cn/It looks similar to https://<your-resource-name>.cognitiveservices.azure.cn/
    “键”Keys API 密钥API Key 复制两个密钥中的 1 个。Copy 1 of the two keys. 它是一个由 32 个字母数字组成的字符串(不包含空格或短划线),即 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxIt is a 32 alphanumeric-character string with no spaces or dashes, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.

将异常情况检测模块部署到 EdgeDeploy the Anomaly Detection module to the edge

  1. 在 Azure 门户的搜索栏中输入“IoT Edge 上的异常检测器”并打开 Azure 市场搜索结果。In the Azure portal, enter Anomaly Detector on IoT Edge into the search and open the Azure Marketplace result.

  2. 这会使你转到 Azure 门户的“IoT Edge 模块的目标设备”页It will take you to the Azure portal's Target Devices for IoT Edge Module page. 提供以下所需信息。Provide the following required information.

    1. 选择订阅。Select your subscription.

    2. 选择你的 IoT 中心。Select your IoT Hub.

    3. 选择“查找设备”,查找 IoT Edge 设备。Select Find device and find an IoT Edge device.

  3. 选择“创建”按钮。Select the Create button.

  4. 选择 AnomalyDetectoronIoTEdge 模块。Select the AnomalyDetectoronIoTEdge module.

    IoT Edge 模块用户界面的图像,其中包含以红色框突出显示的 AnomalyDetectoronIoTEdge 链接,指示这是要选择的项。

  5. 导航到“环境变量”并提供以下信息。Navigate to Environment Variables and provide the following information.

    1. 接受 Eula 的值。Keep the value accept for Eula.

    2. 使用认知服务终结点填写账单。Fill out Billing with your Cognitive Services endpoint.

    3. 使用认知服务 API 密钥填写 ApiKey。Fill out ApiKey with your Cognitive Services API key.

    环境变量,用红框突出显示了需要为终结点和 API 密钥填写值的区域

  6. 选择“更新”Select Update

  7. 选择“下一步: 路由”以定义路由。Select Next: Routes to define your route. 可将路由定义为所有模块中的全部消息均转到 Azure IoT 中心。You define all messages from all modules to go to Azure IoT Hub.

  8. 选择“下一步: 查看 + 创建”。Select Next: Review + create. 可预览定义部署到 IoT Edge 设备的所有模块的 JSON 文件。You can preview the JSON file that defines all the modules that get deployed to your IoT Edge device.

  9. 选择“创建”以开始模块部署。Select Create to start the module deployment.

  10. 完成模块部署后,返回到 IoT 中心的 IoT Edge 页面。After you complete module deployment, you'll go back to the IoT Edge page of your IoT hub. 从 IoT Edge 设备列表中选择设备,以查看其详细信息。Select your device from the list of IoT Edge devices to see its details.

  11. 向下滚动并查看列出的模块。Scroll down and see the modules listed. 检查新模块的运行时状态是否为“正在运行”。Check that the runtime status is running for your new module.

若要解决 IoT Edge 设备的运行时状态问题,请参阅故障排除指南To troubleshoot the runtime status of your IoT Edge device, consult the troubleshooting guide

在 IoT Edge 设备上测试异常检测器Test Anomaly Detector on an IoT Edge device

你将对运行 Azure 认知服务容器的 Azure IoT Edge 设备进行 HTTP 调用。You'll make an HTTP call to the Azure IoT Edge device that has the Azure Cognitive Services container running. 该容器提供了基于 REST 的终结点 API。The container provides REST-based endpoint APIs. 使用主机 http://<your-edge-device-ipaddress>:5000 以获得模块 API。Use the host, http://<your-edge-device-ipaddress>:5000, for module APIs.

如果边缘设备不允许端口 5000 上的入站通信,则需要创建新的入站端口规则。If your edge device does not already allow inbound communication on port 5000, you will need to create a new inbound port rule.

对于 Azure VM,可在“虚拟机” > “设置” > “网络” > “入站端口规则” > “添加入站端口规则”下进行设置 。For an Azure VM, this can set under Virtual Machine > Settings > Networking > Inbound port rule > Add inbound port rule.

有几种方法可用于验证模块是否正在运行。There are several ways to validate that the module is running. 找到相关边缘设备的外部 IP 地址和公开端口,并打开你常用的 Web 浏览器。Locate the External IP address and exposed port of the edge device in question, and open your favorite web browser. 使用以下各种请求 URL 验证容器是否正在运行。Use the various request URLs below to validate the container is running. 下面列出的示例请求 URL 是 http://<your-edge-device-ipaddress:5000,但是你的特定容器可能会有所不同。The example request URLs listed below are http://<your-edge-device-ipaddress:5000, but your specific container may vary. 请记住,需要使用边缘设备的外部 IP 地址。Keep in mind that you need to use your edge device's External IP address.

请求 URLRequest URL 目的Purpose
http://<your-edge-device-ipaddress>:5000/ 容器提供主页。The container provides a home page.
http://<your-edge-device-ipaddress>:5000/status 同样使用 GET 进行请求,这将验证用于启动容器的 api-key 是否有效,而不会导致终结点查询。Also requested with GET, this verifies if the api-key used to start the container is valid without causing an endpoint query. 此请求可用于 Kubernetes 运行情况和就绪情况探测This request can be used for Kubernetes liveness and readiness probes.
http://<your-edge-device-ipaddress>:5000/swagger 容器针对终结点及 试用 功能提供了一整套文档。The container provides a full set of documentation for the endpoints and a Try it out feature. 使用此功能可以将设置输入到基于 Web 的 HTML 表单并进行查询,而无需编写任何代码。With this feature, you can enter your settings into a web-based HTML form and make the query without having to write any code. 查询返回后,将提供示例 CURL 命令,用于演示所需的 HTTP 标头和正文格式。After the query returns, an example CURL command is provided to demonstrate the HTTP headers and body format that's required.

容器的主页

后续步骤Next steps