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 Status Description
0 Not idle or suspended
1 Executing
2 Waiting For Thread
3 Between Retries
4 Idle
5 Suspended
6 WaitingForStepToFinish
7 PerformingCompletionActions

 

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

Last run outcome Description
0 Failed
1 Succeeded
3 Canceled
5 Unknown

 

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 Name Job_Name Enabled Execution_Status Current_Execution_step Current_retry_attempt last_run_outcome last_run_date
SQLTest Data Load Yes Idle 0(unknown) 0 Canceled 20081202
SQLDBPROD Import Data Yes Idle 0(unknown) 0 Canceled 20081201

 

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