CreateSystemhealthDBAndSchema.sql 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. /**************************
  2. This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment. THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object code form of the Sample Code, provided that You agree: (i) to not use Our name, logo, or trademarks to market Your software product in which the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product in which the Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code.
  3. Author: Denzil Ribeiro
  4. Date: Jan 6, 2013
  5. Description:
  6. This T-SQL script extracts information found in the System Health Session and puts them into a permanent tables in a database you create
  7. */
  8. /*
  9. use master
  10. go
  11. drop database XEvents_ImportSystemHealth
  12. go
  13. Create Database XEvents_ImportSystemHealth
  14. go
  15. Alter Database XEvents_ImportSystemHealth SET RECOVERY SIMPLE;
  16. USE [XEvents_ImportSystemHealth]
  17. GO
  18. */
  19. /****** Object: StoredProcedure [dbo].[sp_ImportXML] Script Date: 1/25/2013 3:39:13 PM ******/
  20. use dba_local
  21. GO
  22. SET ANSI_NULLS ON
  23. GO
  24. SET QUOTED_IDENTIFIER ON
  25. GO
  26. Create procedure [dbo].[sp_ImportXML]
  27. @path_to_health_session nvarchar(4000)
  28. as
  29. If object_id('tbl_XEImport') is not null
  30. drop table tbl_XEImport
  31. select [object_name] ,CAST(event_data AS XML) as c1
  32. into tbl_XEImport
  33. from sys.fn_xe_file_target_read_file(@path_to_health_session,NULL,NULL,NULL)
  34. create index ind_xeImport on tbl_XEImport(object_name)
  35. If object_id('tbl_ServerDiagnostics') is not null
  36. drop table tbl_ServerDiagnostics
  37. select c1.value('(event/data[@name="component"]/text)[1]', 'varchar(100)') as SdComponent,c1
  38. into tbl_ServerDiagnostics
  39. from tbl_XEImport
  40. where object_name = 'sp_server_diagnostics_component_result'
  41. /*
  42. else
  43. select c1.value('(event/data[@name="component"]/value)[1]', 'varchar(100)') as SdComponent,c1
  44. into tbl_ServerDiagnostics
  45. from tbl_XEImport
  46. where object_name = 'component_health_result'
  47. */
  48. --create index ind_ServerDiagnostics on tbl_ServerDiagnostics(SdComponent)
  49. GO
  50. /****** Object: StoredProcedure [dbo].[SpLoadComponentSummary] Script Date: 1/25/2013 3:39:13 PM ******/
  51. SET ANSI_NULLS ON
  52. GO
  53. SET QUOTED_IDENTIFIER ON
  54. GO
  55. Create procedure [dbo].[SpLoadComponentSummary]
  56. @UTDDateDiff int
  57. as
  58. if object_id('tbl_Summary') is not null
  59. drop table tbl_Summary
  60. select
  61. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  62. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as timestamp,
  63. c1.value('(event/data[@name="component"]/text)[1]', 'varchar(100)') as component_name,
  64. c1.value('(event/data[@name="state"]/text)[1]', 'varchar(100)') as [component_state]
  65. /*
  66. CASE c1.value('(event/data[@name="component"]/text)[1]', 'varchar(100)')
  67. WHEN '' then c1.value('(event/data[@name="component"]/text)[1]', 'varchar(100)')
  68. ELSE c1.value('(event/data[@name="component"]/value)[1]', 'varchar(100)')
  69. END as component_name,
  70. CASE c1.value('(event/data[@name="state"]/text)[1]', 'varchar(100)')
  71. WHEN '' then c1.value('(event/data[@name="state"]/text)[1]', 'varchar(100)')
  72. ELSE c1.value('(event/data[@name="state_desc"]/value)[1]', 'varchar(100)')
  73. END as [component_state]
  74. */
  75. into tbl_Summary
  76. FROM tbl_ServerDiagnostics
  77. CREATE NONCLUSTERED INDEX [Ind_TblSummary] ON [dbo].[tbl_Summary]
  78. (
  79. [timestamp] ASC
  80. )WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]
  81. GO
  82. /****** Object: StoredProcedure [dbo].[spLoadConnectivity_ring_buffer] Script Date: 1/25/2013 3:39:13 PM ******/
  83. SET ANSI_NULLS ON
  84. GO
  85. SET QUOTED_IDENTIFIER ON
  86. GO
  87. Create procedure [dbo].[spLoadConnectivity_ring_buffer]
  88. @UTDDateDiff int
  89. as
  90. if object_id('tbl_connectivity_ring_buffer') is not null
  91. drop table tbl_connectivity_ring_buffer
  92. select
  93. c1.value('(./event/@timestamp)[1]', 'datetime') as utctimestamp,
  94. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  95. c1.value('(./event/data[@name="type"]/text)[1]', 'varchar(100)') AS [Type],
  96. c1.value('(./event/data[@name="id"]/value)[1]', 'bigint') as record_id,
  97. c1.value('(./event/data[@name="source"]/text)[1]', 'varchar(20)') as source,
  98. c1.value('(./event/data[@name="session_id"]/value)[1]', 'int') as session_id,
  99. c1.value('(./event/data[@name="os_error"]/value)[1]', 'bigint') as os_error,
  100. c1.value('(./event/data[@name="sni_error"]/value)[1]', 'bigint') as sni_error,
  101. c1.value('(./event/data[@name="sni_consumer_error"]/value)[1]', 'bigint') as sni_consumer_error,
  102. c1.value('(./event/data[@name="state"]/value)[1]', 'int') as [state],
  103. c1.value('(./event/data[@name="port"]/value)[1]', 'int') as port,
  104. c1.value('(./event/data[@name="remote_port"]/value)[1]', 'int') as remote_port,
  105. c1.value('(./event/data[@name="tds_input_buffer_error"]/value)[1]', 'bigint') as tds_inputbuffererror,
  106. c1.value('(./event/data[@name="total_login_time_ms"]/value)[1]', 'bigint') as total_login_time_ms,
  107. c1.value('(./event/data[@name="login_task_enqueued_ms"]/value)[1]', 'bigint') as login_task_enqueued_ms,
  108. c1.value('(./event/data[@name="network_writes_ms"]/value)[1]', 'bigint') as network_writes_ms,
  109. c1.value('(./event/data[@name="network_reads_ms"]/value)[1]', 'bigint') as network_reads_ms,
  110. c1.value('(./event/data[@name="ssl_processing_ms"]/value)[1]', 'bigint') as ssl_processing_ms,
  111. c1.value('(./event/data[@name="sspi_processing_ms"]/value)[1]', 'bigint') as sspi_processing_ms,
  112. c1.value('(./event/data[@name="login_trigger_and_resource_governor_processing_ms"]/value)[1]', 'bigint') as login_trigger_and_resource_governor_processing_ms,
  113. c1.value('(./event/data[@name="connection_id"]/value)[1]', 'varchar(50)') as connection_id,
  114. c1.value('(./event/data[@name="connection_peer_id"]/value)[1]', 'varchar(50)') as connection_peer_id,
  115. c1.value('(./event/data[@name="local_host"]/value)[1]', 'varchar (50)') as local_host,
  116. c1.value('(./event/data[@name="remote_host"]/value)[1]', 'varchar (50)') as remote_host,
  117. c1.value('(./event/data[@name="SessionIsKilled"]/value)[1]', 'smallint') as SessionIsKilled
  118. into tbl_connectivity_ring_buffer
  119. from tbl_XEImport where object_name = 'connectivity_ring_buffer_recorded'
  120. GO
  121. /****** Object: StoredProcedure [dbo].[SpLoadErrorRecorded] Script Date: 1/25/2013 3:39:13 PM ******/
  122. SET ANSI_NULLS ON
  123. GO
  124. SET QUOTED_IDENTIFIER ON
  125. GO
  126. Create procedure [dbo].[SpLoadErrorRecorded]
  127. @UTDDateDiff int
  128. as
  129. if object_id('tbl_errors') is not null
  130. drop table tbl_errors
  131. select
  132. c1.value('(./event/@timestamp)[1]', 'datetime') as utctimestamp,
  133. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  134. c1.value('(./event/data[@name="session_id"])[1]', 'int') as session_id,
  135. c1.value('(./event/data[@name="database_id"])[1]', 'int') as database_id,
  136. c1.value('(./event/data[@name="error_number"])[1]', 'int') as [error_number],
  137. c1.value('(./event/data[@name="severity"])[1]', 'int') as severity,
  138. c1.value('(./event/data[@name="state"])[1]', 'int') as [state],
  139. c1.value('(./event/data[@name="category"]/text)[1]', 'nvarchar(100)') as category,
  140. c1.value('(./event/data[@name="destination"]/text)[1]', 'nvarchar(100)') as destination,
  141. c1.value('(./event/data[@name="message"])[1]', 'nvarchar(1000)') as message
  142. into tbl_errors
  143. from tbl_XEImport
  144. where object_name like 'error_reported'
  145. GO
  146. /****** Object: StoredProcedure [dbo].[SpLoadIO_SUBSYSTEMComponent] Script Date: 1/25/2013 3:39:13 PM ******/
  147. SET ANSI_NULLS ON
  148. GO
  149. SET QUOTED_IDENTIFIER ON
  150. GO
  151. Create procedure [dbo].[SpLoadIO_SUBSYSTEMComponent]
  152. @UTDDateDiff int
  153. as
  154. if object_id('tbl_IO_SUBSYSTEM') is not null
  155. drop table tbl_IO_SUBSYSTEM
  156. select
  157. c1.value('(./event/@timestamp)[1]', 'datetime') as UTCtimestamp,
  158. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as timestamp,
  159. c1.value('(event/data[@name="component"]/text)[1]', 'varchar(100)') as [component_name],
  160. c1.value('(event/data[@name="state"]/text)[1]', 'varchar(100)') as [component_state],
  161. c1.value('(event/data[@name="data"]/value/ioSubsystem/@ioLatchTimeouts)[1]','int') as [ioLatchTimeouts],
  162. c1.value('(event/data[@name="data"]/value/ioSubsystem/@intervalLongIos)[1]','int') as [intervalLongIos],
  163. c1.value('(event/data[@name="data"]/value/ioSubsystem/@totalLongIos)[1]','int') as [totalLongIos],
  164. c1.value('(event/data[@name="data"]/value/ioSubsystem/longestPendingRequests/pendingRequest[1]/@duration)[1]','bigint') as [longestPendingRequests_duration],
  165. c1.value('(event/data[@name="data"]/value/ioSubsystem/longestPendingRequests/pendingRequest[1]/@filePath)[1]','nvarchar(500)') as [longestPendingRequests_filePath],
  166. c1.value('(event/data[@name="data"]/value/ioSubsystem/longestPendingRequests/pendingRequest[1]/@offset)[1]','bigint') as [longestPendingRequests_offset],
  167. c1.value('(event/data[@name="data"]/value/ioSubsystem/longestPendingRequests/pendingRequest[1]/@handle)[1]','nvarchar(20)') as [longestPendingRequests_handle]
  168. into tbl_IO_SUBSYSTEM
  169. FROM tbl_ServerDiagnostics
  170. where SdComponent = 'IO_SUBSYSTEM'
  171. GO
  172. /****** Object: StoredProcedure [dbo].[SpLoadQueryProcessing] Script Date: 1/25/2013 3:39:13 PM ******/
  173. SET ANSI_NULLS ON
  174. GO
  175. SET QUOTED_IDENTIFIER ON
  176. GO
  177. Create procedure [dbo].[SpLoadQueryProcessing]
  178. @UTDDateDiff int
  179. as
  180. if object_id('tbl_QUERY_PROCESSING') is not null
  181. drop table [tbl_QUERY_PROCESSING]
  182. select
  183. c1.value('(./event/@timestamp)[1]', 'datetime') as utctimestamp,
  184. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  185. c1.value('(event/data[@name="component"]/text)[1]', 'varchar(100)') as [component_name],
  186. c1.value('(event/data[@name="state"]/text)[1]', 'varchar(100)') as [component_state],
  187. c1.value('(./event//data[@name="data"]/value/queryProcessing/@maxWorkers)[1]', 'int') as maxworkers,
  188. c1.value('(./event//data[@name="data"]/value/queryProcessing/@workersCreated)[1]', 'int') as workerscreated,
  189. c1.value('(./event//data[@name="data"]/value/queryProcessing/@tasksCompletedWithinInterval)[1]', 'int') as tasksCompletedWithinInterval,
  190. c1.value('(./event//data[@name="data"]/value/queryProcessing/@oldestPendingTaskWaitingTime)[1]', 'bigint') as oldestPendingTaskWaitingTime,
  191. c1.value('(./event//data[@name="data"]/value/queryProcessing/@pendingTasks)[1]', 'int') as pendingTasks,
  192. c1.value('(./event//data[@name="data"]/value/queryProcessing/@hasUnresolvableDeadlockOccurred)[1]', 'int') as hasUnresolvableDeadlockOccurred,
  193. c1.value('(./event//data[@name="data"]/value/queryProcessing/@hasDeadlockedSchedulersOccurred)[1]', 'int') as hasDeadlockedSchedulersOccurred,
  194. c1.value('(./event//data[@name="data"]/value/queryProcessing/@trackingNonYieldingScheduler)[1]', 'varchar(10)') as trackingNonYieldingScheduler
  195. into [tbl_QUERY_PROCESSING]
  196. from tblQryProcessingXmlOutput
  197. GO
  198. /****** Object: StoredProcedure [dbo].[SpLoadQueryProcessingComponent] Script Date: 1/25/2013 3:39:13 PM ******/
  199. SET ANSI_NULLS ON
  200. GO
  201. SET QUOTED_IDENTIFIER ON
  202. GO
  203. Create procedure [dbo].[SpLoadQueryProcessingComponent]
  204. @UTDDateDiff int
  205. as
  206. -- Import the XML
  207. If object_id('tblQryProcessingXmlOutput') is not null
  208. drop table tblQryProcessingXmlOutput
  209. CREATE TABLE [dbo].[tblQryProcessingXmlOutput](
  210. [c1] [xml] NULL
  211. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  212. insert into tblQryProcessingXmlOutput (c1)
  213. select c1 as snodes
  214. FROM tbl_ServerDiagnostics
  215. where SdComponent = 'QUERY_PROCESSING'
  216. -- Call individual Pieces
  217. exec SpLoadQueryProcessingComponent_TopWaits @UTDDateDiff
  218. exec SpLoadQueryProcessing @UTDDateDiff
  219. exec SpLoadQueryProcessingComponent_Blocking @UTDDateDiff
  220. --exec SpLoadQueryProcessingComponent_HighCPU @UTDDateDiff
  221. --exec SpLoadQueryProcessingComponent_QueryWaits @UTDDateDiff
  222. GO
  223. /****** Object: StoredProcedure [dbo].[SpLoadQueryProcessingComponent_Blocking] Script Date: 1/25/2013 3:39:13 PM ******/
  224. SET ANSI_NULLS ON
  225. GO
  226. SET QUOTED_IDENTIFIER ON
  227. GO
  228. Create procedure [dbo].[SpLoadQueryProcessingComponent_Blocking]
  229. @UTDDateDiff int
  230. as
  231. if object_id('tbl_BlockingXeOutput') is not null
  232. drop table tbl_BlockingXeOutput
  233. select
  234. [utctimestamp],[timestamp],
  235. c1.value('(blocked-process-report/blocking-process/process/inputbuf)[1]', 'nvarchar(max)') as [blocking_process],
  236. c1.value('(blocked-process-report/blocking-process/process[1]/@spid)[1]', 'int') as [blocking_process_id],
  237. c1.value('(blocked-process-report/blocking-process/process[1]/@ecid)[1]', 'int') as [blocking_process_ecid],
  238. c1.value('(blocked-process-report/blocking-process/process[1]/@status)[1]', 'varchar(100)') as [blocking_process_status],
  239. c1.value('(blocked-process-report/blocking-process/process[1]/@isolationlevel)[1]', 'varchar(200)') as [blocking_process_isolationlevel],
  240. c1.value('(blocked-process-report/blocking-process/process[1]/@lastbatchstarted)[1]', 'datetime') as [blocking_process_lastbatchstarted],
  241. c1.value('(blocked-process-report/blocking-process/process[1]/@lastbatchcompleted)[1]', 'datetime') as [blocking_process_lastbatchcompleted],
  242. c1.value('(blocked-process-report/blocking-process/process[1]/@lastattention)[1]', 'datetime') as [blocking_process_lastattention],
  243. c1.value('(blocked-process-report/blocking-process/process[1]/@trancount)[1]', 'int') as [blocking_process_trancount],
  244. c1.value('(blocked-process-report/blocking-process/process[1]/@xactid)[1]', 'bigint') as [blocking_process_xactid],
  245. c1.value('(/blocked-process-report/blocking-process/process[1]/@clientapp)[1]', 'nvarchar(100)') as [blocking_process_clientapp],
  246. c1.value('(/blocked-process-report/blocking-process/process[1]/@hostname)[1]', 'nvarchar(100)') as [blocking_process_hostname],
  247. c1.value('(/blocked-process-report/blocking-process/process[1]/@loginname)[1]', 'nvarchar(100)') as [blocking_process_loginname],
  248. c1.value('(/blocked-process-report/blocking-process/process[1]/@waitresource)[1]', 'nvarchar(200)') as [blocking_process_wait_resource],
  249. c1.value('(/blocked-process-report/blocked-process/process/inputbuf)[1]', 'nvarchar(max)') as [blocked_process],
  250. c1.value('(/blocked-process-report/blocked-process/process[1]/@spid)[1]', 'int') as [blocked_process_id],
  251. c1.value('(/blocked-process-report/blocked-process/process[1]/@ecid)[1]', 'int') as [blocked_process_ecid],
  252. c1.value('(/blocked-process-report/blocked-process/process[1]/@status)[1]', 'varchar(100)') as [blocked_process_status],
  253. c1.value('(/blocked-process-report/blocked-process/process[1]/@waitresource)[1]', 'nvarchar(200)') as [blocked_process_wait_resource],
  254. c1.value('(/blocked-process-report/blocked-process/process[1]/@lockMode)[1]', 'char(5)') as [blocked_process_lockMode],
  255. c1.value('(/blocked-process-report/blocked-process/process[1]/@waittime)[1]', 'nvarchar(200)') as [blocked_process_wait_time],
  256. c1.value('(/blocked-process-report/blocked-process/process[1]/@lastbatchstarted)[1]', 'datetime') as [blocked_process_lastbatchstarted],
  257. c1.value('(/blocked-process-report/blocked-process/process[1]/@lastbatchcompleted)[1]', 'datetime') as [blocked_process_lastbatchcompleted],
  258. c1.value('(/blocked-process-report/blocked-process/process[1]/@lastattention)[1]', 'datetime') as [blocked_process_lastattention],
  259. c1.value('(/blocked-process-report/blocked-process/process[1]/@clientapp)[1]', 'nvarchar(100)') as [blocked_process_clientapp],
  260. c1.value('(/value/blocked-process-report/blocked-process/process[1]/@hostname)[1]', 'nvarchar(100)') as [blocked_process_hostname],
  261. c1.value('(/blocked-process-report/blocked-process/process[1]/@loginname)[1]', 'nvarchar(100)') as [blocked_process_loginname]
  262. --T.bpnodes.value('(event/data[@name="blocked_process"]/value/blocked-process-report/blocking-process/process/executionstack/frame[1]/@sqlhandle)[1]', 'nvarchar(max)') as [blocking_process_sqlhandle]
  263. into tbl_BlockingXeOutput
  264. FROM
  265. (
  266. select c1.value('(event/@timestamp)[1]','datetime') as [utctimestamp]
  267. ,DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp]
  268. ,T.blk.query( '.') as c1 from tblQryProcessingXmlOutput
  269. CROSS APPLY c1.nodes('./event/data[@name="data"]/value/queryProcessing/blockingTasks/blocked-process-report') as T(blk)
  270. ) as T1
  271. GO
  272. /****** Object: StoredProcedure [dbo].[SpLoadQueryProcessingComponent_TopWaits] Script Date: 1/25/2013 3:39:13 PM ******/
  273. SET ANSI_NULLS ON
  274. GO
  275. SET QUOTED_IDENTIFIER ON
  276. GO
  277. Create procedure [dbo].[SpLoadQueryProcessingComponent_TopWaits]
  278. @UTDDateDiff int
  279. as
  280. if object_id('tbl_OS_WAIT_STATS_byDuration') is not null
  281. drop table tbl_OS_WAIT_STATS_byDuration
  282. CREATE TABLE [dbo].[tbl_OS_WAIT_STATS_byDuration](
  283. [UTCtimestamp] [datetime] NULL,
  284. [timestamp] [datetime] NULL,
  285. [wait_type] [varchar](47) NULL,
  286. [waiting_tasks_count] [bigint] NULL,
  287. [avg_wait_time_ms] [bigint] NULL,
  288. [max_wait_time_ms] [bigint] NULL
  289. ) ON [PRIMARY]
  290. ALTER TABLE [dbo].[tbl_OS_WAIT_STATS_byDuration] ADD [wait_category] AS (case when [wait_type] like 'LCK%' then 'Locks' when [wait_type] like 'PAGEIO%' then 'Page I/O Latch' when [wait_type] like 'PAGELATCH%' then 'Page Latch (non-I/O)' when [wait_type] like 'LATCH%' then 'Latch (non-buffer)' when [wait_type] like 'IO_COMPLETION' then 'I/O Completion' when [wait_type] like 'ASYNC_NETWORK_IO' then 'Network I/O (client fetch)' when [wait_type]='CMEMTHREAD' OR [wait_type]='SOS_RESERVEDMEMBLOCKLIST' OR [wait_type]='RESOURCE_SEMAPHORE' then 'Memory' when [wait_type] like 'RESOURCE_SEMAPHORE_%' then 'Compilation' when [wait_type] like 'MSQL_XP' then 'XProc' when [wait_type] like 'WRITELOG' then 'Writelog' when [wait_type]='FT_IFTS_SCHEDULER_IDLE_WAIT' OR [wait_type]='WAITFOR' OR [wait_type]='EXECSYNC' OR [wait_type]='XE_TIMER_EVENT' OR [wait_type]='XE_DISPATCHER_WAIT' OR [wait_type]='WAITFOR_TASKSHUTDOWN' OR [wait_type]='WAIT_FOR_RESULTS' OR [wait_type]='SNI_HTTP_ACCEPT' OR [wait_type]='SLEEP_TEMPDBSTARTUP' OR [wait_type]='SLEEP_TASK' OR [wait_type]='SLEEP_SYSTEMTASK' OR [wait_type]='SLEEP_MSDBSTARTUP' OR [wait_type]='SLEEP_DCOMSTARTUP' OR [wait_type]='SLEEP_DBSTARTUP' OR [wait_type]='SLEEP_BPOOL_FLUSH' OR [wait_type]='SERVER_IDLE_CHECK' OR [wait_type]='RESOURCE_QUEUE' OR [wait_type]='REQUEST_FOR_DEADLOCK_SEARCH' OR [wait_type]='ONDEMAND_TASK_QUEUE' OR [wait_type]='LOGMGR_QUEUE' OR [wait_type]='LAZYWRITER_SLEEP' OR [wait_type]='KSOURCE_WAKEUP' OR [wait_type]='FSAGENT' OR [wait_type]='CLR_MANUAL_EVENT' OR [wait_type]='CLR_AUTO_EVENT' OR [wait_type]='CHKPT' OR [wait_type]='CHECKPOINT_QUEUE' OR [wait_type]='BROKER_TO_FLUSH' OR [wait_type]='BROKER_TASK_STOP' OR [wait_type]='BROKER_TRANSMITTER' OR [wait_type]='BROKER_RECEIVE_WAITFOR' OR [wait_type]='BROKER_EVENTHANDLER' OR [wait_type]='DBMIRROR_EVENTS_QUEUE' OR [wait_type]='DBMIRROR_DBM_EVENT' OR [wait_type]='DBMIRRORING_CMD' OR [wait_type]='DBMIRROR_WORKER_QUEUE' then 'IGNORABLE' else [wait_type] end)
  291. Create clustered index [tbl_OS_WAIT_STATS_byDuration_Clus] on [tbl_OS_WAIT_STATS_byDuration](timestamp)
  292. INSERT INTO [dbo].[tbl_OS_WAIT_STATS_byDuration]
  293. ([UTCtimestamp]
  294. ,[timestamp]
  295. ,[wait_type]
  296. ,[waiting_tasks_count]
  297. ,[avg_wait_time_ms]
  298. ,[max_wait_time_ms])
  299. select
  300. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  301. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  302. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[1]/@waitType)[1]','varchar(47)') as [waitType],
  303. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[1]/@waits)[1]','bigint') as [waits],
  304. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[1]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  305. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[1]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  306. FROM tblQryProcessingXmlOutput
  307. UNION ALL
  308. select
  309. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  310. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  311. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[2]/@waitType)[1]','varchar(47)') as [waitType],
  312. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[2]/@waits)[1]','bigint') as [waits],
  313. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[2]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  314. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[2]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  315. FROM tblQryProcessingXmlOutput
  316. UNION ALL
  317. select
  318. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  319. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  320. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[3]/@waitType)[1]','varchar(47)') as [waitType],
  321. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[3]/@waits)[1]','bigint') as [waits],
  322. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[3]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  323. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[3]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  324. FROM tblQryProcessingXmlOutput
  325. UNION ALL
  326. select
  327. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  328. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  329. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[4]/@waitType)[1]','varchar(47)') as [waitType],
  330. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[4]/@waits)[1]','bigint') as [waits],
  331. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[4]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  332. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[4]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  333. FROM tblQryProcessingXmlOutput
  334. UNION ALL
  335. select
  336. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  337. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  338. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[5]/@waitType)[1]','varchar(47)') as [waitType],
  339. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[5]/@waits)[1]','bigint') as [waits],
  340. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[5]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  341. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[5]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  342. FROM tblQryProcessingXmlOutput
  343. UNION ALL
  344. select
  345. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  346. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  347. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[6]/@waitType)[1]','varchar(47)') as [waitType],
  348. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[6]/@waits)[1]','bigint') as [waits],
  349. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[6]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  350. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[6]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  351. FROM tblQryProcessingXmlOutput
  352. UNION ALL
  353. select
  354. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  355. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  356. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[7]/@waitType)[1]','varchar(47)') as [waitType],
  357. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[7]/@waits)[1]','bigint') as [waits],
  358. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[7]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  359. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[7]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  360. FROM tblQryProcessingXmlOutput
  361. UNION ALL
  362. select
  363. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  364. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  365. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[8]/@waitType)[1]','varchar(47)') as [waitType],
  366. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[8]/@waits)[1]','bigint') as [waits],
  367. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[8]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  368. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[8]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  369. FROM tblQryProcessingXmlOutput
  370. UNION ALL
  371. select
  372. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  373. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  374. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[9]/@waitType)[1]','varchar(47)') as [waitType],
  375. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[9]/@waits)[1]','bigint') as [waits],
  376. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[9]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  377. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[9]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  378. FROM tblQryProcessingXmlOutput
  379. UNION ALL
  380. select
  381. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  382. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  383. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[10]/@waitType)[1]','varchar(47)') as [waitType],
  384. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[10]/@waits)[1]','bigint') as [waits],
  385. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[10]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  386. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/nonPreemptive/byCount/wait[10]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  387. FROM tblQryProcessingXmlOutput
  388. UNION ALL
  389. select
  390. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  391. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  392. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[1]/@waitType)[1]','varchar(47)') as [waitType],
  393. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[1]/@waits)[1]','bigint') as [waits],
  394. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[1]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  395. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[1]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  396. FROM tblQryProcessingXmlOutput
  397. UNION ALL
  398. select
  399. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  400. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  401. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[2]/@waitType)[1]','varchar(47)') as [waitType],
  402. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[2]/@waits)[1]','bigint') as [waits],
  403. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[2]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  404. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[2]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  405. FROM tblQryProcessingXmlOutput
  406. UNION ALL
  407. select
  408. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  409. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  410. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[3]/@waitType)[1]','varchar(47)') as [waitType],
  411. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[3]/@waits)[1]','bigint') as [waits],
  412. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[3]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  413. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[3]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  414. FROM tblQryProcessingXmlOutput
  415. UNION ALL
  416. select
  417. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  418. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  419. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[4]/@waitType)[1]','varchar(47)') as [waitType],
  420. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[4]/@waits)[1]','bigint') as [waits],
  421. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[4]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  422. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[4]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  423. FROM tblQryProcessingXmlOutput
  424. UNION ALL
  425. select
  426. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  427. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  428. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[5]/@waitType)[1]','varchar(47)') as [waitType],
  429. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[5]/@waits)[1]','bigint') as [waits],
  430. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[5]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  431. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[5]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  432. FROM tblQryProcessingXmlOutput
  433. UNION ALL
  434. select
  435. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  436. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  437. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[6]/@waitType)[1]','varchar(47)') as [waitType],
  438. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[6]/@waits)[1]','bigint') as [waits],
  439. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[6]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  440. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[6]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  441. FROM tblQryProcessingXmlOutput
  442. UNION ALL
  443. select
  444. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  445. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  446. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[7]/@waitType)[1]','varchar(47)') as [waitType],
  447. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[7]/@waits)[1]','bigint') as [waits],
  448. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[7]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  449. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[7]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  450. FROM tblQryProcessingXmlOutput
  451. UNION ALL
  452. select
  453. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  454. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  455. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[8]/@waitType)[1]','varchar(47)') as [waitType],
  456. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[8]/@waits)[1]','bigint') as [waits],
  457. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[8]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  458. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[8]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  459. FROM tblQryProcessingXmlOutput
  460. UNION ALL
  461. select
  462. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  463. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  464. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[9]/@waitType)[1]','varchar(47)') as [waitType],
  465. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[9]/@waits)[1]','bigint') as [waits],
  466. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[9]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  467. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[9]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  468. FROM tblQryProcessingXmlOutput
  469. UNION ALL
  470. select
  471. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  472. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  473. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[10]/@waitType)[1]','varchar(47)') as [waitType],
  474. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[10]/@waits)[1]','bigint') as [waits],
  475. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[10]/@averageWaitTime)[1]','bigint') as [averageWaitTime],
  476. c1.value('(event/data[@name="data"]/value/queryProcessing/topWaits/preemptive/byCount/wait[10]/@maxWaitTime)[1]','bigint') as [maxWaitTime]
  477. FROM tblQryProcessingXmlOutput
  478. GO
  479. /****** Object: StoredProcedure [dbo].[SpLoadResourceComponent] Script Date: 1/25/2013 3:39:13 PM ******/
  480. SET ANSI_NULLS ON
  481. GO
  482. SET QUOTED_IDENTIFIER ON
  483. GO
  484. Create procedure [dbo].[SpLoadResourceComponent]
  485. @UTDDateDiff int
  486. as
  487. if object_id('tbl_Resource') is not null
  488. drop table tbl_Resource
  489. select
  490. c1.value('(./event/@timestamp)[1]', 'datetime') as UTCtimestamp,
  491. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  492. c1.value('(./event//data[@name="state"]/text)[1]', 'varchar(20)') as State,
  493. c1.value('(./event//data[@name="data"]/value/resource/@lastNotification)[1]', 'nvarchar(100)') as lastNotification,
  494. c1.value('(./event//data[@name="data"]/value/resource/@outOfMemoryExceptions)[1]', 'tinyint') as outOfMemoryExceptions,
  495. c1.value('(./event//data[@name="data"]/value/resource/@isAnyPoolOutOfMemory)[1]', 'tinyint') as isAnyPoolOutOfMemory,
  496. c1.value('(./event//data[@name="data"]/value/resource/@processOutOfMemoryPeriod)[1]', 'tinyint') as processOutOfMemoryPeriod,
  497. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Process/System Counts"]/entry[@description="Available Physical Memory"]/@value)[1]', 'bigint') as available_physical_memory,
  498. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Process/System Counts"]/entry[@description="Available Virtual Memory"]/@value)[1]', 'bigint') as available_virtual_memory,
  499. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Process/System Counts"]/entry[@description="Available Paging File"]/@value)[1]', 'bigint') as available_paging_file,
  500. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Process/System Counts"]/entry[@description="Working Set"]/@value)[1]', 'bigint') as working_set,
  501. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Process/System Counts"]/entry[@description="Percent of Committed Memory in WS"]/@value)[1]', 'bigint') as percent_workingset_committed,
  502. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Process/System Counts"]/entry[@description="Page Faults"]/@value)[1]', 'bigint') as page_faults,
  503. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Process/System Counts"]/entry[@description="System physical memory high"]/@value)[1]', 'bigint') as sys_physical_memory_high,
  504. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Process/System Counts"]/entry[@description="System physical memory low"]/@value)[1]', 'bigint') as sys_physical_memory_low,
  505. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Process/System Counts"]/entry[@description="Process physical memory low"]/@value)[1]', 'bigint') as process_phyiscal_memory_low,
  506. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Process/System Counts"]/entry[@description="Process virtual memory low"]/@value)[1]', 'bigint') as process_virtual_memory_low,
  507. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="VM Reserved"]/@value)[1]', 'bigint') as vm_reserved_kb,
  508. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="VM Committed"]/@value)[1]', 'bigint') as vm_committed_kb,
  509. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Locked Pages Allocated"]/@value)[1]', 'bigint') as locked_pages_allocated_kb,
  510. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Large Pages Allocated"]/@value)[1]', 'bigint') as large_pages_allocated_kb,
  511. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Target Committed"]/@value)[1]', 'bigint') as target_committed_kb,
  512. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Current Committed"]/@value)[1]', 'bigint') as current_committed_kb,
  513. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Pages Allocated"]/@value)[1]', 'bigint') as Pages_allocated_kb,
  514. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Pages Reserved"]/@value)[1]', 'bigint') as pages_reserved_kb,
  515. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Pages Free"]/@value)[1]', 'bigint') as pages_free_kb,
  516. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Pages In Use"]/@value)[1]', 'bigint') as pages_in_use_kb,
  517. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Page Alloc Potential"]/@value)[1]', 'bigint') as page_alloc_potential,
  518. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="NUMA Growth Phase"]/@value)[1]', 'int') as numa_growth_phase,
  519. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Last OOM Factor"]/@value)[1]', 'int') as last_oom_factor,
  520. c1.value('(./event//data[@name="data"]/value/resource/memoryReport[@name="Memory Manager"]/entry[@description="Last OS Error"]/@value)[1]', 'int') as last_os_error
  521. into tbl_Resource
  522. FROM tbl_ServerDiagnostics
  523. where SdComponent = 'RESOURCE'
  524. GO
  525. /****** Object: StoredProcedure [dbo].[spLoadSchedulerMonitor] Script Date: 1/25/2013 3:39:13 PM ******/
  526. SET ANSI_NULLS ON
  527. GO
  528. SET QUOTED_IDENTIFIER ON
  529. GO
  530. Create Procedure [dbo].[spLoadSchedulerMonitor]
  531. @UTDDateDiff int
  532. as
  533. if object_id('tbl_scheduler_monitor') is not null
  534. drop table tbl_scheduler_monitor
  535. select
  536. c1.value('(./event/@timestamp)[1]', 'datetime') as UTCtimestamp,
  537. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  538. c1.value('(./event/data[@name="id"])[1]', 'bigint') as [id],
  539. c1.value('(./event/data[@name="process_utilization"])[1]', 'int') as process_utilization,
  540. c1.value('(./event/data[@name="system_idle"])[1]', 'int') as system_idle,
  541. c1.value('(./event/data[@name="user_mode_time"])[1]', 'bigint') as user_mode_time,
  542. c1.value('(./event/data[@name="kernel_mode_time"])[1]', 'bigint') as kernel_mode_time,
  543. c1.value('(./event/data[@name="working_set_delta"])[1]', 'numeric(24,0)') as working_set_delta,
  544. c1.value('(./event/data[@name="memory_utilization"])[1]', 'int') as memory_utilization
  545. into tbl_scheduler_monitor
  546. from tbl_XEImport
  547. where object_name like 'scheduler_monitor_system_health_ring_buffer_recorded'
  548. GO
  549. /****** Object: StoredProcedure [dbo].[SpLoadSecurityRingBuffer] Script Date: 1/25/2013 3:39:13 PM ******/
  550. SET ANSI_NULLS ON
  551. GO
  552. SET QUOTED_IDENTIFIER ON
  553. GO
  554. Create procedure [dbo].[SpLoadSecurityRingBuffer]
  555. @UTDDateDiff int
  556. as
  557. if object_id('tbl_security_ring_buffer') is not null
  558. drop table [tbl_security_ring_buffer]
  559. select
  560. c1.value('(./event/@timestamp)[1]', 'datetime') as utctimestamp,
  561. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  562. c1.value('(./event/data[@name="id"])[1]', 'bigint') as id,
  563. c1.value('(./event/data[@name="session_id"])[1]', 'int') as session_id,
  564. c1.value('(./event/data[@name="error_code"])[1]', 'bigint') as [error_code],
  565. c1.value('(./event/data[@name="api_name"])[1]', 'nvarchar(100)') as api_name,
  566. c1.value('(./event/data[@name="calling_api_name"])[1]', 'nvarchar(100)') as calling_api_name
  567. into [tbl_security_ring_buffer]
  568. from tbl_XEImport
  569. where object_name like 'security_error_ring_buffer_recorded'
  570. GO
  571. /****** Object: StoredProcedure [dbo].[SpLoadSYSTEMComponent] Script Date: 1/25/2013 3:39:13 PM ******/
  572. SET ANSI_NULLS ON
  573. GO
  574. SET QUOTED_IDENTIFIER ON
  575. GO
  576. Create procedure [dbo].[SpLoadSYSTEMComponent]
  577. @UTDDateDiff int
  578. as
  579. if object_id('tbl_SYSTEM') is not null
  580. drop table tbl_SYSTEM
  581. select
  582. c1.value('(event/@timestamp)[1]','datetime') as [UTCtimestamp],
  583. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as timestamp,
  584. c1.value('(event/data[@name="component"]/text)[1]', 'varchar(100)') as [component_name],
  585. c1.value('(event/data[@name="state"]/text)[1]', 'varchar(100)') as [component_state],
  586. c1.value('(event/data[@name="data"]/value/system[1]/@spinlockBackoffs)[1]', 'int') as [spinlockBackoffs],
  587. c1.value('(event/data[@name="data"]/value/system[1]/@sickSpinlockTypeAfterAv)[1]', 'varchar(100)') as [sickSpinlockTypeAfterAv],
  588. c1.value('(event/data[@name="data"]/value/system[1]/@latchWarnings)[1]', 'int') as [latchWarnings],
  589. c1.value('(event/data[@name="data"]/value/system[1]/@isAccessViolationOccurred)[1]', 'int') as [isAccessViolationOccurred],
  590. c1.value('(event/data[@name="data"]/value/system[1]/@writeAccessViolationCount)[1]', 'int') as [writeAccessViolationCount],
  591. c1.value('(event/data[@name="data"]/value/system[1]/@totalDumpRequests)[1]', 'int') as [totalDumpRequests],
  592. c1.value('(event/data[@name="data"]/value/system[1]/@intervalDumpRequests)[1]', 'int') as [intervalDumpRequests],
  593. c1.value('(event/data[@name="data"]/value/system[1]/@nonYieldingTasksReported)[1]', 'int') as [nonYieldingTasksReported],
  594. c1.value('(event/data[@name="data"]/value/system[1]/@pageFaults)[1]', 'bigint') as [pageFaults],
  595. c1.value('(event/data[@name="data"]/value/system[1]/@systemCpuUtilization)[1]', 'int') as [systemCpuUtilization],
  596. c1.value('(event/data[@name="data"]/value/system[1]/@sqlCpuUtilization)[1]', 'int') as [sqlCpuUtilization],
  597. c1.value('(event/data[@name="data"]/value/system[1]/@BadPagesDetected)[1]', 'int') as [BadPagesDetected],
  598. c1.value('(event/data[@name="data"]/value/system[1]/@BadPagesFixed)[1]', 'int') as [BadPagesFixed],
  599. c1.value('(event/data[@name="data"]/value/system[1]/@LastBadPageAddress)[1]', 'nvarchar(30)') as [LastBadPageAddress]
  600. into tbl_SYSTEM
  601. FROM tbl_ServerDiagnostics
  602. where SdComponent = 'SYSTEM'
  603. GO
  604. /****** Object: StoredProcedure [dbo].[spLoadWaitQueries] Script Date: 1/25/2013 3:39:13 PM ******/
  605. SET ANSI_NULLS ON
  606. GO
  607. SET QUOTED_IDENTIFIER ON
  608. GO
  609. Create procedure [dbo].[spLoadWaitQueries]
  610. @UTDDateDiff int
  611. as
  612. if object_id('tbl_waitqueries') is not null
  613. drop table tbl_waitqueries
  614. SELECT
  615. c1.value('(./event/@timestamp)[1]', 'datetime') as utctimestamp,
  616. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp],
  617. c1.value('(/event/data[@name="wait_type"]/text)[1]', 'varchar(50)') as WaitType,
  618. c1.value('(/event/data[@name="duration"]/value)[1]', 'bigint') as Duration,
  619. c1.value('(/event/data[@name="signal_duration"]/value)[1]', 'bigint') as signal_duration,
  620. c1.value('(/event/action[@name="session_id"]/value)[1]', 'int') as Session_ID,
  621. c1.value('(/event/action[@name="sql_text"]/value)[1]', 'varchar(max)') as sql_text
  622. into tbl_waitqueries
  623. FROM tbl_XEImport
  624. where object_name like 'wait_info%'
  625. GO
  626. /****** Object: StoredProcedure [dbo].[spLoadDeadlockReport] Script Date: 1/25/2013 3:39:13 PM ******/
  627. SET ANSI_NULLS ON
  628. GO
  629. SET QUOTED_IDENTIFIER ON
  630. GO
  631. Create procedure [dbo].[spLoadDeadlockReport]
  632. @UTDDateDiff int
  633. as
  634. if object_id('tbl_DeadlockReport') is not null
  635. drop table tbl_DeadlockReport
  636. SELECT
  637. c1.value('(./event/@timestamp)[1]', 'datetime') as utctimestamp,
  638. DATEADD(mi,@UTDDateDiff,c1.value('(./event/@timestamp)[1]', 'datetime')) as [timestamp]
  639. , *
  640. into tbl_DeadlockReport
  641. FROM tbl_XEImport
  642. where object_name like 'xml_deadlock_report'
  643. GO
  644. /****** Object: StoredProcedure [dbo].[spLoadSystemHealthSession] Script Date: 1/25/2013 3:39:13 PM ******/
  645. SET ANSI_NULLS ON
  646. GO
  647. SET QUOTED_IDENTIFIER ON
  648. GO
  649. Create procedure [dbo].[spLoadSystemHealthSession]
  650. @path_to_health_session nvarchar(4000) = NULL ,
  651. @UTDDateDiff int = 0
  652. as
  653. if object_id('tbl_ImportStatus') is not null
  654. drop table tbl_ImportStatus
  655. Create table tbl_ImportStatus
  656. ( StepName varchar(100),
  657. Status varchar(20),
  658. Starttime datetime
  659. )
  660. insert into tbl_ImportStatus Values('Load System Health Session','Processing',getdate())
  661. DECLARE @filename varchar(8000) ;
  662. IF (SUBSTRING(CAST(SERVERPROPERTY ('ProductVersion') AS varchar(50)),1,CHARINDEX('.',CAST(SERVERPROPERTY ('ProductVersion') AS varchar(50)))-1) >= 11)
  663. BEGIN
  664. If ( @path_to_health_session is null or @path_to_health_session ='')
  665. begin
  666. SET @UTDDateDiff = DATEDIFF(mi,GETUTCDATE(),GETDATE())
  667. -- Fetch information about the XEL file location
  668. SELECT @filename = CAST(target_data as XML).value('(/EventFileTarget/File/@name)[1]', 'varchar(8000)')
  669. FROM sys.dm_xe_session_targets
  670. WHERE target_name = 'event_file' and event_session_address = (select address from sys.dm_xe_sessions where name = 'system_health')
  671. SET @path_to_health_session = SUBSTRING(@filename,1,CHARINDEX('system_health',@filename,1)-1) + 'system_health*.xel'
  672. select @path_to_health_session,@filename, @UTDDateDiff
  673. end
  674. insert into tbl_ImportStatus Values('Importing XEL file','Processing',getdate())
  675. exec sp_ImportXML @path_to_health_session
  676. insert into tbl_ImportStatus Values('Load Scheduler Monitor','Processing',getdate())
  677. exec spLoadSchedulerMonitor @UTDDateDiff
  678. insert into tbl_ImportStatus Values('Load Resource Server Health Component','Processing',getdate())
  679. exec SpLoadResourceComponent @UTDDateDiff
  680. insert into tbl_ImportStatus Values('Load IO_Subsystem Server Health Component','Processing',getdate())
  681. exec SpLoadIO_SUBSYSTEMComponent @UTDDateDiff
  682. insert into tbl_ImportStatus Values('Load System Server Health Component','Processing',getdate())
  683. exec SpLoadSYSTEMComponent @UTDDateDiff
  684. insert into tbl_ImportStatus Values('Load System Health Summary','Processing',getdate())
  685. exec SpLoadComponentSummary @UTDDateDiff
  686. insert into tbl_ImportStatus Values('Load Query_Processing Server Health Component','Processing',getdate())
  687. exec SpLoadQueryProcessingComponent @UTDDateDiff
  688. insert into tbl_ImportStatus Values('Load Security Ring Buffer','Processing',getdate())
  689. exec SpLoadSecurityRingBuffer @UTDDateDiff
  690. insert into tbl_ImportStatus Values('Load Errors Recorded','Processing',getdate())
  691. exec SpLoadErrorRecorded @UTDDateDiff
  692. insert into tbl_ImportStatus Values('Wait Queries','Processing',getdate())
  693. exec spLoadWaitQueries @UTDDateDiff
  694. insert into tbl_ImportStatus Values('Connectivity Ring Buffer','Processing',getdate())
  695. exec spLoadConnectivity_ring_buffer @UTDDateDiff
  696. insert into tbl_ImportStatus Values('Deadlock Report','Processing',getdate())
  697. exec [spLoadDeadlockReport] @UTDDateDiff
  698. insert into tbl_ImportStatus Values('Import Finished','Done',getdate())
  699. end
  700. Else
  701. select 'Not a supported Server version: ' + @@version
  702. GO
  703. /********** TODO
  704. CREATE INDEXES to improve performance
  705. ****************/
  706. select 'Process System Health Session fom a SQL instance' as ImportMethod, 'Exec spLoadSystemHealthSession' as Example
  707. Union all
  708. select 'Process System Health XEL files from a UNC' as ImportMethod, 'exec spLoadSystemHealthSession @path_to_health_session=''D:\XELFiles\system_health*.xel'',@UTDDateDiff=-6' as Example
  709. /*
  710. exec spLoadSystemHealthSession @path_to_health_session='D:\XELFiles\system_health*.xel',@UTDDateDiff=-6
  711. Exec spLoadSystemHealthSession
  712. */