Monitoring Azure SQL with Log Analytics

By Tom Nonmacher

In today's data-driven world, monitoring your database server is crucial to ensure optimal performance and quick troubleshooting. For Azure SQL users, Microsoft has provided a powerful tool, Azure Log Analytics, which can be used to monitor, analyze, and optimize your databases. Whether you are using SQL Server 2019, MySQL 8.0, DB2 11.5, Azure SQL, or Azure Synapse, Azure Log Analytics can be an invaluable resource.

Azure Log Analytics is a service in Azure that helps you collect and analyze data generated by resources in your cloud and on-premises environments. It gives you real-time insights using integrated search and custom dashboards to readily analyze millions of records across all your workloads and servers. This post will guide you on how to monitor Azure SQL with Log Analytics.

To begin with, you need to create a Log Analytics Workspace if you do not have one already. The workspace provides a unique environment where Azure Monitor stores data. You can create one from the Azure portal. Once done, you need to enable diagnostics settings for your Azure SQL Database and direct it to send logs to the Log Analytics workspace.

You can use the following T-SQL code snippets to enable diagnostics settings for your Azure SQL Database:

SET SERVERPROPERTY ('EngineEdition') AS EngineEdition, 
SET SERVERPROPERTY ('ProductVersion') AS ProductVersion,
SET SERVERPROPERTY ('ProductLevel') AS ProductLevel,
SET SERVERPROPERTY ('Edition') AS Edition,
SET SERVERPROPERTY ('IsClustered') AS IsClustered,
SET SERVERPROPERTY ('HadrManagerStatus') AS HadrManagerStatus

Azure Log Analytics uses a query language known as Kusto Query Language (KQL) for data analysis. With KQL, you can easily retrieve, manipulate, and visualize data. Here's an example of a KQL query that retrieves the top five database names by average CPU percentage:

AzureMetrics
| where ResourceProvider == "MICROSOFT.SQL"
| where MetricName == "cpu_percent"
| summarize avg(CounterValue) by DatabaseName
| top 5 by avg_CounterValue desc

Azure Log Analytics is not just limited to Azure SQL. It can also be used to monitor SQL Server 2019, MySQL 8.0, and DB2 11.5. For instance, to monitor a MySQL 8.0 server, you can install the Log Analytics agent on your MySQL server, and then use KQL queries to analyze the collected data.

In conclusion, Azure Log Analytics provides an effective way to monitor Azure SQL along with other databases like SQL Server 2019, MySQL 8.0, and DB2 11.5. It provides real-time insights using integrated search and custom dashboards, making it easier to analyze and troubleshoot your database server. With the help of KQL, it offers an easy and flexible way to query your data.




16B213
Please enter the code from the image above in the box below.