Creating Dashboards with Azure Digital Twins, Azure Data Explorer, and Grafana
Published Apr 08 2022 08:00 AM 8,895 Views

This blog shows how to create dashboards to visualize the performance of the sample manufacturing operation presented in the blog Rewind the Metaverse with Data History for Azure Digital Twins. You can use these examples to build your own dashboards to analyze the behavior of environments that you model using Azure Digital Twins. 


To get started, complete the following prerequisites.

  • Gain access to a Grafana resource where you can create your dashboards. Azure Mangaged Grafana is a great place to start.
  • Complete the steps in the above-mentioned blog or in the article Use data history with Azure Data Explorer. Upon completion, you will have a working data history connection between Azure Digital Twins and Azure Data Explorer that enables you to perform historical analytics on a simulated dairy operation containing factories, people, and machines across multiple locations. Below is a visualization of the twin graph of the dairy operation created during the exercise.



Next, follow the below steps to create dashboards to visualize the performance of the dairy operation.


Connect Grafana to an Azure Data Explorer data source

The data history feature for Azure Digital Twins historizes twin changes to an Azure Data Explorer database. You can connect this database to Grafana by following the steps in Visualize data from Azure Data Explorer in Grafana (the video included in the guide is a great place to start). When installing the Azure Data Explorer plugin, make sure that the plugin is version 3.6.1 or higher.


Assign your app registration the Azure Digital Twins Data Reader role

In the above step, you will create an app registration. Assign this app registration the Azure Digital Twins Data Reader role on your Azure Digital Twins instance. This will enable the KQL queries run by the dashboards to query your Azure Digital Twins instance.


Start by viewing your Azure Digital Twins instance in the portal. Select Access Control (IAM) from the left navigation and select Add role assignment.





In the next screen, select the Azure Digital Twins Data Reader role, and select Next.




In the next screen, choose +Select members. Search for the name of your app registration and choose Select.




On the next screen, select Review + assign.


Import the Contoso Dairy dashboards into Grafana

Three dashboard JSON files are provided in this repo folder. Download the files. Import the Machine View by Factory, Maintenance Technician dashboard into Grafana as shown below.




In the import dialog, select the Azure Data Explorer data source you created earlier and enter values for your Azure Digital Twins endpoint and data history table name.  Complete this same process for the other dashboard JSON files.




Once a dashboard loads, you will see time series charts and gauges for machines in the dairy operation. You can make selections from the dropdown menus at the top to drill down on the machines of interest.




When you select an item from the menu, it triggers a query to the twin graph of the dairy operation that searches for twins based on twin name, twin type, relationships between twins, and other parameters. The result of the query is held in a Grafana variable. To view variables, click on the gear icon in the upper right-hand corner of a dashboard, then click on Variables in the left navigation panel.




The KQL queries for most variables dynamically assemble an Azure Digital Twins query via the strcat() KQL function. In many cases, the assembled Azure Digital Twins query references other Grafana variables from other menus. Grafana denotes variables in a query expression with a $. For example, the MaintTech variable is based on a query that searches for all twins that have an employs relationship with a factory twin, where the factory twin ID is defined by the Factory variable. The result of the query is held in the MaintTech Grafana variable.


You can also view the KQL queries that fetch data for a panel. Click on Edit to view the panel query.




In the editor, you can view the query for each tile that uses Grafana variables. These variables are driven by the menu queries discussed above.





In this walkthrough, you learned how to use Grafana to support visualization experiences for environments modeled in Azure Digital Twins. The relationships in the underlying twin graph of the dairy operation combined with time series data enable a variety of performance analytics. Example analytics include summing the output of machines that feed a common downstream machine, comparing the performance of similar machines in the same factory, or comparing machines in different factories.  Explore the query for each Grafana dashboard in this blog as well as additional queries here for more examples.

Version history
Last update:
‎Apr 22 2022 07:10 AM
Updated by: