监视 IoT Edge 部署Monitor IoT Edge deployments

Azure IoT Edge 提供报告,让你可以实时监视部署到 IoT Edge 设备上的模块的信息。Azure IoT Edge provides reporting that lets you monitor real-time information on the modules deployed to your IoT Edge devices. IoT 中心服务从设备检索状态,然后将这些状态提供给操作员。The IoT Hub service retrieves the status from the devices and makes them available to the operator. 监视对于大规模部署(包括自动部署和分层部署)也很重要。Monitoring is also important for deployments made at scale that include automatic deployments and layered deployments.

设备和模块都具有相似的数据(例如连接性),因此根据设备 ID 或模块 ID 获取值。Both devices and modules have similar data, such as connectivity, so values are obtained according to the device ID or the module ID.

IoT 中心服务收集设备和模块孪生报告的数据,并提供设备可能具有的各种状态的计数。The IoT Hub service collects data reported by device and module twins and provides counts of the various states that devices may have. IoT 中心服务将此数据组织成四组指标:The IoT Hub service organizes this data into four groups of metrics:

类型Type 说明Description
目标Targeted 显示与部署目标条件匹配的 IoT Edge 设备。Shows the IoT Edge devices that match the deployment targeting condition.
已应用Applied 显示的目标 IoT Edge 设备尚未成为另一优先级更高的部署的目标。Shows the targeted IoT Edge devices that are not targeted by another deployment of higher priority.
报告成功Reporting Success 显示已报告了成功部署模块的 IoT Edge 设备。Shows the IoT Edge devices that have reported that the modules have been deployed successfully.
报告失败Reporting Failure 显示已报告未成功部署一个或多个模块的 IoT Edge 设备。Shows the IoT Edge devices that have reported that one or more modules haven't been deployed successfully. 若要进一步调查此错误,请通过远程方式连接到这些设备并查看日志文件。To further investigate the error, connect remotely to those devices and view the log files.

IoT 中心服务使此数据可供你在 Azure 门户和 Azure CLI 中监视。The IoT Hub service makes this data available for you to monitor in the Azure portal and in the Azure CLI.

在 Azure 门户中监视部署Monitor a deployment in the Azure portal

若要查看部署的详细信息并监视运行它的设备,请执行以下步骤:To view the details of a deployment and monitor the devices running it, use the following steps:

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

  2. 从左窗格菜单中选择“IoT Edge”。Select IoT Edge from the left pane menu.

  3. 选择“IoT Edge 部署”选项卡。Select the IoT Edge deployments tab.

  4. 检查部署列表。Inspect the deployment list. 对于每个部署,可以查看以下详细信息: For each deployment, you can view the following details:

    Column 说明Description
    IDID 部署的名称。The name of the deployment.
    类型Type 部署的类型(“部署”或“分层部署”) 。The type of deployment, either Deployment or Layered Deployment.
    目标条件Target Condition 用于定义目标设备的标记。The tag used to define targeted devices.
    优先级Priority 分配给部署的优先级编号。The priority number assigned to the deployment.
    系统指标System metrics IoT 中心内与目标条件匹配的设备孪生数。The number of device twins in IoT Hub that match the targeting condition. “已应用”指定 IoT 中心内已将部署内容应用到其模块孪生的设备数。Applied specifies the number of devices that have had the deployment content applied to their module twins in IoT Hub.
    设备指标Device Metrics 从 IoT Edge 客户端运行时报告成功或错误的 IoT Edge 设备数。The number of IoT Edge devices reporting success or errors from the IoT Edge client runtime.
    自定义指标Custom Metrics IoT Edge 设备数,此类设备针对你为部署定义的任何指标报告数据。The number of IoT Edge devices reporting data for any metrics that you defined for the deployment.
    创建时间Creation Time 创建部署时的时间戳。The timestamp from when the deployment was created. 两个部署具有相同优先级,此时间戳用于消除它们的关系。This timestamp is used to break ties when two deployments have the same priority.
  5. 选择想要监视的部署。Select the deployment that you want to monitor.  

  6. 在“部署详细信息”页上,向下滚动到底部部分并选择“目标条件”选项卡。选择“查看”以列出符合目标条件的设备。On the Deployment Details page, scroll down to the bottom section and select the Target Condition tab. Select View to list the devices that match the target condition. 可以更改条件,也可以更改“优先级”。You can change the condition and also the Priority. 如果进行了更改,请选择“保存”。Select Save if you made changes.

    查看部署的目标设备

  7. 选择“指标”选项卡。如果从“选择指标”下拉列表中选择指标,则会出现“查看”按钮,用于显示结果。Select the Metrics tab. If you choose a metric from the Select Metric drop-down, a View button appears for you to display the results. 还可以选择“编辑指标”以调整已定义的任何自定义指标的条件。You can also select Edit Metrics to adjust the criteria for any custom metrics that you have defined. 如果进行了更改,请选择“保存”。Select Save if you made changes.

    查看某个部署的指标

若要更改部署,请参阅修改部署To make changes to your deployment, see Modify a deployment.

使用 Azure CLI 监视部署Monitor a deployment with Azure CLI

使用 az IoT Edge deployment show 命令显示单个部署的详细信息:Use the az IoT Edge deployment show command to display the details of a single deployment:

az iot edge deployment show --deployment-id [deployment id] --hub-name [hub name]

deployment show 命令采用以下参数:The deployment show command takes the following parameters:

  • --deployment-id - IoT 中心存在的部署的名称。--deployment-id - The name of the deployment that exists in the IoT hub. 必需参数。Required parameter.
  • --hub-name - 部署所在的 IoT 中心的名称。--hub-name - Name of the IoT hub in which the deployment exists. 此中心必须在当前订阅中。The hub must be in the current subscription. 使用 az account set -s [subscription name] 命令切换到所需订阅Switch to the desired subscription with the command az account set -s [subscription name]

在命令窗口中检查部署。Inspect the deployment in the command window. metrics 属性列出由每个中心评估的每个指标的计数: The metrics property lists a count for each metric that is evaluated by each hub:

  • targetedCount - 一个系统指标,根据目标条件指定 IoT 中心的设备孪生数。targetedCount - A system metric that specifies the number of device twins in IoT Hub that match the targeting condition.
  • appliedCount - 一个系统指标,指定已在 IoT 中心将部署内容应用到其模块孪生的设备数。appliedCount - A system metric specifies the number of devices that have had the deployment content applied to their module twins in IoT Hub.
  • reportedSuccessfulCount - 一个设备指标,用于指定通过 IoT Edge 客户端运行时报告成功的部署中的 IoT Edge 设备数。reportedSuccessfulCount - A device metric that specifies the number of IoT Edge devices in the deployment reporting success from the IoT Edge client runtime.
  • reportedFailedCount - 一个设备指标,指定已通过 IoT Edge 客户端运行时报告失败的部署中的 IoT Edge 设备数。reportedFailedCount - A device metric that specifies the number of IoT Edge devices in the deployment reporting failure from the IoT Edge client runtime.

可以使用 az IoT Edge deployment show-metric 命令显示每个指标的设备 ID 或对象的列表:You can show a list of device IDs or objects for each of the metrics with the az IoT Edge deployment show-metric command:

az iot edge deployment show-metric --deployment-id [deployment id] --metric-id [metric id] --hub-name [hub name]

deployment show-metric 命令采用以下参数:The deployment show-metric command takes the following parameters:

  • --deployment-id - IoT 中心存在的部署的名称。--deployment-id - The name of the deployment that exists in the IoT hub.
  • --metric-id - 需要查看设备 ID 列表时所对应指标的名称,例如 reportedFailedCount--metric-id - The name of the metric for which you want to see the list of device IDs, for example reportedFailedCount.
  • --hub-name - 部署所在的 IoT 中心的名称。--hub-name - Name of the IoT hub in which the deployment exists. 此中心必须在当前订阅中。The hub must be in the current subscription. 使用 az account set -s [subscription name] 命令切换到所需订阅。Switch to the desired subscription with the command az account set -s [subscription name].

若要更改部署,请参阅修改部署To make changes to your deployment, see Modify a deployment.

后续步骤Next steps

了解如何监视模块孪生(主要是 IoT Edge 代理和 IoT Edge 中心运行时模块),以监视 IoT Edge 部署的连接性和运行状况。Learn how to monitor module twins, primarily the IoT Edge Agent and IoT Edge Hub runtime modules, for the connectivity and health of your IoT Edge deployments.