Technical Article

MSSQL Job Monitoring Simplified using Simple Query

,

I have made a solution for SQL server job Monitoring without using temp tables. The solution is based on a query which use OPENROWSET and query the stored procedure output accoding to various conditions specially Current execution status of the jobs.

I am using this query for monitoring more then 500 SQL server's with a combination of (SQL Server 2000, 2005 and 2008). I am using SQL Server Management Studio 2008 (SSMS) and its new feature Multi-Server query for monitoring the Current Executing jobs on various servers.

 

There are 8 exectution status of any jobs which is described as

Execution StatusDescription
0Not idle or suspended
1Executing
2Waiting For Thread
3Between Retries
4Idle
5Suspended
6WaitingForStepToFinish
7PerformingCompletionActions

 

and there are 4 possible outcomes of the jobs which is as

Last run outcomeDescription
0Failed
1Succeeded
3Canceled
5Unknown

 

exec(' SELECT a.name Job_Name, case when enabled = 1 then ''Yes'' else ''NO'' end Enabled,
case when current_execution_status =0 then ''Not idle or suspended'' when current_execution_status = 1 then ''Executing''
when current_execution_status = 2 then ''Waiting For Thread'' when
current_execution_status = 3 then ''Between Retries''
when current_execution_status = 4 then ''Idle'' when current_execution_status = 5 then ''Suspended''
when current_execution_status = 6 then ''WaitingForStepToFinish'' when current_execution_status = 7 then ''PerformingCompletionActions'' end Execution_Status
,current_execution_step, current_retry_attempt, Case when last_run_outcome = 0 then ''Failed'' when last_run_outcome = 1 then ''Succeeded''
when last_run_outcome = 3 then ''Canceled'' when last_run_outcome = 5 then
''Unknown'' End last_run_outcome
, last_run_date FROM OPENROWSET(''SQLOLEDB'',
''DRIVER={SQL Server};SERVER='+@@servername +';Trusted_Connection=yes;'',
''SET NOCOUNT ON;SET FMTONLY OFF;exec msdb.dbo.sp_help_job'') AS a
where last_run_outcome = 3
')

{Note: You can change the resultset according to your need. i.e.Last_run_outcomecan be 0 ,1,3,5 As description is mentioned in the table above and will provide you desired result. }

 

If you run the above query in SSMS (SQL Server 2008 Management Studio) using Multi-Server query. You will get the output like that

Server NameJob_NameEnabledExecution_StatusCurrent_Execution_stepCurrent_retry_attemptlast_run_outcomelast_run_date
SQLTestData LoadYesIdle0(unknown)0Canceled20081202
SQLDBPRODImport DataYesIdle0(unknown)0Canceled20081201

 

I have attempted to simplify the monitoring of SQL jobs in multiserver environment where you can easily identify the status of the jobs and its previous outcomes before attempting next execution with the help of simple queries and without using any external utlity

 

Kind Regards
Shashi Kant Chauhan

exec(' SELECT a.name Job_Name, case when enabled = 1 then ''Yes'' else ''NO'' end Enabled,
case when current_execution_status =0 then ''Not idle or suspended'' when current_execution_status = 1 then ''Executing''
when current_execution_status = 2 then ''Waiting For Thread'' when current_execution_status = 3 then ''Between Retries''
when current_execution_status = 4 then ''Idle'' when current_execution_status = 5 then ''Suspended''
when current_execution_status = 6 then ''WaitingForStepToFinish'' when current_execution_status = 7 then ''PerformingCompletionActions'' end Execution_Status
,current_execution_step, current_retry_attempt, Case when last_run_outcome = 0 then ''Failed'' when last_run_outcome = 1 then ''Succeeded''
when last_run_outcome = 3 then ''Canceled'' when last_run_outcome = 5 then ''Unknown'' End last_run_outcome, last_run_date FROM OPENROWSET(''SQLOLEDB'',
''DRIVER={SQL Server};SERVER='+@@servername +';Trusted_Connection=yes;'',
''SET NOCOUNT ON;SET FMTONLY OFF;exec msdb.dbo.sp_help_job'') AS a
where last_run_outcome = 3')

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating