azure-iot-hubazure-cost-calculation

Can we find device-specific data ingress and storage cost on Azure IoT Hub?


I am looking for any suggestions to query the monitoring data for the Azure IoT Hub, in such a way that I can find out data ingress and storage cost per device connected to the IoT Hub. This will help us in creating a proper charging model for customers.

From the Azure documentation I can see that the costs are aggregate for the IoT Hub, also checked the event hubs documentation - it also doesn't give any more granularity in the telemetry messages, such that it can be bound to a particular device.

If someone has tried something like this or has any pointers related to the monitoring queries, please let me know.

Thanks in advance!


Solution

  • Azure IoT Hub does not provide an out of the box option to capture the telemetry data transferred per device yet. One of the ways to achieve what you are looking for is by creating a Device Twin property that captures the telemetry count on the device level. You can have the client/service SDK pushing data to the IoT Hub access this property every hour or so, based on your need, and update the telemetry count.

    Here is how you can update the telemetry data using javascript

        // Get the device twin for the device
    registry.getTwin('TestDevice4', function (err, twin) {
        if (err) {
            console.error('Failed to get device twin: ' + err.message);
            return;
        }
        // Get the telemetryCount property from the device twin
        var telemetryCount = twin.properties.desired.telemetryCount;
    
        // Update the telemetryCount property in the device twin
        twin.properties.desired.telemetryCount = telemetryCount + 1;
    
        // Update the device twin
        registry.updateTwin(twin.deviceId, twin, twin.etag, function (err) {
            if (err) {
                console.error('Failed to update device twin: ' + err.message);
                return;
            }
    
            console.log('Device twin updated successfully');
        });
    });
    

    You can see the telemetryPoperty gets updates on the Azure portal by inspecting the Device Twin of the device. Refer the below image for reference.

    enter image description here

    You can further reset the telemetryCount property to 0 at the end of the day/month per your needs and store the data to a blob end point.

    Please note that this telemetry data just gives you the idea on number of telemetry messages being pushed. The actual storage cost depends on the size of the telemetry data being pushed as well. Each message is capped at 4KB. Inspect the message size delivered and analyze accordingly.