|
shaileshpatangay
Starting Member
4 Posts |
Posted - 2009-06-29 : 09:50:15
|
| Following are list of columns, which T-sql would return. Spid : System Process Id info, which is effected by blocking.Loginame : Login Name for the spid, which is causing the blocking. CPU : CPU in milliseconds.Physical_IO : Total Number of Reads and writes.Memusage : Memory Usage.Login_time : When this session started.last_batch : Last batch date time info. IdleHrs : Number of Hours, this process has been Idle.Hostname : Computer name from where this process has been initiated.Programname : Program Name from where this spid is causing blocking. Cmd : Sql Text, contains first 256 characters. TSQL Statementset nocount oncreate table #IdleSessions(spid int,loginame varchar(500),cpu int,physical_io bigint,memusage int,login_time datetime,last_batch datetime,IdleSessionMin int,hostname varchar(500),program_name varchar(1000),cmd varchar(3000),EventType varchar(500),Parameters varchar(500))declare @spid int,@loginame varchar(500),@cpu int,@physical_io bigint,@memusage int,@login_time datetime,@last_batch datetime,@IdleSessionMin int,@hostname varchar(500),@program_name varchar(1000),@cmd varchar(3000)DECLARE cur_IdleSession CURSORREAD_ONLYFOR select spid,loginame,cpu,physical_io,memusage,login_time , last_batch,datediff(mi,last_batch,getdate()) as IdleSessionMin , hostname,program_namefrom master.dbo.sysprocesses with (nolock)where spid > 50 and datediff(mi,last_batch,getdate()) > ${IdleSessionMin} and dbid = db_id('${DBSERVER.DBNAME}') DECLARE @name varchar(40)OPEN cur_IdleSessionFETCH NEXT FROM cur_IdleSession INTO @spid,@loginame,@cpu,@physical_io,@memusage,@login_time,@last_batch,@IdleSessionMin,@hostname,@program_nameWHILE (@@fetch_status <> -1)BEGIN IF (@@fetch_status <> -2) BEGIN Set @cmd = 'DBCC INPUTBUFFER ('+convert(varchar,@spid)+')' Insert into #IdleSessions(EventType,Parameters,cmd) EXEC (@cmd) update #IdleSessions set spid = @spid ,loginame = @loginame ,cpu = @cpu ,physical_io = @physical_io ,memusage= @memusage ,login_time= @login_time ,last_batch=@last_batch ,IdleSessionMin=@IdleSessionMin ,hostname=@hostname ,program_name=@program_name where spid is null END FETCH NEXT FROM cur_IdleSession INTO @spid,@loginame,@cpu,@physical_io,@memusage,@login_time ,@last_batch,@IdleSessionMin,@hostname,@program_nameENDCLOSE cur_IdleSessionDEALLOCATE cur_IdleSessionselect spid,loginame,cpu,physical_io,memusage ,login_time,last_batch,IdleSessionMin,hostname ,program_name,cmdfrom #IdleSessionswhere cmd not like ('%${ListOfCmd}%') drop table #IdleSessions Parameters ${IdleHrs} : This would be user entered parameter, which is used to gather process information. Default Value for this parameter = 24. ${DBSERVER.DBNAME} : This is a system entered parameter, which would input the database name.${ListOfCmd} : This parameter would be user inputted entry, which is used for exclusion purposes.User would be inputting multiple values seperated by comma (“,”). Default input for this parameter is empty string, which means no exclusions. Note : The Default sevierity Level for this alert is 333. Testing this Alert:1. Open query analyzer on the testing server.2. Execute some sql query and keep it query analyzer Idle for ${IdleHrs}.3. Make sure that this alert (MS Idle Sessions) is scheduled.4. Find that this alert should raise a ticket.5. For testing exclusion list use parameter ${ListOfCmd} in the alert parameters.cheersshailesh patangay |
|