Skip to content

AzureIoTGBB/How-To-Monitor-Azure-IoT-Hub-with-Azure-CLI-2.0

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

How to monitor your Azure IoT Hub messages from Azure CLI


We have a lot of people who ask “How can I monitor the messages coming into the IoT Hub?” In truth, there are a lot of different ways to view the message traffic, and while one way is not better than others, some are simpler to configure. In this article we will be looking at how to setup Azure CLI to monitor the IoT Hub Message traffic.

The benefit of using Azure CLI is that it is a cross platform tool, meaning, that you can run on Windows, Mac, or Linux. The LI is designed to make scripting easy, query data, support long running operations and much more. While you can install the Azure CLI on several different operating systems, for the purpose of this article we will be installing it on Windows.

Install the Azure CLI 2.0


Getting started you will need to:

  • Download the MSI Package from here.
  • The instructions can be found here.
  • To install the Azure CLI for other operating systems click here.

After downloading the MSI Package run it:

image

image

Click Next

image

After it is finished the installation click on finish

image

Install the Azure IoT CLI Extension


Now that the Azure CLI tool is installed we need to extend it be able to use IoT CLI tools. To do this we will install the Azure IoT Extension for Azure CLI. This will provide the IoT commands and capabilities that are focused around the IoT Hub and Device Provisioning services.

To install the Azure IoT Extension for Azure CLI you will perform the following steps:

  • from the an elevated PowerShell prompt run the following:
    • az extension add --name azure-cli-iot-ext image

Monitor the IoT Hub for messages


Now that we have the CLI tools installed lets start monitoring message traffic

  • At a PowerShell prompt type
    • az login
      • Note this will log you into azure. The az login command will open a new web browser window and ask your to log into your Azure Subscription account.
        image

image

image

image

Next we need to generate a SAS token. We can do this by running this command in the Azure CLI window:

  • az iot hub generate-sas-token --duration -n

image

Now we have our SAS Token, we can start monitoring the hub messages by running the following command:

  • az iot hub monitor-events --hub-name

image

Conclusion


There are many different ways to monitor the IoT Hub. For example the above documentation will monitor all devices sending data into the IoT Hub, but if you wanted to select just one device, you could do that too...here is how:

  • az iot hub monitor-events --hub-name --device-id

And to get more help on the Azure CLI IoT Hub extension you can run this command:

  • az iot hub -h

We hope that this article helps you in monitoring your IoT Hub message traffic.

Happy monitoring your IoT Hub Messages with Azure CLI!!

About

How to use Azure CLI to monitor Azure IoT Hub

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published