Lesson 3 of 5 Azure Monitoring Tools

Collecting and Analysing Data with Azure Monitor and Log Analytics

This lesson explains Azure Monitor, the difference between metrics and logs, the activity log, and how Log Analytics queries log data with Kusto Query Language.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe what Azure Monitor collects and from where.
  • Distinguish metrics from logs.
  • Describe the purpose of Log Analytics and KQL.

What Azure Monitor is

Azure Monitor is a platform for collecting data on your resources, analysing that data, visualizing the information and even acting on the results. Azure Monitor can monitor Azure resources, your on-premises resources and even multicloud resources such as virtual machines hosted with a different cloud provider. Many Azure services send data to Azure Monitor automatically, and agents, such as the Azure Monitor Agent, collect data from inside virtual machines and servers.

The data Azure Monitor collects comes from several layers: the application (its performance and functionality), the guest operating system, each Azure resource, the subscription (operations recorded in the activity log) and the tenant (Microsoft Entra ID activity). Azure Monitor then provides tools to analyse and act on it: insights, visualizations such as dashboards and workbooks, alerts and automated responses.

Select all that apply

What Azure Monitor can collect

Exam skills 3.4.3

Identify the sources and layers Azure Monitor collects data from.

Log in to try this activity Interactive activities are free with an account.

Metrics and logs

Azure Monitor stores two fundamental types of data. The following comparison shows how they differ.

Metrics
What they areNumerical values collected at regular intervals
ExamplesCPU percentage, available memory, requests per second
Stored inA time-series database
Best forNear real-time charts and fast alerting
Logs
What they areRecords of events and traces, with different kinds of data in each record
ExamplesError messages, sign-in events, activity log entries, application traces
Stored inLog Analytics workspaces
Best forDetailed analysis and correlation with queries

The activity log is a special log that records subscription-level events, such as who created, modified or deleted a resource and when, which helps with auditing. Platform metrics are collected automatically for most resources; logs from inside resources are sent to a workspace by configuring diagnostic settings or data collection rules.

The following diagram shows the two types of data and what each is used for.

Metrics and logs in Azure Monitor. Metrics are numerical values collected at regular intervals, such as CPU percentage, stored in a time-series database and suited to near real-time charts and fast alerts. Logs are records of events and traces, such as errors and sign-ins, stored in Log Analytics workspaces and analysed with queries. Platform metrics are collected automatically; logs from inside resources need diagnostic settings or data collection rules.
Metrics for fast alerts; logs for detailed analysis.
Sort into groups

Metric or log?

Exam skills 3.4.3

Decide whether each piece of data is a metric or a log.

Log in to try this activity Interactive activities are free with an account.

Log Analytics

Log Analytics is a tool in the Azure portal where you write and run log queries on the data gathered by Azure Monitor, stored in Log Analytics workspaces. Queries are written in Kusto Query Language (KQL), a read-only language designed for searching large volumes of data. Log Analytics supports both simple and complex queries and data analysis: you can write a simple query that returns a set of records and then use features of Log Analytics to sort, filter and analyse them, or write an advanced query to perform statistical analysis and visualize the results in a chart to identify a particular trend.

For example, the following KQL query counts the Azure resource operations recorded in the activity log over the last day, grouped by operation.

AzureActivity
| where TimeGenerated > ago(1d)
| summarize count() by OperationNameValue
| order by count_ desc

Query results can be pinned to dashboards, used in workbooks, or used as the basis of log alert rules.

Worked example

Investigating a change

A virtual machine was deleted over the weekend, and the operations manager wants to know who deleted it and when. The team also wants to analyse error events from several servers together over the past month to find a pattern. Which Azure Monitor features should they use?

The activity log records subscription-level operations, including who deleted the VM and when. To analyse error events from several servers over a month, the servers' logs should be collected into a Log Analytics workspace and analysed with KQL queries in Log Analytics, which can filter, aggregate and chart them. Metrics would show numerical performance values but not the detailed error records.

Check yourself

Which query language does Log Analytics use?

Show answer

Kusto Query Language (KQL).

Exam Tips

Remember for the exam

  • Azure Monitor collects, analyses and acts on telemetry from Azure, on-premises and other clouds.
  • Metrics are numerical time series; logs are event records stored in Log Analytics workspaces.
  • Log Analytics runs Kusto Query Language (KQL) queries on log data.
  • The activity log records who did what to resources and when.