Monitoring IoT Hub events, messages & metrics
How to monitor events, messages and metrics in IoT Hub
Table of Contents
How to use Azure IoT Explorer to monitor messagesEvents & Message in Azure CLIVideo of monitoring metrics & eventsMessages that are being sent to IoT Devices in Azure IoT Hub can be monitored. Monitoring messages arriving in IoT Hub is very useful when debugging and troubleshooting.
Messages can be monitored as general metrics but you can also monitor them on message level by using Azure CLI tool or by using Azure's own desktop client Azure IoT Explorer
How to use Azure IoT Explorer to monitor messages
Azure IoT Explorer is a handy tool delivered by Microsoft to help troubleshooting and monitoring messages being sent from edge devices and to Azure IoT Hub.
To get started with Azure IoT Explorer follow the below steps:
- Download and install Azure IoT explorer from Azures Github repository. Click here for full guide
- After installation an IoT Hub needs added. Go to IoT Hubs and click Add connection
- Enter the connection string of the IoT Hub owner. Find this in the Azure portal under Security settings, Shared access policies and then click on iothubowner policy. Copy paste one of the connection strings.
- In Azure IoT explorer you should see the added IoT Hub and all the devices
- Click on the desired device which you want to monitor the telemetry from or sending Cloud-to-devices to
- In the menu go to Telemetry and press start. Incoming messages will be present.
Events & Message in Azure CLI
To see the message details for all messages coming in you will have to use the Azure CLI.
For further information of Azure CLI on your desktop and the Azure Cloud Shell check these articles:
- Install the Azure CLI | Microsoft Docs
- Azure Cloud Shell overview | Microsoft Docs
- Monitoring Azure IoT Hub | Microsoft Docs
To monitor the events and messages do the following if you are using the Azure Cloud Shell:
Click the terminal icon in the portals upper right corner next to your username.
When the Cloud Shell is ready use one of the following command to monitor all messages arriving into the IoT Hub
az iot hub monitor-events --hub-name HubName az iot hub monitor-events --login "ConnectionString"
Or to monitor for a specific Device, which is very useful if you have many devices and are getting a lot of messages
az iot hub monitor-events --hub-name HubName --device-id DeviceID
To view more details of each message such as user defined and system properties use the following command
az iot hub monitor-events --hub-name HubName --device-id DeviceID --properties app sys az iot hub monitor-events --login "ConnectionString" --properties app sys
To get a full list of parameters and help use
az iot hub monitor-events -h
HubName and DeviceID can be located in IoT Hub ➡ IoT Devices
- HubName is your IoT Hub name
- DeviceID is the ID of the Device
- ConnectionString is the connection string of your IoT Hub or device. Learn how to find ConnectionString here
In Azure CLI the format of message event in to the device is as follows
{ "event": { "origin": "DeviceID", "module": "", "interface": "", "component": "", "payload": "MessagePayload" } }
and when monitoring with all the properties it looks as
{ "event": { "origin": "DeviceID", "module": "", "interface": "", "component": "", "properties": { "application": { "UserProperty1": "UserValue1", "UserProperty2": "UserValue2", .... } }, "payload": "MessagePayload" } }
where
- UserProperty & UserValue is the custom user properties and values added from SIA in the properties field
- MessagePayload is the payload being sent from SIA and being parsed to the IoT Hub
Metrics
In Azure IoT Hub you have metrics available for the given hub. This metrics can shows you information such as telemetry messages being sent.
Viewing the amount of telemetry messages sent to the IoT Hub is a really basic way of validating it works and cannot give you further information than data is coming in. Please keep in mind if you have multiple devices which are receiving data on the Hub this metrics might not be suitable to use as their telemetry messages will also appear.
- In Azure Portal go to IoT Hub and select the Hub where your IoT device belongs to
- In the left menu go to Monitoring ➡ Metrics
- Add new metric
- Metric: Telemtry messages sent
- Aggregation: Sum (you can use any of those available)
- Select a suitable time range in in the top right of the metric
- Analyze the metric and validate the data graph
Video of monitoring metrics & events
The following video shows you how to monitor metrics and events from Azure IoT Hub.