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