SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 CPU Utilization
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rajam.venkatesh58
Starting Member

2 Posts

Posted - 12/06/2012 :  10:14:30  Show Profile  Reply with Quote
Hi all,

is there any query to know cpu utilization that are running in a specific database for last 24 hours for 1 hour interval in sqlserver 2008 and that query shouldn't be burden to database.

Please answer.Thanks in advance.

Regards,
Venkat.

tkizer
Almighty SQL Goddess

USA
37446 Posts

Posted - 12/06/2012 :  13:37:27  Show Profile  Visit tkizer's Homepage  Reply with Quote
No. CPU utilization can be seen at the instance level but you can only derive it for the database level. You can collect the CPU info via a trace and then correlate that back to what the instance was using.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

denis_the_thief
Aged Yak Warrior

Canada
594 Posts

Posted - 12/07/2012 :  10:51:16  Show Profile  Reply with Quote
This query can give insight into the historical CPU Utilization, but won't give any other detail:


DECLARE @ts_now bigint = (SELECT ms_ticks FROM sys.dm_os_sys_info); 

SELECT  SQLProcessUtilization AS [SQL Server Process CPU Utilization], 
               SystemIdle AS [System Idle Process], 
               100 - SystemIdle - SQLProcessUtilization AS [Other Process CPU Utilization], 
               DATEADD(ms, -1 * (@ts_now - [timestamp]), GETDATE()) AS [Event Time] 
FROM ( 
      SELECT record.value('(./Record/@id)[1]', 'int') AS record_id, 
            record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int') 
            AS [SystemIdle], 
            record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]', 
            'int') 
            AS [SQLProcessUtilization], [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 x 
      ) AS y 
ORDER BY record_id DESC;
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37446 Posts

Posted - 12/07/2012 :  23:27:09  Show Profile  Visit tkizer's Homepage  Reply with Quote
FYI: the above query will show the past 4 hours of CPU data. I log the data every minute as a result.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

denis_the_thief
Aged Yak Warrior

Canada
594 Posts

Posted - 12/10/2012 :  09:07:29  Show Profile  Reply with Quote
quote:
Originally posted by tkizer

I log the data every minute as a result.




Cool.

Is that a job that runs every minute and saves something similar to the above query in a Logging table? Do you also include anything about which query or in which Database the CPU usage is highest?
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37446 Posts

Posted - 12/10/2012 :  14:53:02  Show Profile  Visit tkizer's Homepage  Reply with Quote
It does use a query similar to what you posted. I actually presented my solution at a recent SQL Saturday here. My topic was Ring Buffers and had a special focus on CPU utilization.

I do have a separate job that records what queries were running but it only takes action when CPU hits a certain threshold. On the server where I have this setup, our threshold is 65%. I think I grab the top 10 queries using CPU and log it.

I'd be happy to share my presentation with you. It includes all of my SQL scripts, well it doesn't include the logging of the high CPU queries as I added that bit after the presentation. But I can send an updated file. PM me your email addy if you are interested. I eventually plan on blogging it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000