Metrics & Diagnostics for IoT Hub
Metrics & Diagnostics for IoT Hub

This course will focus on the skills needed to integrate Azure Monitor and its corresponding features within IoT solutions. Each service within a given IoT solution has the ability to produce metrics, logging, and alerting data. How are you going to gather all of that information and make it available to users that are managing and maintaining your solutions? This course will provide the answers to that question!

Learning Objectives

  • Understand the different metrics and diagnostics that can be retrieved from the Azure IoT Hub
  • Learn how to configure the IoT Hub for scaling programmatically
  • Learn how to query and visualize the data that is stored in Azure Monitor
  • Define specific Azure policies for your IoT Hub so that the hub meets your requirements
  • Learn how to gather metrics and diagnostics from IoT Edge

Intended Audience

  • Developers
  • Operational engineers
  • Cloud architects
  • Anyone responsible for deploying IoT solutions on Azure


To get the most out of this course, you should have a strong understanding of the available IoT services that Microsoft provides, as well as a strong understanding of Azure Monitor and the different types of data that can be retrieved through all of its features and services.


Hi there, in this video we're gonna be focusing on the metrics and diagnostics that are available for IoT Hub. How you can turn them on, how you can view them, and how you can then use them to provide troubleshooting data, provide queries and logging to determine how your IoT Hub is performing as well as even the devices that are connected to it. So the first thing to understand is metrics.

Now, if you'll remember from our intro video, this is where we talked about real time data that is collected with respect to your IoT Hub. Now your IoT Hub can be connected to many different devices, many different Azure services and therefore there are numerous different data points that can be collected and seen within the scope of the IoT Hub. These are some of those metrics. I do not have the time in this video to go into great description about each one of these. However, I'll show you in the portal not only how to turn them on, but also how to find out more information about each one. 

On the overview page of every IoT Hub, some metric data is collected for that Hub. These are all data points that you can add to a dashboard and use as part of your reporting. So you can see here we're seeing the number of messages used, devices to cloud messages, total IoT devices that are connected to the Hub, and so on. So with that, let's go into the portal and actually take a look at this.

Okay, here we are in the portal with a IoT Hub that I've created specifically for this course. As you can see it's called course-iot-hub, and this is what I'll be using for demonstration purposes. I am currently simulating a device that is connected to this IoT Hub so that we can actually see live metric data and just like I just showed you in the PowerPoint, here are those same metric points that we can see here for this particular IoT Hub. And I'm only showing over the last hour because the device has only been connected for about the last 20 minutes or so. If I do a quick refresh, we can start with number of messages used today, total message quota, the number of IoT devices.

Now, because this is a simulated device, it does not see that device as actually being there. We can then take a look at each individual metric point and see the numbers associated along the chart as we're scrolling. Where currently, we have a total number of 55 messages used, we have a total of 89 that have been sent and then the one connected device, the one IoT device, specifically the IoT Hub.

Now if we wanna look at data other than these four metric points, we go over to the navigation bar for our hub. We scroll down to the monitoring section, and this is where you'll see a metrics point. We can click on this from here, by the way you can get to this exact same location through Azure Monitor and get to metrics for multiple devices or multiple Azure services all at the same time, but by doing it here inside of the Hub, we're getting a focal point on this IoT Hub's set of metrics. Now, as I mentioned, there is a large number of metrics here. So we start out with the scope of this particular Hub, in some Azure services there are different types of metrics. There is only one type in the scope of IoT Hubs, so it's gonna be IoT Hub standard metrics and the next thing is to pick a metric.

Now I'm gonna scroll down here and go down to total number of messages used. And the minute that I scroll over it and put my mouse over top of it, you'll see a pop-up show that gives a little bit more information about this particular metric and what the data is that it is collecting. So if you want more detail about each of these metrics, this is one place to go. Another place to go is the URL that I'm providing at the end of the slide deck that actually takes you to the documentation page that lists every single metric that's available and gives you information about what each one of them actually does.

So, let's click on this one and it's gonna automatically select an aggregation of Max. Now you could just as easily set up average or min. And it's gonna give you those aggregations based off of the type of the data that's being collected, and we can change it at any time. You can see here that I've got the same number that we saw on the overview page of 101.

So it has been collecting this data. Now the chart itself doesn't look all that fantastic, and that's because the default view for Azure metrics is a 24-hour period, so therefore it's showing you the 101 messages that have been collected in the last 20 minutes but showing it over a much wider span. We can change that however by going up here to the top, clicking on the time and saying, you know what? I want the last hour. And click apply and now we have a little bit better view of the data that's been collected over that 20-minute span that I've been talking about here. Based on the list that we saw, there's a lot more data with respect to metrics, but I wanted to make sure that you understood how to turn these on. And then you can just as easily set up alert rules for these metrics. You can actually export these charts onto the Azure dashboard. There is a lot of things that you can do but all of that is really more closely tied to Azure Monitor and all of its capability rather than focusing on what is available within IoT Hub. For that information you can certainly get that in other courses here at Cloud Academy.

Now the next thing we wanna take a look at is Azure Diagnostics, so let me jump back over into the slide deck. Okay, with IoT Hub diagnostics, just like with Azure IoT Hub metrics, there is a large list of log types that can be collected. That log data is going to be aggregated into more than likely CSV files that you can then export out to a storage device of your choosing, and I'll show you how to set this up in a minute, that you can then use for log queries, whether it's in Azure Log Analytics or your own third-party log aggregation tool like a LogStash or Splunk. Again, this list is too long for me to go into very much detail, but I am gonna be providing you with a link at the end of the slide deck that will take you to documentation to let you know what each of these diagnostic logs does and what all of the data points are that they are collecting.

So, with that, let's go back into the portal and let's take a quick look at Azure Diagnostics with respect to the IoT Hub. Okay, here we are back at the overview page for our IoT Hub, and I wanted to start here as a central point for where to begin from, no matter what it is that you're gonna be doing from a monitoring and alerting perspective. We scroll back down to the monitoring area of our navigation section, and you'll see a diagnostic settings spot. Let's click on that. And the very first thing that you'll see is that same list of diagnostic logs that showed you in the PowerPoint deck, but you'll also notice that this clearly states, no diagnostic settings have been defined, meaning that Azure is not currently storing or collecting any log data with respect to your IoT Hub.

To do that, we click on add diagnostic setting. We then choose one of those logs that we just took a look at. So let's start with the one right up at the top of Connections. We can also collect all of the metric data here as well and have that be exported out into a log file. So if in fact you are using a third-party log aggregation engine like a Splunk or a LogStash or so on, then you may want to make sure that all of your metrics are exported out so that you can create your log queries in combination with, not only may be Azure Activity Log, IoT Hub diagnostic logs, but also the metrics as well. Once you've chosen the log, we need to give the diagnostic setting a name and then we need to specify where is this data is going to go.

So the destination details give us four different options. Now that doesn't mean that we only get to select one. We can actually select all four if we want to, but we can send them directly to Log Analytics if you happen to be using Azure Cloud native log aggregation engine. We can be sending all this to a Azure storage account. We can send all of the data to Event Hub, or we can send them to a partner solution.

Now in the partner solution option, you need to have something already defined in your Azure portal space that can accept Azure Monitor diagnostic logs and there is a supported list in the Azure documentation, so let's focus on the other three. Once you choose one of the other three, you then need to have a Log Analytics workspace, an Azure storage account or an Event Hub that will accept the diagnostics logs. And when you select each one, you'll obviously will choose one of those to actually export the data into. Now idea behind this is, for Log Analytics workspace to cloud native log aggregation engine you gonna be doing your querying and reporting directly from Log Analytics. However, if you're using a third-party tool like Splunk or LogStash, all of these third-party engines have some type of connector for Azure, either a storage account connector or an Event Hub connector. I can tell you from personal experience, Splunk uses Azure Event Hub, whereas a product like LogStash or SolarWinds both use Azure storage account. So therefore, you're gonna need to determine what makes the most sense for you for exporting out all these logs. And you know what? You may just wanna export them out for archival purposes, which means you're probably gonna be pushing them to a storage account. Once you have a good understanding of what each of these diagnostic logs produce, you can then make determinations as to what makes the most sense for you, and what data you need to be keeping track of, creating queries against, reports against, and so on. I'll see you in the next video.

About the Author

Brian has been working in the Cloud space for more than a decade as both a Cloud Architect and Cloud Engineer. He has experience building Application Development, Infrastructure, and AI-based architectures using many different OSS and Non-OSS based technologies. In addition to his work at Cloud Academy, he is always trying to educate customers about how to get started in the cloud with his many blogs and videos. He is currently working as a Lead Azure Engineer in the Public Sector space.