Monitoring Azure SQL Database CPU Usage

Sometimes there is a need to monitor Microsoft’s Azure SQL database usage, but your after the raw figures rather than an impressive looking graph.

Running the following SQL against the master database will give you the recent information:

DECLARE @DatabaseName nvarchar(50);
SET @DatabaseName = '*databasename*';

SELECT getdate() AS [Current Server Time];

SELECT start_time AS [Start of Period],
end_time AS [End of Period],
active_session_count AS [Sessions At End of Period],
avg_cpu_percent AS [Average CPU Usage %],
avg_physical_data_read_percent AS [Average Log Reads %],
avg_log_write_percent AS [Average Log Writes %]
FROM sys.resource_stats

WHERE start_time > DATEADD(minute, -240, GETDATE()) AND database_name = @DatabaseName
Order By start_time DESC;

Here’s an example of the results:
Azure SQL Database Processor Usage

Leave a Reply