Get CPU Utilization Data from SQL Server
SQL Server is built on top of the Windows operating system and shares many of the same components with other Windows-based applications. This means that SQL Server is subject to the same potential performance issues as any other Windows application. In this article, we’ll take a look at how to get CPU utilization data from SQL Server so that you can identify and troubleshoot any performance issues.
There are a few different ways to get CPU utilization data from SQL Server. The most direct way is to use the Windows Performance Monitor tool. This tool can be used to collect a variety of performance data from a variety of sources, including SQL Server. To use the Performance Monitor tool, you’ll need to first add the “SQL Server:Buffer Manager” counters. These counters will give you information about the amount of work that SQL Server is doing to manage its buffers.
Another way to get CPU utilization data from SQL Server is through the use of the sp_monitor system stored procedure. This procedure can be used to collect a variety of performance data, including CPU utilization data. To use this procedure, you’ll need to first enable the trace flag T1118. This trace flag will cause the sp_monitor procedure to output its data to the SQL Server error log.
Once you’ve enabled the trace flag, you can run the sp_monitor procedure as follows:
This will output a variety of performance data to the error log, including CPU utilization data. You can then use this data to troubleshoot any performance issues that you may be experiencing.
Another way to get CPU utilization data from SQL Server is by using the belwo script. Benjamin Nevarez described in his blog on how to “Get CPU Utilization Data from SQL Server” and he inspired me to repost the information. Unfortunately this webpage is not accessible currently.
Author: Benjamin Nevarez
DECLARE @ts_now BIGINT;
SELECT @ts_now = cpu_ticks / CONVERT(FLOAT, cpu_ticks)
, Dateadd(ms, -1 * ( @ts_now - [timestamp])
, Getdate()) AS EventTime
, 100 - systemidle - sqlprocessutilization AS OtherProcessUtilization
FROM (SELECT record.value('(./Record/@id)', 'int') AS record_id
, record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)', 'int') AS SystemIdle
, record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)', 'int') AS SQLProcessUtilization
FROM (SELECT timestamp
, CONVERT(XML, record) AS record
WHERE ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
AND record LIKE '%<SystemHealth>%') AS x) AS y
ORDER BY record_id DESC;
In conclusion, getting CPU utilization data from SQL Server is a important task for any DBA. There are various ways to collect this data, and the method you choose will depend on your specific needs. However, all methods have one thing in common: they require you to have a solid understanding of SQL Server internals.