IoT Hub Direct Method "GetModuleLogs" causes high IoT Hub Message use

Steffen 71 Reputation points
2023-10-27T17:26:21.3533333+00:00

Hello

I tried to receive the logs of an IoT Edge Device with a TimerTrigger Azure Function that uses the DirectMethod "GetModuleLogs" to get the logs of two Edge Modules. Because the log messages are sometimes quite big, I need to call the "GetModuleLogs" Method multiple times (for example 20 Times an hour). I am using this method:

registry_manager = IoTHubRegistryManager(host = IOT_HUB_HOSTNAME, token_credential = credential)
device_method = CloudToDeviceMethod(method_name="GetModuleLogs", payload=method_payload, response_timeout_in_seconds=TIMEOUT)
response = registry_manager.invoke_device_module_method(DEVICE_ID, EDGE_MODULE_ID, device_method)

I noticed that I got a huge spike in IoT Messages on my IoT Hub: I am talking 1000 messages an hour. I am not sending any telemetry data to the IoT Hub so I am pretty sure that the IoT Messages are caused by the Azure Function calling the "GetModuleLogs" Method.

I could not find any documentation about how the DirectMethod uses the messages. Am I doing something wrong or does the "GetModuleLogs" Method just uses multiple IoT Messages when transmitting the logs?

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.
543 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sander van de Velde 29,196 Reputation points MVP
    2023-10-27T20:01:00.8566667+00:00

    Hello @Steffen,

    So you ask most recent logs of modules and you see a spike in message consumption.

    This is by design.

    Bot D2C and C2D communication are charged as being part of the daily message consumption:

    Successful method requests are charged in 4-KB chunks, and responses are charged in 4-KB chunks as additional messages. Requests or responses with no payload are charged as one message. For example, a method with a 4-KB body that results in a response with no payload from the device is charged as two messages. A method with a 6-KB body that results in a 1-KB response from the device is charged as two messages for the request plus another message for the response. Requests to disconnected devices are charged as messages in 4-KB chunks plus one message for a response that indicates the device isn't online.

    So, the requests and response messages are counted per 4Kb (chunks).

    So, do you really want to download the complete module logs, day in, and day out?

    In production, we see other patterns to check module execution. If these modules are custom modules, you built yourself, why not send a daily message with some summary of requests a summary of that module using a direct method?


    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.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 13,471 Reputation points
    2023-10-27T20:18:10.4966667+00:00

    Hi @Steffen Greetings! Thank you for posting the question here.

    A similar issue has been addressed in the past on one of the threads. Here is the link to the question - Azure IOT Hub: messages send when device is doing nothing. The reason for this behavior as outlined in the solution is because twin reads and updating of reported properties on the Edge device modules are also factored into the IoT Hub messages count you see. You can modify the Edge device environment variables MinTwinSyncPeriodSecs and ReportedPropertiesSyncFrequencySecs to adjust the frequency of this messages. Note that the message count is also impacted by the size of the twin.

    Please refer the link Environment Variables to get more understanding on different default settings on various settings.

    Hope this helps. Please let us know if you have any further questions on this.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    0 comments No comments