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


Monitoring Long Running Agent Jobs


Monitoring Long Running Agent Jobs

Author
Message
Green Armchair
Green Armchair
SSC Veteran
SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)

Group: General Forum Members
Points: 209 Visits: 430

Hi

Does anybody have a way of monitoring for long running sql agent jobs? I've looked at all the usual suspects, sp_help_job, xp_sqlagent_enum_jobs, job tables etc but none of them seem to tell me how long a job has been running or even when it started (it must be held somewhere mustn't it?)

We had a situation were a sql agent job (calling a dts package that executes a batch file) had been running for days waiting for a response from a RSH to a mainframe). Nobody knew because it didn't fail.

I know I can set the timeout for a batch file execution from within the DTS package, but I would prefer to monitor the execution of the Agent job.

Thanks

Andy





andyobl
andyobl
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 105
You will need a bespoke script to that I think.
Check out the link below.

http://databasejournal.com/features/mssql/article.php/2168291
philcart
philcart
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2752 Visits: 1434

You'll need a bit of T-SQL coding

First you'll need to record the previous run duration. Maybe store an average value for past executions.
Record when a job starts
Then use xp_sqlagent_enum_jobs to determine which jobs are running.
For the jobs that are running, compare the datediff from the start time against your stored duration.

Have a browse throught the script library and you might find something useful there.



Hope this helps
Phill Carter
--------------------
Colt 45 - the original point and click interface

Australian SQL Server User Groups - My profile
Phills Philosophies
Murrumbeena Cricket Club
Green Armchair
Green Armchair
SSC Veteran
SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)

Group: General Forum Members
Points: 209 Visits: 430

Thanks Phill

My problem is that I can't seem to find where the job start time is stored. Any ideas?

Andy





Graeme100
Graeme100
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1249 Visits: 760

Hi Andy,

I use this script to capture info on job/job step duration

DECLARE @JOBNAME varchar(200)

SET @JOBNAME = 'YoUR Job Name'

SELECT DISTINCT j.name [JOB], jt.Step_ID [StepID],jt.Step_Name [Step],
SUBSTRING(CAST(jt.Last_Run_Duration AS varchar(10)) ,LEN(CAST(jt.Last_Run_Duration AS varchar(10)))-5,2) [Hours],
SUBSTRING(CAST(jt.Last_Run_Duration AS varchar(10)) ,LEN(CAST(jt.Last_Run_Duration AS varchar(10)))-3,2) [Minutes],
RIGHT(jt.Last_Run_Duration,2)[Seconds],jt.Last_Run_Date [Last Run Date],jt.Last_Run_Time [Time],GetDate() [Check Date]
FROM msdb.dbo.sysjobs j
INNER JOIN msdb.dbo.sysjobschedules js ON js.job_Id = j.job_id
INNER JOIN msdb.dbo.sysjobsteps jt ON jt.job_id = j.job_id
WHERE j.name = @JobName
ORDER BY [StepID]

Enter the name of your job in the job name variable and run this against the MSDB databse.

Any thoughts?

Graeme





Green Armchair
Green Armchair
SSC Veteran
SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)

Group: General Forum Members
Points: 209 Visits: 430

Thanks Graeme

I tried this but it only gives me info on the last run of the job, not how long the job has been running if it is currently running.

Andy





Green Armchair
Green Armchair
SSC Veteran
SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)SSC Veteran (209 reputation)

Group: General Forum Members
Points: 209 Visits: 430

I've found a solution here http://www.sqldts.com/default.aspx?271

Thanks for your thoughts and replies.

Andy





fai0626
fai0626
Old Hand
Old Hand (380 reputation)Old Hand (380 reputation)Old Hand (380 reputation)Old Hand (380 reputation)Old Hand (380 reputation)Old Hand (380 reputation)Old Hand (380 reputation)Old Hand (380 reputation)

Group: General Forum Members
Points: 380 Visits: 109
Hi,

For SQL 2005 or after, you can get current job execution time from the view
msdb.dbo.sysjobactivity.
PappyBlueRibs99
PappyBlueRibs99
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 153
Graeme, I like your suggestion. However, I don't think you need to have "INNER JOIN msdb.dbo.sysjobschedules AS js ON js.job_id = j.job_id" in your statement, since you don't actually use any of the fields. The reason I bring this up is that we have jobs with multiple schedules, and your results get funky if the job has multiple schedules.
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