-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathSession Monitoring.sql
57 lines (36 loc) · 2.26 KB
/
Session Monitoring.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
/********************************************************************************************
*** Session Momitoring using sp_whoisactive ***
------------------------------------------------
I have prepared this script to monitor currently running sessions
in different scenarios like CPU, Blocking, So first you need to
create sp_whoisactive stored procedure, please downad it from the link,
https://github.com/SqlAdmin/AwesomeSQLServer/blob/master/T-SQL%20Scripts/sp_whoisactive.sql
*******************************************************************************************/
-- To get overall info about current sessions
EXEC sp_whoisactive
------------------------------------------------
/*** 1. Currently running sessions CPU time ***/
------------------------------------------------
EXEC sp_WhoIsActive @get_plans = 1,
@get_avg_time = 1,
@output_column_list = '[dd%][session_id][database_name][cpu%][sql_text]',
@sort_order = '[start_time] ASC'
-----------------------------------------------------------
/*** 2. Currently running sessions memory pages usage ***/
-----------------------------------------------------------
EXEC sp_WhoIsActive @output_column_list = '[dd%][session_id][database_name][sql_text][used_memory][tempdb_allocations][tempdb_current]',
@sort_order = '[start_time] ASC';
--------------------------------------------------------------
/*** 3. Currently running query, batch and execution plan ***/
--------------------------------------------------------------
EXEC sp_WhoIsActive @get_full_inner_text = 1,
@get_plans = 1,
@get_outer_command = 1,
@output_column_list = '[dd%][session_id][database_name][sql_text][sql_command][query_plan]',
@sort_order = '[start_time] ASC';
-----------------------------------------------------------------
/*** 4. Monitor Transaction log writing process of a session ***/
-----------------------------------------------------------------
EXEC sp_WhoIsActive @get_transaction_info = 1,
@output_column_list = '[dd%][session_id][database_name][tran_log_writes]',
@sort_order = '[start_time] ASC';