CPU History in SQL Server 2008 R2

How to query last 2 months CPU history using T-SQL in SQL Server 2008 R2?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
Unless you've setup this monitoring previously then there is no way to query for items in the past
Pawan KumarDatabase ExpertCommented:
Do you have anything Monitioring setup already?
Please try this query if it helps-

declare @ts_now bigint 
select @ts_now = ms_ticks from
select record_id,dateadd (ms, (y.[timestamp] -@ts_now), CONVERT(varchar(10), DATEADD(day, -1, GETDATE()), 101)) as EventTime,
100 - SystemIdle - SQLProcessUtilization as OtherProcessUtilization
from (
record.value('(./Record/@id)[1]', 'int') as record_id,
record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int')
as SystemIdle,
'int') as SQLProcessUtilization,
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 

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
The counters are kept only from the last time SQL Server service restarted.
It's your SQL Server instance working the last 2 months with suffering a restart?
VijayAuthor Commented:
Good information.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.