SqlServer has the following tools to monitor the state and range of productivity indicators.1. Dynamic administrative submissions and functions (sighs)Dynamic
Management Views and Functions♪ https://msdn.microsoft.com/ru-ru/library/ms188754.aspx )In the first part of the question, it is not clear what indicators you are interested in. Look at this. sys.dm_os_process_memory♪ sys.dm_io_virtual_file_stats or sys.dm_os_performance_countersMaybe you can find some interesting ones.The second part of the question could be requested sys.dm_exec_sessionsselect
session_id,
session_duration_sec = round(cast(getdate() - login_time as float) * 86400, 3),
cpu_time_sec = round(cast(cpu_time as float) / 1000, 3),
reads_Mb = round(cast(reads as float) / 128, 2),
writes_Mb = round(cast(writes as float) / 128, 2),
logical_reads_Mb = round(cast(logical_reads as float) / 128, 2)
from sys.dm_exec_sessions
where original_login_name = 'LoginName'
who will return the data on the current open session for the intended logic.Although, in some cases, this information is sufficient, it is clear, however, that it is not possible to obtain information on the final sessions. I mean, in a way, it's "mean" figures.If interest is not instantaneous and dynamics, it can be traced to polling. Such a decision, however, may not be appropriate in the case of, for example, short-lived sessions. Better use the means of tracking events.2. Traces (sighs)SQL Trace♪ https://msdn.microsoft.com/ru-ru/library/hh245121.aspx )To date, this is a worker, but outdated, so I will limit myself to mentioning it. He was replaced. Expanded developments♪3. Expanded developments (sighs)Extended Events♪ https://msdn.microsoft.com/ru-ru/library/bb630282.aspx )This tool is less resource-neutral compared to the transhipment (but it is not well-used, and can be said to be a kneeling server).Event data can be collected not only in the file, but also in the simple. Computer or Gestogram (which is very cost-effective in terms of memory costs) ring buffer (for cyclical events). It is possible to establish an automatic launch of a session of expanded events at the beginning of the SqlServer.In the second part of the question, for example, it is possible to trace events logout (relates to the package sqlserverwho has fieldsdurationcpu_timephysical_readslogical_readswritesContaining the accumulated values during the session by adding a filter sqlserver.session_server_principal_name = N'LoginName'♪For example:CREATE EVENT SESSION [LoginName_resource_usage] ON SERVER
ADD EVENT sqlserver.logout (
WHERE
([sqlserver].[session_server_principal_name] = N'LoginName')
)
ADD TARGET package0.event_file (
SET
filename = N'd:\Temp\XE_Logs\LoginName_resource_usage.xel',
max_file_size = 50,
max_rollover_files = 0
)
WITH (
MAX_MEMORY = 4096 KB,
EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS,
MAX_DISPATCH_LATENCY = 30 SECONDS,
MAX_EVENT_SIZE = 0 KB,
MEMORY_PARTITION_MODE = NONE,
TRACK_CAUSALITY = OFF,
STARTUP_STATE = OFF)
GO
ALTER EVENT SESSION [LoginName_resource_usage] ON SERVER
STATE = START
GO
After which events are read (with help) sys.fn_xe_file_target_read_fileand analysed (e.g., summarised by time intervals, etc.).