Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 CPU Utilization

Author  Topic 

rajam.venkatesh58
Starting Member

2 Posts

Posted - 2012-12-06 : 10:14:30
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

38200 Posts

Posted - 2012-12-06 : 13:37:27
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

596 Posts

Posted - 2012-12-07 : 10:51:16
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

38200 Posts

Posted - 2012-12-07 : 23:27:09
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

596 Posts

Posted - 2012-12-10 : 09:07:29
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

38200 Posts

Posted - 2012-12-10 : 14:53:02
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
   

- Advertisement -