Skip to content

Commit eee4ce3

Browse files
committed
[FEATURE] Add CPU Utilization from Benjamin Nevarez
1 parent f86c8b9 commit eee4ce3

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

Scripts/CPU_Utilization.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Author: Benjamin Nevarez
3+
Original link: http://sqlblog.com/blogs/ben_nevarez/archive/2009/07/26/getting-cpu-utilization-data-from-sql-server.aspx
4+
*/
5+
6+
7+
DECLARE @ts_now BIGINT;
8+
9+
SELECT @ts_now = cpu_ticks / CONVERT(FLOAT, cpu_ticks)
10+
FROM sys.dm_os_sys_info;
11+
12+
SELECT record_id
13+
, Dateadd(ms, -1 * ( @ts_now - [timestamp])
14+
, Getdate()) AS EventTime
15+
, sqlprocessutilization
16+
, systemidle
17+
, 100 - systemidle - sqlprocessutilization AS OtherProcessUtilization
18+
FROM (SELECT record.value('(./Record/@id)[1]', 'int') AS record_id
19+
, record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int') AS SystemIdle
20+
, record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]', 'int') AS SQLProcessUtilization
21+
, timestamp
22+
FROM (SELECT timestamp
23+
, CONVERT(XML, record) AS record
24+
FROM sys.dm_os_ring_buffers
25+
WHERE ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR'
26+
AND record LIKE '%<SystemHealth>%') AS x) AS y
27+
ORDER BY record_id DESC;

Scripts/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ Tested on SQL Server version: 2008/2012/2014/2016
4646
## [CPU Utilization Graphical form](CPU_Utilization_Graphical_form.sql)
4747
Author: Slava Murygin<br/>
4848
Original link: http://slavasql.blogspot.ru/2016/03/sql-server-cpu-utilization-in-graphical.html<br/>
49-
Tested on SQL Server version: 2008/2012/2014/2016
49+
Tested on SQL Server version: 2012/2014
50+
51+
52+
## [CPU Utilization](CPU_Utilization.sql)
53+
Author: Benjamin Nevarez<br/>
54+
Original link: http://sqlblog.com/blogs/ben_nevarez/archive/2009/07/26/getting-cpu-utilization-data-from-sql-server.aspx<br/>
55+
Tested on SQL Server version: 2014
5056

5157

5258
## [Table count alternative](Table Count alternative.sql)

0 commit comments

Comments
 (0)