Save a query to the dashboard

  1. Home
  2. Save a query to the dashboard

Go back to Tutorial

In this we will learn about Log Analytics interface with understand the query dashboard and log data schema including write and run simple queries, and modify the time range for queries. Further, we will also learn about filter, sort, and group query results, view, modify, and share visuals of query results.

Log Analytics is a tool in the Azure portal to edit and run log queries from data collected by Azure Monitor Logs and interactively analyze their results. Moreover, you can use Log Analytics queries to retrieve records matching particular criteria, identify trends, analyze patterns, and provide a variety of insights into your data.

Open Log Analytics

Open the Log Analytics demo environment or select Logs from the Azure Monitor menu in your subscription. This will set the initial scope to a Log Analytics workspace meaning that your query will select from all data in that workspace. If you select Logs from an Azure resource’s menu, the scope is set to only records from that resource.

Table schema

  • Firstly, the left side of the screen includes the Tables tab which allows you to inspect the tables that are available in the current scope. These are grouped by Solution by default, but you change their grouping or filter them.
  • Secondly, expand the Log Management solution and locate the AzureActivity table. You can expand the table to view its schema, or hover over its name to show additional information about it.
  • Lastly, click Learn more to go to the table reference that documents each table and its columns. Click Preview data to have a quick look at a few recent records in the table. This can be useful to ensure that this is the data that you’re expecting before you actually run a query with it.

Write a query

Let’s go ahead and write a query using the AzureActivity table. Double-click its name to add it to the query window. You can also type directly in the window and even get intellisense that will help complete the names of tables in the current scope and KQL commands. However, this is the simplest query that we can write. It just returns all the records in a table. Run it by clicking the Run button or by pressing Shift+Enter with the cursor positioned anywhere in the query text.

AZ-104  practice tests

Time range

  • Firstly, all tables in a Log Analytics workspace have a column called TimeGenerated which is the time that the record was created. And, all queries have a time range that limits the results to records with a TimeGenerated value within that range. The time range can either be set in the query or with the selector at the top of the screen.
  • However, by default, the query will return records form the last 24 hours. So, select the Time range dropdown and change it to 7 days. Then, click Run again to return the results.There, yYou can see that results are returned, but we have a message here that we’re not seeing all of the results. This is because Log Analytics can return a maximum of 10,000 records, and our query returned more records than that.

Work with charts

Let’s have a look at a query that uses numerical data that we can view in a chart. Instead of building a query, we’ll select an example query.

  • Firstly, click on Queries in the left pane. This pane includes example queries that you can add to the query window. However, if you’re using your own workspace, you should have a variety of queries in multiple categories. But if you’re using the demo environment, you may only see a single Log Analytics workspaces category. Expand that to view the queries in the category.
  • Secondly, cick on the query called Request Count by ResponseCode. This will add the query to the query window. Notice that the new query is separated from the other by a blank line. A query in KQL ends when it encounters a blank line, so these are seen as separate queries.
  • Thirdly, the current query is the one that the cursor is positioned on. You can see that the first query is highlighted indicating it’s the current query. Click anywhere in the new query to select it and then click the Run button to run it.
  • Lastly, notice that this output is a chart instead of a table like the last query. That’s because the example query uses a render command at the end. Notice that there are various options for working with the chart such as changing it to another type.

Log queries in Azure Monitor

Azure Monitor Logs is based on Azure Data Explorer, and log queries are written using the same Kusto query language (KQL). This is a rich language designed to be easy to read and author, so you should be able to start writing queries with some basic guidance.

Areas in Azure Monitor where you will use queries include the following:
  • Firstly, Log Analytics. Primary tool in the Azure portal for editing log queries and interactively analyzing their results.
  • Secondly, Log alert rules. Proactively identify issues from data in your workspace. Each alert rule is based on a log query that is automatically run at regular intervals.
  • Then, Workbooks. Include the results of log queries using different visualizations in interactive visual reports in the Azure portal.
  • Fourthly, Azure Dashboards. Pin the results of any query into an Azure dashboard which allow you to visualize log and metric data together and optionally share with other Azure users.
  • After that, Logic Apps. Use the results of a log query in an automated workflow using Logic Apps.
  • Next, PowerShell. Use the results of a log query in a PowerShell script from a command line or an Azure Automation runbook that uses Get-AzOperationalInsightsSearchResults.
  • Lastly, Azure Monitor Logs API. Retrieve log data from the workspace from any REST API client. The API request includes a query that is run against Azure Monitor to determine the data to retrieve.
Save a query to the dashboard AZ-104 online course

Reference: Microsoft Documentation

Go back to Tutorial

Menu