Issue in accessing the metrics of edge device through HTTP protocol

Athira Gopinath(UST,IN) 141 Reputation points
2023-08-08T12:42:30.3133333+00:00

Hi,

As part of our research and devlopment ,We have tried to access the metrics,edgehub_messages_received_total and edgehub_messages_sent_total of IoT Edge Device through HTTP protocol. But it is throwing an 404 error .I am hereby sharing the python code snippet for the same.Please suggest some solution to resolve this issue.

import requests

 

# Replace these values with your actual module and device IDs, and the correct access token

module_id = "IoTEdgeMetricsCollector"  

device_id = "CRA0002"  

access_token = <"connectionstring">

 

 

# Get the module metrics

#url = "https://hostname/devices/CRA0002/messages/modules/IoTEdgeMetricsCollector/outputs/metricOutput?api-version=2018-06-30"

#url = "https://hostname/devices/{}/modules/{}/metrics".format(device_id, module_id)

 

url = "https://hostname/api/v2/devices/CRA0002/metrics?modules=IoTEdgeMetricsCollector&api-version=2018-04-01"

print(url)

headers = {"Authorization":"Bearer "+ access_token,

           "Content-Type": "application/json" }

response = requests.get(url, headers=headers, verify=False)

print(response)

 

# Check if the request was successful

if response.status_code == 200:

    print("success......")

    data = response.json()

    data_sent = data["metrics"]["edgehub_messages_sent_total"]

    data_received = data["metrics"]["edgehub_messages_received_total"]

    print("Number of messages sent:", data_sent)

    print("Number of messages received:", data_received)

else:

    print("Failed to retrieve metrics. Status Code:", response.status_code)
Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
598 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,258 questions
{count} votes

Accepted answer
  1. Sander van de Velde | MVP 36,131 Reputation points MVP
    2023-08-08T13:05:56.7366667+00:00

    Hello @Athira Gopinath(UST,IN),

    the Metricscollector module collects metrics from both OS and module and routes (eg. via edgeAgent and edgeHub) and can send these to the cloud (LogAnalytics). The IoT Hub then offers a dashboard with the actual state.

    It seems you try to access the routing output of the metricscollector edge module which is normally managed by the edgeHub.

    The traffic over the routes is secured.

    I have not seen this approach yet.

    Can you share with us the documentation of what you are trying to achieve?

    Meanwhile, there are two other solutions which give more success, I expect:

    1. write a customer module yourself, having an input and listening to the metrics collector messages sent over that output. From there you are in control of what to do with it
    2. Skip the Metricscollector and listen directly to the built-in metrics endpoints.

    Let us know if this helps you with your research.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.