Add visualizations to compare and analyze the data

Completed

In this exercise, we're going to take things one step further. Instead of just having visualizations that show data from some data sources, we're going to add visuals that combine data from these sources to let you correlate the data and analyze your system.

We're going to create graphs to show the requests, CPU time, and request unit consumption in the web app and the Cosmos DB. The graph uses combined metrics from the web application and the database.

We're going to combine data using Log Analytics queries that get data from these sources:

  • the Web app
  • the Cosmos DB
  • the Log Analytics workspace

Then we'll add a metric that monitors the application.

Generate some data for this exercise

  1. Sign into the Azure portal.

  2. On the Home page, select Resource groups, or search for "Resource groups" in the search bar at the top of the page.

  3. Select the "learn" resource group created when the sandbox was activated.

  4. Look through the list of resources and select the App Service.

    Screenshot of selecting the App Service from the resource group.

  5. On the top toolbar, select Browse.

    Screenshot of the browser button from the App Service page.

  6. Populate the app service with some activities to generate some data for our example. On the List of To-Do Items page, create some items, edit them, or mark some as complete.

    Screenshot that shows tasks for the app service for workbooks learn module.

Add graphs to compare the volume of requests

We're going to generate two graphs to place side by side to compare the number of requests sent to the web app and to the Cosmos DB.

In your workbook, select Edit from the top toolbar.

  1. Select Add, and then select Add parameters.

  2. Select Add parameter to add a new parameter.

    1. In the Parameter name field, enter WebApps.

    2. In the Parameter type field, select Resource picker.

    3. Select the Required checkbox.

    4. In the Get data from section, select Query.

    5. In the Subscriptions Log query section:

      1. In the Data source field, select Azure resource graph.

      2. In the Resource type field, select Subscription.

      3. In the Subscriptions field, select the Subscription resource parameter.

      4. Enter the following query, and then select Run Query.

        resources 
        | where type == "microsoft.web/sites" 
        | project id
        

      Screenshot that shows the web app parameter in a workbook.

    6. Select Save.

  3. In the same Add parameter section, select Add parameter again.

    Screenshot that shows adding a second parameter to an existing parameter control in Azure workbooks.

    1. In the Parameter name field, enter CosmosDB.

    2. In the Parameter type field, select Resource picker.

    3. Select the Required checkbox.

    4. In the Get data from section, select Query.

    5. In the Subscriptions Log query section:

      1. In the Data source field, select Azure resource graph.

      2. In the Resource type field, select Subscription.

      3. In the Subscriptions field, select the Subscription resource parameter.

      4. Enter the following query, and then select Run Query.

        resources 
        | where type == "microsoft.documentdb/databaseaccounts" 
        | project id
        
    6. Select Save.

  4. In the same Add parameter section, select Add parameter again.

    1. In the Parameter name field, enter LogAnalytics.

    2. In the Parameter type field, select Resource picker.

    3. Select the Required checkbox.

    4. In the Get data from section, select Query.

    5. In the Subscriptions Log query section:

      1. In the Data source field, select Azure resource graph.

      2. In the Resource type field, select Subscription.

      3. In the Subscriptions field, select the Subscription resource parameter.

      4. Enter the following query, and then select Run Query.

        resources 
        | where type == "microsoft.operationalinsights/workspaces"
        | project id
        
    6. Select Save.

  5. In the same Add parameter section, select Add parameter again.

    1. In the Parameter name field, enter TimeRange.
    2. In the Parameter type field, select Time range picker.
    3. Select the Required checkbox.
    4. In the Available time ranges field, make sure all the values are selected.
    5. Select Save.
  6. Select Done editing. Your workbook now has a parameter control with four parameters. When you select the first parameter, the list in each consecutive drop down is populated based on your selection.

    Screenshot that shows multiple parameters in one control in Azure workbooks.

  7. Select Edit next to the parameter control we just added, and then select Add and Add metric.

  8. Enter these settings for the metric:

    1. In the Resource Type field, select App Service.

    2. In the App Service field, select the WebApp parameter.

    3. In the Time Range field, select the TimeRange parameter.

      Screenshot that shows the metric settings for a web app in Azure Workbooks.

  9. Select Add metric, and enter these settings:

    1. In the Namespace field, select App Service standard metrics.

    2. In the Metrics field, select Requests.

    3. In the Aggregation field, select Count.

    4. Select Save.

      Screenshot that shows the metric settings for the number of requests made to a web app in Azure Workbooks.

  10. To make sure that the graphs display side by side, select Style on the top of the window, and then select the Make this item a custom width checkbox. Make sure that the Percent width is set to 50%.

  11. Select Advanced settings, and enter a name for the chart in the Chart title field, such as "Web app number of requests".

  12. Select Done editing. You now have a graph displaying the number of requests sent to your web app.

    Screenshot that shows one graph in an Azure Workbook.

  13. Select Add and Add metric.

  14. Enter these settings for the metric:

    1. In the Resource Type field, select Azure Cosmos DB account.
    2. In the App Service field, select the CosmosDB parameter.
    3. In the Time Range field, select the TimeRange parameter.
  15. Select Add metric, and enter these settings:

    1. In the Namespace field, select Azure Cosmos DB account standard metrics.
    2. In the Metrics field, select Total Requests.
    3. In the Aggregation field, select Count.
    4. Select Save.
  16. To make sure that the graphs display side by side, select Style on the top of the window, and then select the Make this item a custom width checkbox. Make sure that the Percent width is set to 50%.

  17. Select Advanced settings, and enter a name for the chart in the Chart title field, such as "Cosmos DB total requests".

  18. Select Done editing. You now have two side by side graphs displaying the number of requests sent to your web app and your database.

    Screenshot that shows two graphs in an Azure Workbook.

Add graphs to compare the volume of operations

We're going to use Log Analytics queries to generate two graphs that we'll place side by side to compare the number and types of requests sent to the web app and to the Cosmos DB.

In your workbook, select Edit from the top toolbar.

  1. Add a query for the number of requests per operation. Select Add, and then select Add query.

    1. In the Data source field, select Logs.

    2. In the Resource type field, select Log Analytics.

    3. In the Log Analytics workspace field, select the Log Analytics parameter.

    4. In the Time Range field, select the TimeRange parameter.

    5. Enter this Log query:

        AppRequests
      | summarize RequestsCount=sum(ItemCount) by OperationName, _ResourceId
      | order by RequestsCount desc
      

      Screenshot that shows a query for the number of requests to a web app in an Azure Workbooks.

  2. Now, we're going to use the rendering settings to make the chart easy to understand visually. Select Column settings, and then in the Columns section on the left, select Operation Name, and then enter these settings.

    1. In the Column name field, enter (or leave the default name) "OperationName".

    2. In the Column renderer field, select Thresholds.

    3. In the Thresholds section, select Colors, and then add these thresholds:

      Operator Value Color Text
      contains Create Orange {0}{1}
      contains Delete Red (Bright) {0}{1}
      contains Edit Blue (Light) {0}{1}
      Default Green {0}{1}

      Screenshot that shows setting the colors in a grid in Azure Workbooks.

  3. In the Columns section on the left, select _ResourceId, and then in the Column renderer field, select Hidden.

  4. In the Columns section on the left, select ResourceCount, and then enter these settings:

    1. In the Column name field, enter (or leave the default name) "RequestCount".
    2. In the Column renderer field, select Bar.
    3. In the Color palette section, select Blue.**
    4. Select Save and Close.
  5. To make sure that the graphs display side by side, select Style on the top of the window, and then select the Make this item a custom width checkbox. Make sure that the Percent width is set to 50%.

  6. Select Advanced settings, and enter a name for the chart in the Chart title field, such as "Web App Operations".

  7. Select Done editing. Your workbook now has a color-coded graph showing the types of operations sent to your web app and the number of each type of request.

    Screenshot that shows a bar chart with the number of requests per operation for a web app.

  8. Now we're going to add a visualization for the number of requests for the Cosmos DB.

  9. Select Edit next to the parameter control we just added, and then select Add and Add metric.

  10. Enter these settings for the metric:

    1. In the Resource Type field, select Azure Cosmos DB account.
    2. In the App Service field, select the CosmosDB parameter.
    3. In the Time Range field, select the TimeRange parameter.
    4. In the Visualization field, select Grid.
  11. Select Add metric, and enter these settings:

    1. In the Namespace field, select Azure Cosmos DB account standard metrics.

    2. In the Metrics field, select Total Requests.

    3. In the Aggregation field, select Count.

    4. In the Split field, select None.

    5. Select Save.

      Screenshot that shows a query for the number of requests to a database in an Azure Workbook.

  12. Add another metric. Select Add and Add metric, and enter these settings:

    1. In the Namespace field, select Azure Cosmos DB account standard metrics.

    2. In the Metrics field, select Total Requests.

    3. In the Aggregation field, select Count.

    4. In the Split by field, select OperationType.

    5. In the Sort by field, select Descending.

    6. In the Number of splits field, select 5.

    7. In the Display Name field, enter "Operations".

    8. Select Save.

      Screenshot that shows a query with results split into columns in an Azure Workbook.

  13. We're going to use the rendering settings to make the chart easy to understand visually.

  14. Select Column settings, and then in the Columns section on the left, select microsoft.documentsdb/databaseaccounts-Requests-TotalRequests, and then enter these settings.

    1. In the Column renderer field, select Heatmap.

    2. In the Color palette field, select Blue.

    3. Select Custom formatting.

      1. In the Units field, select Count.
      2. In the Style field, select Decimal.

      Screenshot that shows setting the colors in a grid using the heatmap setting in Azure Workbooks.

  15. In the Columns section on the left, select microsoft.documentsdb/databaseaccounts-Requests-TotalRequests Timeline (Hidden), and then enter these settings:

    1. In the Column Label field, enter (or leave the default name) "Total Requests (Count)".
    2. In the Column renderer field, select Heatmap.
    3. In the Color palette field, select Blue.
  16. In the Columns section on the left, select */Operations$ (Text), and then enter these settings:

    1. In the Column Label field, enter (or leave the default name) "Total Requests (Count)".
    2. In the Column renderer field, select Heatmap.
    3. In the Color palette field, select Blue.
    4. Select Custom formatting.
      1. In the Units field, select Count.
      2. In the Style field, select Decimal.
    5. Select Save and Close.
  17. To make sure that the graphs display side by side, select Style on the top of the window, and then select the Make this item a custom width checkbox. Make sure that the Percent width is set to 50%.

  18. Select Advanced settings, and enter a name for the chart in the Chart title field, such as "Cosmos DB Operations".

  19. Select Done editing. Your workbook now has two color coded graphs showing the numbers and types of requests sent to your web app and your Cosmos DB.

    Screenshot that shows two side by side grids in Azure Workbooks.