Count total number of messages per project?

Blazej Marciniak 0 Reputation points
2024-10-17T13:54:51.4533333+00:00

Hi All,

I'd like to understand time granularity used in IoT Hub metrics.

My use case is 5 projects running on the same IoT Hub and I need to calculate monthly usage of messages per project, and average daily for all projects. I've been using "Total number of messages used" metrics, exporting it to excel, summarize and divide by 30, to get total number of messages IoT Hub counted in that month and daily average.

I have noticed there is a significant (2, 3x) difference with time granularity set to "Automatic" and "1 day". I thought this is a data density setting, not affecting total numbers. Graph showing the metric daily doesn't mach my number either.

I'd appreciate someone explain the granularity diffidence and perhaps there's an easier way to calculate this?

Thanks!

Blazej

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,198 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sander van de Velde | MVP 32,811 Reputation points MVP
    2024-10-17T20:55:32.8633333+00:00

    Hello @Blazej Marciniak,

    welcome to this moderated Azure community forum.

    The IoT Hub counts the number of 'messages' per day because it offers a service sized on that number.

    If you want to know the number of 'messages' per devices, this is not a feature provided by the IoT Hub.

    You need to add extra logic listening to any of the messages coming from the IoT Hub.

    For example, Stream analytics is capable of counting the number of messages per time slot, per device (check out the tumbling window).

    Regarding the message count difference, did you know the IoT Hub does not actually count the number of incoming messages?

    What it counts is the number of chunks, the 4KB parts your incoming message is made of.

    An explination of how to measure the size, check out this documentation.

    If the incoming message has a size of 5KB, it is counted as two chunks.

    This could explain the difference.


    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.

    0 comments No comments

  2. LeelaRajeshSayana-MSFT 15,886 Reputation points Microsoft Employee
    2024-10-17T21:19:11.8266667+00:00

    Hi @Blazej Marciniak Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    The time granularity determines the number of data points that needs to be used by the chart for plotting. Consider the below scenario for example

    For time granularity = 30 minutes and the time range = 24 hours:

    • The chart is drawn from 48 datapoints. That is 24 hours x 2 datapoints per hour (60min/30min) aggregated
    • The line chart connects 48 dots in the chart plot area.
    • Depending on whether Aggregation is set to Max/Min/Avg, each datapoint represents the max/min/avg of all messages used during each of the relevant 30-min time periods.

    The default time granularity for the graph is 5 minutes and the aggregation is set to Max. If we change the value from default to 1 day, it greatly reduces the sample size for the graph plot and I would expect to see a change in the value rendered. Hope this clarifies your question on why the plot generated differs if the granularity is changed.

    perhaps there's an easier way to calculate this

    Unfortunately, there is no direct approach provided by IoT Hub that lets you monitor/track the message usage count per device/project level. It would only capture the metric at the IoT Hub level. You would have to do some sort of additional manipulation by routing the telemetry events to a different end point such as Event Hub or Stream Analytics job and capture in the property device-id in the message to perform additional analysis.


    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.


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.