本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
在 Amazon IoT Events (Amazon CLI) 中分析探测器模型
以编程方式分析 Amazon IoT Events 探测器模型,可提供有关其结构、行为和性能的宝贵见解。这种基于 API 的方法允许自动分析、与现有工作流程集成,并能够跨多个探测器模型执行批量操作。通过利用 StartDetectorModelAnalysisAPI,您可以启动对模型的深入检查,帮助您识别潜在问题,优化逻辑流程,并确保您的物联网事件处理符合您的业务需求。
以下步骤使用 Amazon CLI 来分析探测器模型。
要使用分析探测器模型 Amazon CLI
-
运行以下命令以启动分析。
aws iotevents start-detector-model-analysis --cli-input-json file://
file-name
.json注意
file-name
替换为包含探测器模型定义的文件名。例 探测器模型定义
{ "detectorModelDefinition": { "states": [ { "stateName": "TemperatureCheck", "onInput": { "events": [ { "eventName": "Temperature Received", "condition": "isNull($input.TemperatureInput.sensorData.temperature)==false", "actions": [ { "iotTopicPublish": { "mqttTopic": "IoTEvents/Output" } } ] } ], "transitionEvents": [] }, "onEnter": { "events": [ { "eventName": "Init", "condition": "true", "actions": [ { "setVariable": { "variableName": "temperatureChecked", "value": "0" } } ] } ] }, "onExit": { "events": [] } } ], "initialStateName": "TemperatureCheck" } }
如果您使用 Amazon CLI 来分析现有的探测器模型,请选择以下选项之一来检索探测器模型定义:
-
如果要使用 Amazon IoT Events 控制台,请执行以下操作:
-
在导航窗格中,选择探测器模型。
-
在探测器模型下,选择目标探测器模型。
-
从操作中选择导出探测器模型以下载探测器模型。此探测器模型以 JSON 格式保存。
-
打开探测器模型 JSON 文件。
-
您只需要
detectorModelDefinition
对象。移除以下内容:-
页面顶部的第一个大括号 (
{
) -
detectorModel
线 -
detectorModelConfiguration
对象 -
页面底部的最后一个大括号(
}
)
-
-
保存该文件。
-
-
如果要使用 Amazon CLI,请执行以下操作:
-
在终端中运行以下命令。
aws iotevents describe-detector-model --detector-model-name
detector-model-name
-
detector-model-name
替换为探测器型号的名称。 -
将
detectorModelDefinition
对象复制至文本编辑器。 -
在
detectorModelDefinition
外面添加大括号 ({}
)。 -
以 JSON 格式保存此文件。
-
例 响应示例
{ "analysisId": "c1133390-14e3-4204-9a66-31efd92a4fed" }
-
-
从输出项中复制分析 ID。
-
运行以下命令,以检索分析状态。
aws iotevents describe-detector-model-analysis --analysis-id "
analysis-id
"注意
analysis-id
替换为您复制的分析 ID。例 响应示例
{ "status": "COMPLETE" }
状态可以是以下值之一:
-
RUNNING
— Amazon IoT Events 正在分析您的探测器模型。完成此过程可能最多需要一分钟。 -
COMPLETE
— Amazon IoT Events 已完成对探测器模型的分析。 -
FAILED
— Amazon IoT Events 无法分析您的探测器模型。请稍后重试。
-
-
运行以下命令,以检索一个或多个探测器模型分析结果。
注意
analysis-id
替换为您复制的分析 ID。aws iotevents get-detector-model-analysis-results --analysis-id "
analysis-id
"例 响应示例
{ "analysisResults": [ { "type": "data-type", "level": "INFO", "message": "Inferred data types [Integer] for $variable.temperatureChecked", "locations": [] }, { "type": "referenced-resource", "level": "ERROR", "message": "Detector Model Definition contains reference to Input 'TemperatureInput' that does not exist.", "locations": [ { "path": "states[0].onInput.events[0]" } ] } ] }
注意
Amazon IoT Events 开始分析您的探测器模型后,您最多有 24 小时的时间来检索分析结果。