|
1 | | ---- |
2 | | -title: "Monitor System Activity Using Extended Events | Microsoft Docs" |
3 | | -ms.custom: "" |
4 | | -ms.date: "06/13/2017" |
5 | | -ms.prod: "sql-server-2014" |
6 | | -ms.reviewer: "" |
7 | | -ms.technology: |
8 | | - - "database-engine" |
9 | | -ms.topic: conceptual |
10 | | -helpviewer_keywords: |
11 | | - - "xe" |
12 | | - - "extended events [SQL Server], monitoring system activity" |
13 | | -ms.assetid: d83ad88f-818c-49fe-a9a9-299f704fca53 |
14 | | -author: MightyPen |
15 | | -ms.author: genemi |
16 | | -manager: craigg |
17 | | ---- |
18 | | -# Monitor System Activity Using Extended Events |
19 | | - This procedure illustrates how Extended Events can be used with Event Tracing for Windows (ETW) to monitor system activity. The procedure also shows how the CREATE EVENT SESSION, ALTER EVENT SESSION, and DROP EVENT SESSION statements are used. |
20 | | - |
21 | | - Accomplishing these tasks involves using Query Editor in [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] to carry out the following procedure. The procedure also requires using the command prompt to run ETW commands. |
22 | | - |
23 | | -### To monitor system activity using Extended Events |
24 | | - |
25 | | -1. In Query Editor, issue the following statements to create an event session and add two events. These events, checkpoint_begin and checkpoint_end, fire at the beginning and end of a database checkpoint. |
26 | | - |
27 | | - ``` |
28 | | - CREATE EVENT SESSION test0 |
29 | | - ON SERVER |
30 | | - ADD EVENT sqlserver.checkpoint_begin, |
31 | | - ADD EVENT sqlserver.checkpoint_end |
32 | | - WITH (MAX_DISPATCH_LATENCY = 1 SECONDS) |
33 | | - go |
34 | | - ``` |
35 | | - |
36 | | -2. Add the bucketing target with 32 buckets to count the number of checkpoints based on the database ID. |
37 | | - |
38 | | - ``` |
39 | | - ALTER EVENT SESSION test0 |
40 | | - ON SERVER |
41 | | - ADD TARGET package0.histogram |
42 | | - ( |
43 | | - SET slots = 32, filtering_event_name = 'sqlserver.checkpoint_end', source_type = 0, source = 'database_id' |
44 | | - ) |
45 | | - go |
46 | | - ``` |
47 | | - |
48 | | -3. Issue the following statements to add the ETW target. This will enable you to see the begin and end events, which is used to determine how long the checkpoint takes. |
49 | | - |
50 | | - ``` |
51 | | - ALTER EVENT SESSION test0 |
52 | | - ON SERVER |
53 | | - ADD TARGET package0.etw_classic_sync_target |
54 | | - go |
55 | | - ``` |
56 | | - |
57 | | -4. Issue the following statements to start the session and begin event collection. |
58 | | - |
59 | | - ``` |
60 | | - ALTER EVENT SESSION test0 |
61 | | - ON SERVER |
62 | | - STATE = start |
63 | | - go |
64 | | - ``` |
65 | | - |
66 | | -5. Issue the following statements to cause three events to fire. |
67 | | - |
68 | | - ``` |
69 | | - USE tempdb |
70 | | - checkpoint |
71 | | - go |
72 | | - USE master |
73 | | - checkpoint |
74 | | - checkpoint |
75 | | - go |
76 | | - ``` |
77 | | - |
78 | | -6. Issue the following statements to view the event counts. |
79 | | - |
80 | | - ``` |
81 | | - SELECT CAST(xest.target_data AS xml) Bucketizer_Target_Data_in_XML |
82 | | - FROM sys.dm_xe_session_targets xest |
83 | | - JOIN sys.dm_xe_sessions xes ON xes.address = xest.event_session_address |
84 | | - JOIN sys.server_event_sessions ses ON xes.name = ses.name |
85 | | - WHERE xest.target_name = 'histogram' AND xes.name = 'test0' |
86 | | - go |
87 | | - ``` |
88 | | - |
89 | | -7. At the command prompt, issue the following commands to view the ETW data. |
90 | | - |
91 | | - > [!NOTE] |
92 | | - > To get help for the **tracerpt** command, at the command prompt, enter `tracerpt /?`. |
93 | | - |
94 | | - ``` |
95 | | - logman query -ets --- List the ETW sessions. This is optional. |
96 | | - logman update XE_DEFAULT_ETW_SESSION -fd -ets --- Flush the ETW log. |
97 | | - tracerpt %temp%\xeetw.etl -o xeetw.txt --- Dump the events so they can be seen. |
98 | | - ``` |
99 | | - |
100 | | -8. Issue the following statements to stop the event session and remove it from the server. |
101 | | - |
102 | | - ``` |
103 | | - ALTER EVENT SESSION test0 |
104 | | - ON SERVER |
105 | | - STATE = STOP |
106 | | - go |
107 | | - |
108 | | - DROP EVENT SESSION test0 |
109 | | - ON SERVER |
110 | | - go |
111 | | - ``` |
112 | | - |
113 | | -## See Also |
114 | | - [CREATE EVENT SESSION (Transact-SQL)](/sql/t-sql/statements/create-event-session-transact-sql) |
115 | | - [ALTER EVENT SESSION (Transact-SQL)](/sql/t-sql/statements/alter-event-session-transact-sql) |
116 | | - [DROP EVENT SESSION (Transact-SQL)](/sql/t-sql/statements/drop-event-session-transact-sql) |
117 | | - [Extended Events Catalog Views (Transact-SQL)](/sql/relational-databases/system-catalog-views/extended-events-catalog-views-transact-sql) |
118 | | - [Extended Events Dynamic Management Views](../views/views.md) |
119 | | - [SQL Server Extended Events Targets](../../database-engine/sql-server-extended-events-targets.md) |
120 | | - |
121 | | - |
| 1 | +--- |
| 2 | +title: "Monitor System Activity Using Extended Events | Microsoft Docs" |
| 3 | +ms.custom: "" |
| 4 | +ms.date: "06/13/2017" |
| 5 | +ms.prod: "sql-server-2014" |
| 6 | +ms.reviewer: "" |
| 7 | +ms.technology: |
| 8 | + - "database-engine" |
| 9 | +ms.topic: conceptual |
| 10 | +helpviewer_keywords: |
| 11 | + - "xe" |
| 12 | + - "extended events [SQL Server], monitoring system activity" |
| 13 | +ms.assetid: d83ad88f-818c-49fe-a9a9-299f704fca53 |
| 14 | +author: MightyPen |
| 15 | +ms.author: genemi |
| 16 | +manager: craigg |
| 17 | +--- |
| 18 | +# Monitor System Activity Using Extended Events |
| 19 | + This procedure illustrates how Extended Events can be used with Event Tracing for Windows (ETW) to monitor system activity. The procedure also shows how the CREATE EVENT SESSION, ALTER EVENT SESSION, and DROP EVENT SESSION statements are used. |
| 20 | + |
| 21 | + Accomplishing these tasks involves using Query Editor in [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] to carry out the following procedure. The procedure also requires using the command prompt to run ETW commands. |
| 22 | + |
| 23 | +### To monitor system activity using Extended Events |
| 24 | + |
| 25 | +1. In Query Editor, issue the following statements to create an event session and add two events. These events, checkpoint_begin and checkpoint_end, fire at the beginning and end of a database checkpoint. |
| 26 | + |
| 27 | + ``` |
| 28 | + CREATE EVENT SESSION test0 |
| 29 | + ON SERVER |
| 30 | + ADD EVENT sqlserver.checkpoint_begin, |
| 31 | + ADD EVENT sqlserver.checkpoint_end |
| 32 | + WITH (MAX_DISPATCH_LATENCY = 1 SECONDS) |
| 33 | + go |
| 34 | + ``` |
| 35 | + |
| 36 | +2. Add the bucketing target with 32 buckets to count the number of checkpoints based on the database ID. |
| 37 | + |
| 38 | + ``` |
| 39 | + ALTER EVENT SESSION test0 |
| 40 | + ON SERVER |
| 41 | + ADD TARGET package0.histogram |
| 42 | + ( |
| 43 | + SET slots = 32, filtering_event_name = 'sqlserver.checkpoint_end', source_type = 0, source = 'database_id' |
| 44 | + ) |
| 45 | + go |
| 46 | + ``` |
| 47 | + |
| 48 | +3. Issue the following statements to add the ETW target. This will enable you to see the begin and end events, which is used to determine how long the checkpoint takes. |
| 49 | + |
| 50 | + ``` |
| 51 | + ALTER EVENT SESSION test0 |
| 52 | + ON SERVER |
| 53 | + ADD TARGET package0.etw_classic_sync_target |
| 54 | + go |
| 55 | + ``` |
| 56 | + |
| 57 | +4. Issue the following statements to start the session and begin event collection. |
| 58 | + |
| 59 | + ``` |
| 60 | + ALTER EVENT SESSION test0 |
| 61 | + ON SERVER |
| 62 | + STATE = start |
| 63 | + go |
| 64 | + ``` |
| 65 | + |
| 66 | +5. Issue the following statements to cause three events to fire. |
| 67 | + |
| 68 | + ``` |
| 69 | + USE tempdb |
| 70 | + checkpoint |
| 71 | + go |
| 72 | + USE master |
| 73 | + checkpoint |
| 74 | + checkpoint |
| 75 | + go |
| 76 | + ``` |
| 77 | + |
| 78 | +6. Issue the following statements to view the event counts. |
| 79 | + |
| 80 | + ``` |
| 81 | + SELECT CAST(xest.target_data AS xml) Bucketizer_Target_Data_in_XML |
| 82 | + FROM sys.dm_xe_session_targets xest |
| 83 | + JOIN sys.dm_xe_sessions xes ON xes.address = xest.event_session_address |
| 84 | + JOIN sys.server_event_sessions ses ON xes.name = ses.name |
| 85 | + WHERE xest.target_name = 'histogram' AND xes.name = 'test0' |
| 86 | + go |
| 87 | + ``` |
| 88 | + |
| 89 | +7. At the command prompt, issue the following commands to view the ETW data. |
| 90 | + |
| 91 | + > [!NOTE] |
| 92 | + > To get help for the **tracerpt** command, at the command prompt, enter `tracerpt /?`. |
| 93 | + |
| 94 | + ``` |
| 95 | + logman query -ets --- List the ETW sessions. This is optional. |
| 96 | + logman update XE_DEFAULT_ETW_SESSION -fd -ets --- Flush the ETW log. |
| 97 | + tracerpt %temp%\xeetw.etl -o xeetw.txt --- Dump the events so they can be seen. |
| 98 | + ``` |
| 99 | + |
| 100 | +8. Issue the following statements to stop the event session and remove it from the server. |
| 101 | + |
| 102 | + ``` |
| 103 | + ALTER EVENT SESSION test0 |
| 104 | + ON SERVER |
| 105 | + STATE = STOP |
| 106 | + go |
| 107 | + |
| 108 | + DROP EVENT SESSION test0 |
| 109 | + ON SERVER |
| 110 | + go |
| 111 | + ``` |
| 112 | + |
| 113 | +## See Also |
| 114 | + [CREATE EVENT SESSION (Transact-SQL)](/sql/t-sql/statements/create-event-session-transact-sql) |
| 115 | + [ALTER EVENT SESSION (Transact-SQL)](/sql/t-sql/statements/alter-event-session-transact-sql) |
| 116 | + [DROP EVENT SESSION (Transact-SQL)](/sql/t-sql/statements/drop-event-session-transact-sql) |
| 117 | + [Extended Events Catalog Views (Transact-SQL)](/sql/relational-databases/system-catalog-views/extended-events-catalog-views-transact-sql) |
| 118 | + [Extended Events Dynamic Management Views](../views/views.md) |
| 119 | + [SQL Server Extended Events Targets](../../database-engine/sql-server-extended-events-targets.md) |
| 120 | + |
| 121 | + |
0 commit comments