I would like to know how much data a device has sent in a period of time to IoT Hub.
Currently I have following base query:
AzureDiagnostics
| where TimeGenerated between (datetime("2022-10-01") .. datetime('2022-11-08'))
| extend DeviceId = extractjson("$.deviceId", properties_s)
| extend MessageSize = toint(extractjson("$.messageSize", properties_s))
| where DeviceId == "deviceId"
which returns me log entries for a device. The logs that have a message size properties, are those of type D2CTwinOperations
with operation name update
or read
.
Complete query which sums the message sizes looks like this:
AzureDiagnostics
| where TimeGenerated between (datetime("2022-10-01") .. datetime('2022-11-08'))
| extend DeviceId = extractjson("$.deviceId", properties_s)
| extend MessageSize = toint(extractjson("$.messageSize", properties_s))
| where DeviceId == "deviceId"
| where MessageSize > 0
| summarize totalSizeInBytes = sum(MessageSize) by bin(TimeGenerated, 1d)
| extend totalSizeInKiloBytes = totalSizeInBytes/1024
| order by TimeGenerated asc
What with the D2C messages that are not twin operations, i.e. device is sending an message/event that is not a device twin update. Can I query for those somehow? And do they have message size associated with it?
2
Answers
There are different category options available in Diagnostic Settings section of the Azure IoT Hub that lets you log different category of messages in the AzureDiagnostics logs. Please find the below image displaying different options available.
I am not sure if the other logs generated from the D2C message/event has the property message size in it. But you can see different category logs get generated and filter some set of logs that suit your need.
You can also enable "AllMetrics" option on the Diagnostic setting page to
generate a lot of Azure platform generated metrics to monitor your Azure IoT Hub.
Please refer to the resource Monitoring Azure IoT Hub data to find different metrics provided to you by out of the box functionality. Here are some of the daily quota metrics available to you by enabling this setting.
Kindly note that while the metrics provides you the cumulative data transferred to Azure IoT Hub by all the connected devices, there is no current metric to let you know data transferred per IoT device.
A work around for a similar question has been posted on the following thread — Azure IoTHub – How to get usage data per device
Here is the solution shared on the thread
To query for D2C messages that are not twin operations, you can modify the query to include only messages with a specific event type. For example, you can use the following query to get the total size of all D2C messages sent by a device:
This query will only include messages with the event type "Microsoft.Devices.Message", which are D2C messages sent by the device. The message size is associated with these messages and can be queried using the MessageSize field.
Note that the MessageSize field may not be present in all D2C messages, so you may need to modify the query to handle cases where the field is not present.
You can also use the EventType field to filter for other types of messages, such as device twin updates or device telemetry messages.