How can we see what CPU Usage we had per minute in SQL Server

Latest posts by Stratos Matzouranis (see all)
- How to roll back an Oracle Database using a restore point in a Data Guard environment - 28 April 2025
- How can we increase performance on Oracle GoldenGate Replicat target with parallelism? - 19 March 2025
- How to create users in databases that belong to a SQL Server Always On Availability Group - 10 February 2025
SQL Server upon installation creates a lightweight Extended Event with a size of up to 5mb in which it records performance information. This Extended Event is called system_health and in this article we will see how we can with a simple query see what CPU Usage we had on the server per minute.
But we must not forget that the information is made rollover and overlap with new data. So the amount of time we can see in the past is not very long.
The code
All we need to do is to run the following code in a query window:
SELECT time,100-record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'INT') as 'Cpu Usage %' FROM ( SELECT CONVERT(xml, record) AS [record],dateadd (ms,timestamp - (select ms_ticks from sys.dm_os_sys_info),getdate()) as 'Time' FROM sys.dm_os_ring_buffers WHERE ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR' AND record LIKE '%<SystemHealth>%' order by time desc) AS x
The result that will return to us is the CPU Usage we had per minute:
