Edit

Connect Azure Managed Grafana to the OPC UA reference solution

You can use Azure Managed Grafana to create a dashboard on Azure for the OPC UA reference solution. Use Grafana in manufacturing to create dashboards that display real-time data. This article shows how to enable Grafana on Azure and create a dashboard with simulated production line data from Azure Data Explorer.

Architecture

The following diagram illustrates the OPC UA solution. It shows Azure Managed Grafana querying Azure Data Explorer for industrial IoT analytics dashboards.

Architecture diagram of the reference solution that shows Azure Managed Grafana querying Azure Data Explorer for industrial IoT analytics dashboards.

Download a PowerPoint file of this architecture.

Enable the Azure Managed Grafana service

Create an Azure Managed Grafana instance and configure it with permissions to access the ontologies database:

  1. In the Azure portal, search for Grafana, and then select the Azure Managed Grafana service.

  2. On the Azure Managed Grafana page, select Create.

  3. On the Create Grafana Workspace page, enter a name for your instance. Use the default values for the other options.

  4. Select Review + create. After validation passes, select Create.

  5. After the service is created, make sure your Azure Managed Grafana instance has a system-assigned managed identity. In the Azure portal, go to the page for your Azure Managed Grafana instance. Go to Settings > Identity. If the system-assigned managed identity isn't enabled, enable it. Note the Object (principal) ID value. You'll need it later.

  6. To grant permission for the managed identity to access the ontologies database in Azure Data Explorer:

    1. Go to your Azure Data Explorer instance in the Azure portal.
    2. Under Overview > Permissions, select Add > Viewer.
    3. Search for and select the Object (principal) ID value that you noted earlier.

Add a new data source in Grafana

Add a new data source to connect to Azure Data Explorer. For this solution, use a system-assigned managed identity to connect to Azure Data Explorer.

To add the data source in Grafana, follow these steps:

  1. Go to the endpoint URL for your Grafana instance. You can find the endpoint URL on the Azure Managed Grafana page for your instance in the Azure portal.
  2. Sign in to your Grafana instance.
  3. In the Grafana dashboard, select Connections > Data sources, and then select Add new data source. Scroll down and select Azure Data Explorer Datasource.
  4. Choose Managed Identity as the authentication method.
  5. Add the URL of your Azure Data Explorer cluster. You can find the URL on the Overview page of your Azure Data Explorer instance in the Azure portal under URI.
  6. Select Save & test to verify the datasource connection.

Import a sample dashboard

Now you're ready to import the sample dashboard.

  1. Download the Sample Grafana Manufacturing Dashboard.
  2. In the left pane of Grafana, go to Dashboards and then select New > Import.
  3. Select Upload dashboard JSON file, and then select the samplegrafanadashboard.json file that you downloaded earlier. Select Import.
  4. On the menu on the OEE Station tile, select Edit, and then select the Azure Data Explorer data source that you set up earlier.
  5. Select KQL in the Queries pane and add the following query: print round (CalculateOEEForStation('${Station}', '${Location}', '${CycleTime}', '${__from:date:iso}', '${__to:date:iso}') * 100, 2). Select Apply to apply your changes and go back to the dashboard.
  6. On the menu on the OEE Line tile, select Edit, and then select the Azure Data Explorer data source that you set up earlier.
  7. Select KQL in the Queries pane and add the following query: print round(CalculateOEEForLine('${Location}', '${CycleTime}', '${__from:date:iso}', '${__to:date:iso}') * 100, 2). Select Apply to apply your changes and go back to the dashboard.
  8. On the menu on the Discarded products tile, select Edit, and then select the Azure Data Explorer data source that you set up earlier.
  9. Select KQL in the Queries pane and add the following query: opcua_metadata_lkv | where DataSetName contains '${Station}' | where DataSetName contains '${Location}' | join kind=inner (opcua_telemetry | where Name == "NumberOfDiscardedProducts" | where Timestamp > todatetime('${__from:date:iso}') and Timestamp < todatetime('${__to:date:iso}')) on Subject | extend numProd = toint(Value) | summarize max(numProd). Select Apply to apply your changes and go back to the dashboard.
  10. On the menu on the Manufactured products tile, select Edit, and then select the Azure Data Explorer data source that you set up earlier.
  11. Select KQL in the Queries pane and add the following query: opcua_metadata_lkv | where DataSetName contains '${Station}' | where DataSetName contains '${Location}' | join kind=inner (opcua_telemetry | where Name == "NumberOfManufacturedProducts" | where Timestamp > todatetime('${__from:date:iso}') and Timestamp < todatetime('${__to:date:iso}')) on Subject | extend numProd = toint(Value) | summarize max(numProd). Select Apply to apply your changes and go back to the dashboard.
  12. On the menu on the Energy Consumption tile, select Edit, and then select the Azure Data Explorer data source that you set up earlier.
  13. Select KQL in the Queries pane and add the following query: opcua_metadata_lkv | where DataSetName contains '${Station}' | where DataSetName contains '${Location}' | join kind=inner (opcua_telemetry | where Name == "EnergyConsumption" | where Timestamp > todatetime('${__from:date:iso}') and Timestamp < todatetime('${__to:date:iso}')) on Subject | extend NodeValue = todouble(Value) | project Timestamp1, NodeValue. Select Apply to apply your changes and go back to the dashboard.
  14. On the menu on the Pressure tile, select Edit, and then select the Azure Data Explorer data source that you set up earlier.
  15. Select KQL in the Queries pane and add the following query: opcua_metadata_lkv| where DataSetName contains '${Station}'| where DataSetName contains '${Location}'| join kind=inner (opcua_telemetry | where Name == "Pressure" | where Timestamp > todatetime('${__from:date:iso}') and Timestamp < todatetime('${__to:date:iso}')) on Subject | extend NodeValue = toint(Value)| project Timestamp1, NodeValue. Select Apply to apply your changes and go back to the dashboard.

Configure alerts

In Grafana, you can also create alerts. In this example, you create a low OEE alert for one of the production lines.

  1. In the left pane of Grafana, go to Alerting > Alert rules.

  2. Select New alert rule.

  3. Enter a name for your alert, and select Azure Data Explorer as the data source. Under Define query and alert condition, select KQL.

  4. In the query field, enter the following query. This example uses the Seattle production line:

    let oee = CalculateOEEForStation("assembly", "seattle", 10000, now(-1h), now());
    print round(oee * 100, 2)
    
  5. Select Set as alert condition.

  6. Scroll down to the Expressions section. Delete the Reduce expression.

  7. For the alert threshold, select A as Input. Select IS BELOW and enter 10.

  8. Scroll down to the Set evaluation behavior section. Create a new Folder to save your alerts. Create a new Evaluation group and specify 2m.

  9. Select Save rule and exit in the upper right corner.

In the overview of your alerts, you can now see that an alert is triggered when your OEE is less than 10.

Next steps