Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Extended events script to monitor a job - SQL Server 2008-2008 R2


Extended events script to monitor a job - SQL Server 2008-2008 R2

Author
Message
pmscorca
pmscorca
SSC Journeyman
SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)SSC Journeyman (89 reputation)

Group: General Forum Members
Points: 89 Visits: 278
Hi,
I need to create a sql script to use the extended events in order to monitor the execution of
a SQL Server Agent job.
I'm searching some examples.

Any helps, please?
Thanks
li_leme
li_leme
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 154
Hi

DECLARE @JobName NVARCHAR(128) = 'Test';

DECLARE @Predicate NVARCHAR(MAX)='';
DECLARE @sqlcmd NVARCHAR(MAX)='';

SET @sqlcmd ='IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name=''TrackResourceWaits'')
DROP EVENT SESSION [TrackResourceWaits] ON SERVER;
CREATE EVENT SESSION [TrackResourceWaits] ON SERVER
ADD EVENT sqlos.wait_info
( WHERE
(opcode = 1 --End Events Only
AND duration > 0 -- had to accumulate 100ms of time
AND ({0})
))
ADD TARGET package0.asynchronous_bucketizer
( SET filtering_event_name=''sqlos.wait_info'',
source_type=0, -- specifies bucketing on column
source=''wait_type'' -- Bucket by wait_type
),
ADD TARGET package0.ring_buffer(SET max_memory=4096)';

SELECT @Predicate = @Predicate +
'sqlserver.client_app_name = ''' +
'SQLAgent - TSQL JobStep (Job 0x'+
SUBSTRING(job_id,7,2) +
SUBSTRING(job_id,5,2) +
SUBSTRING(job_id,3,2) +
SUBSTRING(job_id,1,2) +
SUBSTRING(job_id,12,2) +
SUBSTRING(job_id,10,2) +
SUBSTRING(job_id,17,2) +
SUBSTRING(job_id,15,2) +
SUBSTRING(job_id,20,4) +
SUBSTRING(job_id,25,12) +
' : Step ' +
CAST(step_id AS VARCHAR(3)) +
')'' OR '
FROM( SELECT CAST(j.job_id AS VARCHAR(50)) AS job_id,
js.step_id
FROM msdb.dbo.sysjobs AS j
INNER JOIN msdb.dbo.sysjobsteps AS js
ON j.job_id = js.job_id
WHERE j.name = @JobName) AS tab;

-- Append the predicate into the SQL command
SET @sqlcmd = REPLACE(@sqlcmd, '{0}', LEFT(@Predicate, LEN(@Predicate)-3));

-- Create the Event Session
EXEC(@sqlcmd);


I found this in http://www.sqlskills.com/blogs/jonathan/tracking-extended-events-for-a-sql-agent-job/


best Regards,

Liliam
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search