question

DavidMaelfait-1602 avatar image
0 Votes"
DavidMaelfait-1602 asked ·

Is there a way to retrieve the total message count for a specific device?

We want to be able to programmatically disable a device in case it sends too many messages (unexpected behaviour).

For this to work, we need a way to measure the amount of messages that has been sent from the device (too be more specific, from an iot edge device) to the iothub and vice versa within a certain time frame.

All I could find is a way to retrieve the total message count for all connected devices.


azure-iot-hub
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SandervandeVelde42 avatar image
1 Vote"
SandervandeVelde42 answered ·

@DavidMaelfait-1602 ,

The metrics on the IoT Hub only report on a meta-level about the health, usages, etc. of the IoT Hub, not for individual devices.

To get a count per device per time interval, you have to add the logic yourself.

This is not that hard with custom logic in eg. Azure Stream Analytics or an Azure Function.

Still, there are costs involved for these extra services just to handle a 'copy' of the message so a counter can be incremented or a group by on an ASA window can be executed.

So, if you are able to combine it with existing logic which is picking up the messages already, you can save some resources...

· 4 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SandervandeVelde42,

Thanks for your quick response,

We were indeed thinking to keep a counter ourselves, updated by an (already existing) Azure function. However, as we want to count ALL D2C messages (incl. twin reported updates), we need to configure different message routings (one for D2C messages and one for twin property updates) to our function and then update a 'persistent counter' for each message. This solution seems a little bit cumbersome, not to name the extra cost as you also mention.

We also noticed that there already exists a cloudToDeviceMessageCount property on the device twin. A deviceToCloudMessageCount would have been nice. Maybe a nice feature for a future release...


0 Votes 0 ·

Hello @DavidMaelfait-1602 ,

this would make a nice addition.

You can make a suggestion in https://feedback.azure.com/forums/34192--general-feedback

The same is valid for Azure IoT Edge modules. These modules also expose only a C2D message count.

If you add the link here we can all upvote this.

0 Votes 0 ·

Hello @SandervandeVelde42,

I posted the suggestion at Cloud to device messagecount for iot (edge) devices

Thanks again for your feedback!


1 Vote 1 ·
Show more comments