forked from DavidWiseman/sqlserver-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPU_Utilization.sql
27 lines (23 loc) · 1.06 KB
/
CPU_Utilization.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
Author: Benjamin Nevarez
Original link: http://sqlblog.com/blogs/ben_nevarez/archive/2009/07/26/getting-cpu-utilization-data-from-sql-server.aspx
*/
DECLARE @ts_now BIGINT;
SELECT @ts_now = cpu_ticks / CONVERT(FLOAT, cpu_ticks)
FROM sys.dm_os_sys_info;
SELECT 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
WHERE ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
AND record LIKE '%<SystemHealth>%') AS x) AS y
ORDER BY record_id DESC;