SQL CHECK

 /*check current cpu*/
declare @ts_now bigint
select @ts_now = cpu_ticks / convert(float, cpu_ticks_in_ms)
from sys.dm_os_sys_info with(nolock)
select top 1 record_id,
dateadd(ms, -1 * (@ts_now - [timestamp]), GetDate()) as EventTime,
SQLProcessUtilization,
SystemIdle,
100 - SystemIdle - SQLProcessUtilization as OtherProcessUtilization
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   with(nolock)
where ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
and record like '%<SystemHealth>%') as x
) as y
order by record_id desc

/*check current top 5 cpu query*/
select top 5                                   
top_current_cpu=r.cpu_time                                   
,r.total_elapsed_time                                   
,r.logical_reads                                   
,r.session_id                                   
,s.login_name                                   
,s.[host_name]                                   
,s.status                                   
,r.command                                     
,dbname=db_name(r.database_id)                                   
,s.[program_name]                                   
,running_query_text= (select top 1 [text]
from master.sys.dm_exec_sql_text(r.sql_handle) )                                 
,s.login_time                                              
from master.sys.dm_exec_requests r  with(nolock)                                   
inner join master.sys.dm_exec_sessions s with(nolock)                                   
on r.session_id = s.session_id                                     
where r.session_id>50  
and  r.session_id<>@@spid                                                 
order by r.cpu_time desc     
,r.session_id  desc     
,r.total_elapsed_time desc 

/*check top 5 avg cpu*/
select top 5
total_worker_time/execution_count as top_cpu
,total_elapsed_time
,execution_count
,query_text= (select top 1 [text]
from master.sys.dm_exec_sql_text(qs.sql_handle) )
from sys.dm_exec_query_stats as qs with(nolock)
where qs.last_execution_time>=dateadd(mi,-30,getdate())
order by
total_worker_time/execution_count desc
,total_elapsed_time desc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值