Get CPU, DataIO And Memory Usage In Azure SQL Through A Query

Introduction 

 
If you are the owner of any Azure SQL Database, you must be using the Matrics section of the same in the Azure portal for checking the DTU, CPU, memory percentages continuously. But if you don't have the access to the Azure portal, you might not be able to check this. 
 
Using the below query, you can directly get these numbers from the SQL server itself:
 
Code
  1. CREATE SCHEMA [SystemMonitor] -- Create if not present   
  2.    
  3. CREATE PROC [SystemMonitor].[GetDBStatus]  
  4. @interval INT    
  5. AS    
  6. BEGIN    
  7.     
  8.     DECLARE @edition varchar(50),     
  9.             @serviceObjective varchar(50)    
  10.          
  11.     SELECT     
  12.         @edition = slo.edition,    
  13.         @serviceObjective  =slo.service_objective    
  14.     FROM sys.databases d       
  15.     JOIN sys.database_service_objectives slo        
  16.     ON d.database_id = slo.database_id    
  17.     
  18.     SELECT        
  19.         AVG(avg_cpu_percent) AS 'AverageCPUPercent',       
  20.         MAX(avg_cpu_percent) AS 'MaximumCPUPercent',       
  21.         AVG(avg_data_io_percent) AS 'AverageDataIOPercent',       
  22.         MAX(avg_data_io_percent) AS 'MaximumDataIOPercent',       
  23.         AVG(avg_memory_usage_percent) AS 'AverageMemoryPercent',       
  24.         MAX(avg_memory_usage_percent) AS 'MaximumMemoryPercent',    
  25.         MAX(end_time) AS 'StartDatetime',    
  26.         MIN(end_time) AS 'EndDatetime',    
  27.         @edition AS 'Edition',    
  28.         @serviceObjective 'ServiceObjective'    
  29.     FROM sys.dm_db_resource_stats    
  30.     WHERE end_time < GETDATE()    
  31.         AND end_time >= DATEADD(minute, (-1 * @interval), getdate())  -- Set the interval as per your requirement to check    
  32. END    
Result
 
Get CPU, DataIO And Memory Usages In Azure SQL Through Query
 
Now if you want to change the pricing tier from the SQL server portal, check the below link. 
 
 
Enjoy!