Blog Post

SQL Server Blog
1 MIN READ

SQL Server CPU usage available in sys.dm_os_ring_buffers DMV starting SQL Server 2019 RC on Linux

Tejas Shah's avatar
Tejas Shah
Icon for Microsoft rankMicrosoft
Aug 27, 2019

Sys.dm_os_ring_buffers DMV has been a key DMV used for monitoring SQL Server by built-in tools as well as third party monitoring utilities. When SQL Server 2017 was released on Linux, unfortunately this DMV did not return correct CPU usage information by SQL Server process. SQL Server team is glad to announce that the starting with SQL Server 2019 release candidate, the sys.dm_os_ring_buffers DMV returns SQL CPU utilization correctly. This improvement should benefit the SQL Server monitoring ecosystem on Linux by providing a way to monitor SQL Server CPU usage and enable decision making to engage corrective action if required.

 

Sample Query:

select top 10

    id, SQLServerCPUUtilization, 100 - SystemIdle - SQLServerCPUUtilization as NonSQLCPUUtilization

-- SystemIdle on Linux will be 0

from (

select

        record.value('(./Record/@id)[1]', 'int') as id,

        record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int') as SystemIdle,

        record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]', 'int') as SQLServerCPUUtilization,

        timestamp

    from (

select timestamp, convert(xml, record) as record

        from sys.dm_os_ring_buffers

        where ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'

            and record like '%<SystemHealth>%') as RingBufferInfo

) AS TabularInfo

order by id desc

 

Sample Results:

id          SQLServerCPUUtilization NonSQLCPUUtilization

----------- ----------------------- --------------------

112         14                      86

111         13                      87

110         14                      86

109         15                      85

108         15                      85

107         15                      85

106         3                       97

105         9                       91

104         3                       97

103         0                       100

 

(10 rows affected)

 

 

Completion time: 2019-08-27T22:35:52.4202651+05:30

 

And same information in graphical manner using Azure Data Studio.

 

Updated Sep 04, 2019
Version 2.0

3 Comments

  • jeff_yao's avatar
    jeff_yao
    Copper Contributor

    I believe the most accurate monitoring is from OS level performance counter. In my case, I use Counter Instance "\Porcess(_total)\% Processor Time" for the whole CPU while instance "\Porcess(sqlservr)\% Processor Time" for sql server process

  • chadbaldwin's avatar
    chadbaldwin
    Copper Contributor

    So I'm just here to +1 the other comment. This view does not seem to report accurate CPU usage. I realize it is some sort of aggregate/average over the course of a minute...but it still does not report accurate values.

    For non-hypervisor instances, it seems to report ProcessUtilization values WELL above their actual CPU % when viewing it directly in Task Manager (or similar). For example, we have one instance that will show ProcessUtilization values as high as 300+.

    I've spent hours trying to figure out if maybe for non-hypervisors this value is multiplied by the number of NUMA nodes, memory nodes, sockets, etc....but nothing has proven to be accurate.

    On top of that, the SystemIdle value does not appear to be accurate either. For example, I ran a query which steadily held the instance CPU at 45% and System Idle at 55% (when viewing Task Manager). It held this reading for 5+ minutes without deviating. Which means the averages should also be 45/55.

    However, sys.dm_os_ring_buffers reported a ProcessUtilization value of 180 and a SystemIdle of 50.

    And yes...this is still true even for SQL Server 2022 (running on Windows Server, not Linux). Could someone please look into this? I'm not necessarily asking for it to be "fixed" , but maybe at the very least, provide a formula/method for normalizing that value back to being 100 based.

    This is obviously an ongoing issue based on the number of feature suggestions that have been submitted specifically mentioning this issue...

    https://feedback.azure.com/d365community/idea/5e7f7457-8125-ec11-b6e6-000d3a4f0da0
    https://feedback.azure.com/d365community/idea/6b113656-5d25-ec11-b6e6-000d3a4f0da0
    https://feedback.azure.com/d365community/idea/8d09dfb3-4a25-ec11-b6e6-000d3a4f0da0
    https://feedback.azure.com/d365community/idea/8e09dfb3-4a25-ec11-b6e6-000d3a4f0da0
    https://feedback.azure.com/d365community/idea/9320f59a-4a25-ec11-b6e6-000d3a4f0da0
    https://feedback.azure.com/d365community/idea/cefc64f0-8125-ec11-b6e6-000d3a4f0da0
    https://feedback.azure.com/d365community/idea/f7db3568-6f25-ec11-b6e6-000d3a4f0da0
    https://feedback.azure.com/d365community/idea/fe0aaeb8-5025-ec11-b6e6-000d3a4f0da0

  • Pankaj_Mittal's avatar
    Pankaj_Mittal
    Copper Contributor

    Hi Tejas Shah : We utilize this DMV to monitor SQL Server CPU utilization and fire alerts based on certain thresholds across thousands of SQL Server in our environment. We have noticed that the numbers do not align on a Windows machine as they do on a Linux machine. For example, in many cases the SQLServerCPUUtilization + NonSQLCPUUtilization >100%. Sometimes, SQLServerCPUUtilization alone exceeds 100%. Wondering if "ProcessUtilization" column in this DMV represents absolute or relative % of CPU utilization by SQL Server. An example of what we are seeing is below