Custom Alert: Need query for Job Executing
PDinCA
Posts: 642 Silver 1
The "Job Duration Unusual" Alert is fine when the job actually stops, but there are times when a Job runs interminably.
I need a Custom Metric that tells me when an active Job has been running for more than my (threshold of pain) max "exceptional duration".
For now, I need that threshold to be in hours. If I can make it data-driven by Jobname, that would be ideal! If the query can poll the same target server as the Job is executing on and retrieve a configuration value from one of my existing configuration tables, I can then set up my "Job Still Running" Alert:
When Job <name> has been running for more than <configured hours for Job <name>> Alert me with High Importance.
Can this be done, and if so, could Red Gate share a sample query for "retrieve currently executing Jobs" that I can filter?
This could then be added to the list on the http://sqlmonitormetrics.red-gate.com site for others to use.
In hopes, with thanks, Stephen
I need a Custom Metric that tells me when an active Job has been running for more than my (threshold of pain) max "exceptional duration".
For now, I need that threshold to be in hours. If I can make it data-driven by Jobname, that would be ideal! If the query can poll the same target server as the Job is executing on and retrieve a configuration value from one of my existing configuration tables, I can then set up my "Job Still Running" Alert:
When Job <name> has been running for more than <configured hours for Job <name>> Alert me with High Importance.
Can this be done, and if so, could Red Gate share a sample query for "retrieve currently executing Jobs" that I can filter?
This could then be added to the list on the http://sqlmonitormetrics.red-gate.com site for others to use.
In hopes, with thanks, Stephen
Jesus Christ: Lunatic, liar or Lord?
Decide wisely...
Decide wisely...
Comments
You can try plugging this query into a custom metric against the MSDB database. It will report the number of seconds a job named MyJob has been running. You should then be able to set an alert when the number of seconds has been exceeded. I hope this helps!
Many thanks, Brian.
UPDATE
Sadly, the join criterion on just job_id gets me the list of every execution, so I revised the query, using my own replacement for DATEDIFF() for the hours calc as I want to be precise, not just have it fire after 3hrs 1min if it starts at, say, 12:59... (Hate DATEDIFF!)
Using SELECT TOP 1 ... ORDER BY a.start_execution_date DESC gets me the currently executing Job details.
Thanks, though, for your original query - wouldn't be anywhere without it. 8)
Decide wisely...
As it is, I can use the above for ONE Job per Custom Alert, which is fine if that's all one cared about, up to a handful perhaps would be OK, but in environments with many servers and many, many Jobs, I can see this kind of thing being unwieldy in a hurry.
Would RG please consider adding a standard alert "Job Still Running"? It should be reusable by being able to select the job of interest and state the job duration that when exceeded would raise the alert. Alert thresholds could use the standard Low/Medium/High measures for "Duration in excess of the Alert Duration", perhaps.
Thanks in hopes.
Decide wisely...
I'm glad I could help. I'm surprised that you can't just get this information from sysjobhistory, but that table only updates after the job finishes. So you have to use an undocumented xp to get the running jobs and then check the job activity table.
Sql Monitor has a UserVoice site here in case you want to add suggestions:
http://sqlmonitor.uservoice.com/forums/ ... uggestions
Would you please post the RSS URL for the SSC Uservoice as I like to keep an eye on suggestions that way (I already have the SQL Prompt, SSC and Search RSS feeds active). Thanks.
Decide wisely...