-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRTM.ServiceBrokerStats_VW.View.sql
91 lines (76 loc) · 7.64 KB
/
RTM.ServiceBrokerStats_VW.View.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
/****************************************************************************************************
Developed by DataView, LLC. All rights reserved.
Licensed under GNU LESSER GENERAL PUBLIC LICENSE Version 3
Real Time Messenging Software for SQL Server
***************************************************************************************************/
CREATE VIEW [RTM].[ServiceBrokerStats_VW]
AS
SELECT [Database_Name] = Db_Name()
,[schema] = [sch].[name]
,[Queue] = [sq].[name]
,[Queue_State] = [qm].[state]
,[Messages_in_Queue] = [p].[rows]
,[sq].[is_activation_enabled]
,[EnableActivation] = Concat('ALTER QUEUE [', [sch].[name], '].[', [sq].[name], '] WITH ACTIVATION ( STATUS = ON )')
,[DisableActivation] = Concat('ALTER QUEUE [', [sch].[name], '].[', [sq].[name], '] WITH ACTIVATION ( STATUS = OFF)')
,[at].[current_readers]
,[sq].[max_readers]
,[qm].[last_empty_rowset_time]
,[qm].[last_activated_time]
,[queue_last_modify_date] = [sq].[modify_date]
,[qm].[tasks_waiting]
,[bat].[spid]
,[blocked] = [syspr].[blocking_session_id]
,[waittime] = [syspr].[wait_time]
,[lastwaittype] = [syspr].[last_wait_type]
,[wait_resource] = [syspr].[wait_resource]
,[cmd] = [syspr].[command]
,[sq].[activation_procedure]
,[sq].[is_receive_enabled]
,[sq].[is_enqueue_enabled]
,[sq].[is_retention_enabled]
,[sq].[is_poison_message_handling_enabled]
FROM [sys].[service_queues] [sq] WITH ( NOLOCK )
LEFT JOIN [sys].[dm_broker_queue_monitors] [qm] WITH ( NOLOCK ) ON [qm].[queue_id] = [sq].[object_id]
LEFT JOIN [sys].[dm_broker_activated_tasks] [bat] WITH ( NOLOCK ) ON [bat].[queue_id] = [sq].[object_id]
LEFT JOIN [sys].[dm_exec_requests] [syspr] WITH ( NOLOCK ) ON [bat].[spid] = [syspr].[session_id]
LEFT JOIN [sys].[objects] [o2] WITH ( NOLOCK ) ON [o2].[parent_object_id] = [sq].[object_id]
LEFT JOIN [sys].[schemas] [sch] ON [sch].[schema_id] = [sq].[schema_id]
LEFT JOIN [sys].[partitions] [p] WITH ( NOLOCK ) ON [p].[object_id] = [o2].[object_id]
AND [p].[index_id] = 1
LEFT JOIN
( SELECT [queue_id]
,[current_readers] = Count(*)
FROM [sys].[dm_broker_activated_tasks]
GROUP BY
[queue_id] ) [at] ON [sq].[object_id] = [at].[queue_id]
WHERE [sq].[is_ms_shipped] = 0
UNION ALL
SELECT [Database_Name] = Db_Name()
,[schema] = 'sys'
,[Queue] = 'Transmission_Queue'
,[Queue_State] = NULL
,[Messages_in_Queue] = [p].[rows]
,[is_activation_enabled] = 0
,[EnableActivation] = NULL
,[DisableActivation] = NULL
,[current_readers] = NULL
,[max_readers] = NULL
,[last_empty_rowset_time] = NULL
,[queue_last_modify_date] = NULL
,[last_activated_time] = NULL
,[tasks_waiting] = NULL
,[spid] = NULL
,[blocked] = NULL
,[waittime] = NULL
,[lastwaittype] = NULL
,[wait_resource] = NULL
,[cmd] = NULL
,[activation_procedure] = NULL
,[is_receive_enabled] = 0
,[is_enqueue_enabled] = 0
,[is_retention_enabled] = 0
,[is_poison_message_handling_enabled] = NULL
FROM [sys].[partitions] [p]
WHERE [p].[object_id] = Object_Id('sys.sysxmitqueue');
GO