【问题标题】:How to get the running status of IOT Edge Modules via Azure REST API? (not the connectionState or status from the 'Get Modules on Device' API Call)如何通过 Azure REST API 获取 IOT Edge Modules 的运行状态? (不是来自“获取设备上的模块”API 调用的 connectionState 或状态)
【发布时间】:2020-09-10 19:27:25
【问题描述】:

上下文:

Azure REST - Modules - Get Modules On Device

通过使用此 API 调用,我可以获得有关模块的连接状态(连接/断开)和状态(启用/禁用)的信息。我们可以通过访问 Azure IoT Hub 门户网站检查设备上部署的模块的运行时状态 portal.azure.com -> iot hub -> iot edge section -> select the device you wish to find the details for

问题: 我怎样才能通过 Azure API 获得这个RUNTIME STATUS?(请参考图片)。

【问题讨论】:

    标签: azure azure-iot-hub azure-iot-edge


    【解决方案1】:

    如果您检查 edgeAgent 的模块孪生,如下所示:-

    {
      "deviceId": "edgeDevice",
      "moduleId": "$edgeAgent",
      "etag": "AAAAAAAAAEA=",
      "deviceEtag": "NDU1OTY3MjA=",
      "status": "enabled",
      "statusUpdateTime": "0001-01-01T00:00:00Z",
      "connectionState": "Disconnected",
      "lastActivityTime": "0001-01-01T00:00:00Z",
      "cloudToDeviceMessageCount": 0,
      "authenticationType": "sas",
      "x509Thumbprint": {
        "primaryThumbprint": null,
        "secondaryThumbprint": null
      },
      "version": 501,
      "properties": {
        "desired": {
          "schemaVersion": "1.0",
          "runtime": {
            "type": "docker",
            "settings": {
              "minDockerVersion": "v1.25",
              "loggingOptions": "",
              "registryCredentials": {
              }
            }
          },
          "systemModules": {
            "edgeAgent": {
              "type": "docker",
              "settings": {
                "image": "mcr.microsoft.com/azureiotedge-agent:1.0",
                "createOptions": "{}"
              }
            },
            "edgeHub": {
              "type": "docker",
              "status": "running",
              "restartPolicy": "always",
              "settings": {
                "image": "mcr.microsoft.com/azureiotedge-hub:1.0",
                "createOptions": "{\"HostConfig\":{\"PortBindings\":{\"5671/tcp\":[{\"HostPort\":\"5671\"}],\"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}]}}}"
              }
            }
          },
          "modules": {
            "CustomModuleName": {
              "version": "1.0",
              "type": "docker",
              "status": "running",
              "restartPolicy": "always",
              "settings": {
                "image": "iotregdev300.azurecr.io/customModuleName:0.0.2-amd64",
                "createOptions": "{\"HostConfig\":{\"PortBindings\":{\"8080/tcp\":[{\"HostPort\":\"8080\"}]}}}"
              }
            }
          }
        },
        "reported": {
          "schemaVersion": "1.0",
          "version": {
            "version": "1.0.9.4",
            "build": "32971639",
            "commit": "12d55e582cc7ce95c8abfe11eddfbbc938ed6001"
          },
          "lastDesiredStatus": {
            "code": 200,
            "description": ""
          },
          "runtime": {
            "platform": {
              "os": "linux",
              "architecture": "x86_64",
              "version": "1.0.9.4"
            },
            "type": "docker",
            "settings": {
              "minDockerVersion": "v1.25",
              "loggingOptions": "",
              "registryCredentials": {
              }
            }
          },
          "systemModules": {
            "edgeAgent": {
              "type": "docker",
              "exitCode": 0,
              "statusDescription": "running",
              "lastStartTimeUtc": "2020-09-09T07:34:34.4585643Z",
              "lastExitTimeUtc": "2020-09-09T07:34:26.9869915Z",
              "runtimeStatus": "running",
              "imagePullPolicy": "on-create",
              "settings": {
                "image": "mcr.microsoft.com/azureiotedge-agent:1.0",
                "imageHash": "sha256:1a2fffc3c74a2b2510a3149bb2295b68a553e4c9aca90698879902f36fd6d163",
                "createOptions": "{}"
              }
            },
            "edgeHub": {
              "type": "docker",
              "status": "running",
              "restartPolicy": "always",
              "imagePullPolicy": "on-create",
              "env": {},
              "exitCode": 0,
              "statusDescription": "running",
              "lastStartTimeUtc": "2020-09-09T07:34:50.8012461Z",
              "lastExitTimeUtc": "2020-09-09T07:34:26.9845717Z",
              "restartCount": 0,
              "lastRestartTimeUtc": "2020-09-09T07:34:26.9845717Z",
              "runtimeStatus": "running",
              "settings": {
                "image": "mcr.microsoft.com/azureiotedge-hub:1.0",
                "imageHash": "sha256:f531eb6c23f347c37ea8c90204e9cb12024aec77d8b2e68e93b14c38ec066520",
                "createOptions": "{\"HostConfig\":{\"PortBindings\":{\"5671/tcp\":[{\"HostPort\":\"5671\"}],\"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}]}}}"
              }
            }
          },
          "lastDesiredVersion": 64,
          "modules": {
            "CustomModuleName": {
              "exitCode": 0,
              "statusDescription": "running",
              "lastStartTimeUtc": "2020-09-09T07:34:49.3923079Z",
              "lastExitTimeUtc": "2020-09-09T07:34:26.9606688Z",
              "restartCount": 0,
              "lastRestartTimeUtc": "2020-09-09T07:34:26.9606688Z",
              "runtimeStatus": "running",
              "version": "1.0",
              "status": "running",
              "restartPolicy": "always",
              "imagePullPolicy": "on-create",
              "type": "docker",
              "settings": {
                "image": "iotregdev300.azurecr.io/custommodulename:0.0.2-amd64",
                "imageHash": "sha256:e728d4b8804d2114beab7c1903f706d8152e404be3f5601ee5e7371e8ac32ecf",
                "createOptions": "{\"HostConfig\":{\"PortBindings\":{\"8080/tcp\":[{\"HostPort\":\"8080\"}]}}}"
              },
              "env": {}
            }
          }
        }
      }
    }
    

    在上面的 json 中,CustomModuleName 是自定义模块,它有一个名为 runtimeStatus: "running" 的字段。 edgeHub 和 edgeAgent 模块中也存在相同的字段。因此,您只需通过 REST API 或 Azure Device/Service sdk 获取 edgeAgentTwin。

    【讨论】:

    • 感谢您的回答。在我发布问题后,我最终还是登陆了 DeviceTwins。
    • 你可以投票并接受答案,以便对某人有所帮助。
    • 我在写上一条评论的同时已经这样做了
    猜你喜欢
    • 2019-03-09
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 2015-08-15
    • 1970-01-01
    相关资源
    最近更新 更多